-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert MNIST PyTorch test case to go
- Loading branch information
Showing
5 changed files
with
383 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
support "github.com/project-codeflare/codeflare-operator/test/support" | ||
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestMnistPyTorchMCAD(t *testing.T) { | ||
test := support.With(t) | ||
test.T().Parallel() | ||
|
||
// Create a namespace | ||
namespace := test.NewTestNamespace() | ||
|
||
// Test configuration | ||
config := &corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: corev1.SchemeGroupVersion.String(), | ||
Kind: "ConfigMap", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "notebooks-mcad", | ||
}, | ||
BinaryData: map[string][]byte{ | ||
// MNIST MCAD Notebook | ||
"mnist_mcad_mini.ipynb": ReadFile(test, "resources/mnist_mcad_mini.ipynb"), | ||
}, | ||
Immutable: support.Ptr(true), | ||
} | ||
config, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Create(test.Ctx(), config, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Created ConfigMap %s/%s successfully", config.Namespace, config.Name) | ||
|
||
// Read the Notebook CR from resources and perform replacements for custom values. | ||
// Currently ODH doesn't support creating Notebook CRs outside of UI, https://github.com/opendatahub-io/kubeflow/issues/126 should address this. | ||
customNb := string(ReadFile(test, "resources/custom-nb-small.yaml")) | ||
replacements := map[string]string{ | ||
"%INGRESS%": getIngressDomain(test), | ||
"%OCPSERVER%": getOpenShiftApiUrl(test), | ||
"%OCPTOKEN%": getKubernetesBearerToken(test), | ||
"%NAMESPACE%": namespace.Name, | ||
"%ODH_NAMESPACE%": GetOpenDataHubNamespace(), | ||
"%CODEFLARE_IMAGESTREAM_TAG%": getCodeFlareImageStreamTag(test), | ||
"%JOBTYPE%": "mcad", | ||
} | ||
for k, v := range replacements { | ||
customNb = strings.ReplaceAll(customNb, k, v) | ||
} | ||
|
||
// Create Notebook CR using OC client, didn't find a Notebook go lang client for programmatic creation | ||
file, err := support.CreateTempFile(test, customNb) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
output, err := executeCommand("oc", "apply", "-n", namespace.Name, "-f", file.Name()) | ||
test.T().Logf("Command output: %s", output) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Make sure the AppWrapper is created and running | ||
test.Eventually(support.AppWrappersWithPrefix(test, namespace, "mnistjob"), support.TestTimeoutLong). | ||
Should(And(HaveLen(1), ContainElement(WithTransform(support.AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive))))) | ||
|
||
// Make sure the AppWrapper finishes and is deleted | ||
test.Eventually(support.AppWrappersWithPrefix(test, namespace, "mnistjob"), support.TestTimeoutLong). | ||
Should(HaveLen(0)) | ||
} | ||
|
||
func getIngressDomain(test support.Test) string { | ||
domain, err := executeCommand("oc", "get", "ingresses.config/cluster", "-o", "jsonpath={.spec.domain}") | ||
test.T().Logf("Domain %s", domain) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
return domain | ||
} | ||
|
||
func getOpenShiftApiUrl(test support.Test) string { | ||
openShiftApiUrl, err := executeCommand("oc", "whoami", "--show-server=true") | ||
openShiftApiDomain := strings.TrimPrefix(openShiftApiUrl, "https://") | ||
test.T().Logf("Domain %s", openShiftApiDomain) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
return openShiftApiDomain | ||
} | ||
|
||
func getKubernetesBearerToken(test support.Test) string { | ||
token, err := executeCommand("oc", "whoami", "--show-token=true") | ||
test.T().Logf("Token %s", token) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
return token | ||
} | ||
|
||
func getCodeFlareImageStreamTag(test support.Test) string { | ||
v, ok := os.LookupEnv("CODEFLARE_IMAGESTREAM_TAG") | ||
if !ok { | ||
test.T().Fatalf("CODEFLARE_IMAGESTREAM_TAG not defined, cannot continue") | ||
} | ||
return v | ||
} | ||
|
||
func executeCommand(name string, arg ...string) (string, error) { | ||
outputBytes, err := exec.Command(name, arg...).CombinedOutput() | ||
return string(outputBytes), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# This template maybe used to spin up a custom notebook image | ||
# i.e.: sed s/%INGRESS%/$(oc get ingresses.config/cluster -o jsonpath={.spec.domain})/g tests/resources/custom-nb.template | oc apply -f - | ||
# resources generated: | ||
# pod/jupyter-nb-kube-3aadmin-0 | ||
# service/jupyter-nb-kube-3aadmin | ||
# route.route.openshift.io/jupyter-nb-kube-3aadmin (jupyter-nb-kube-3aadmin-opendatahub.apps.tedbig412.cp.fyre.ibm.com) | ||
# service/jupyter-nb-kube-3aadmin-tls | ||
apiVersion: kubeflow.org/v1 | ||
kind: Notebook | ||
metadata: | ||
annotations: | ||
notebooks.opendatahub.io/inject-oauth: "true" | ||
notebooks.opendatahub.io/last-image-selection: codeflare-notebook:latest | ||
notebooks.opendatahub.io/last-size-selection: Small | ||
notebooks.opendatahub.io/oauth-logout-url: https://odh-dashboard-%ODH_NAMESPACE%.%INGRESS%/notebookController/kube-3aadmin/home | ||
opendatahub.io/link: https://jupyter-nb-kube-3aadmin-%NAMESPACE%.%INGRESS%/notebook/%NAMESPACE%/jupyter-nb-kube-3aadmin | ||
opendatahub.io/username: kube:admin | ||
generation: 1 | ||
labels: | ||
app: jupyter-nb-kube-3aadmin | ||
opendatahub.io/dashboard: "true" | ||
opendatahub.io/odh-managed: "true" | ||
opendatahub.io/user: kube-3aadmin | ||
name: jupyter-nb-kube-3aadmin | ||
namespace: %NAMESPACE% | ||
spec: | ||
template: | ||
spec: | ||
affinity: | ||
nodeAffinity: | ||
preferredDuringSchedulingIgnoredDuringExecution: | ||
- preference: | ||
matchExpressions: | ||
- key: nvidia.com/gpu.present | ||
operator: NotIn | ||
values: | ||
- "true" | ||
weight: 1 | ||
containers: | ||
- env: | ||
- name: NOTEBOOK_ARGS | ||
value: |- | ||
--ServerApp.port=8888 | ||
--ServerApp.token='' | ||
--ServerApp.password='' | ||
--ServerApp.base_url=/notebook/%NAMESPACE%/jupyter-nb-kube-3aadmin | ||
--ServerApp.quit_button=False | ||
--ServerApp.tornado_settings={"user":"kube-3aadmin","hub_host":"https://odh-dashboard-%ODH_NAMESPACE%.%INGRESS%","hub_prefix":"/notebookController/kube-3aadmin"} | ||
- name: JUPYTER_IMAGE | ||
value: image-registry.openshift-image-registry.svc:5000/%ODH_NAMESPACE%/codeflare-notebook:%CODEFLARE_IMAGESTREAM_TAG% | ||
- name: JUPYTER_NOTEBOOK_PORT | ||
value: "8888" | ||
- name: OCP_SERVER | ||
value: https://%OCPSERVER% | ||
- name: OCP_TOKEN | ||
value: %OCPTOKEN% | ||
image: image-registry.openshift-image-registry.svc:5000/%ODH_NAMESPACE%/codeflare-notebook:%CODEFLARE_IMAGESTREAM_TAG% | ||
command: ["/bin/sh", "-c", "pip install papermill && oc login --token=${OCP_TOKEN} --server=${OCP_SERVER} --insecure-skip-tls-verify=true && papermill /opt/app-root/notebooks-%JOBTYPE%/mnist_%JOBTYPE%_mini.ipynb /opt/app-root/src/mcad-out.ipynb && sleep infinity"] | ||
# args: ["pip install papermill && oc login --token=${OCP_TOKEN} --server=${OCP_SERVER} --insecure-skip-tls-verify=true && papermill /opt/app-root/notebooks/mcad.ipynb /opt/app-root/src/mcad-out.ipynb" ] | ||
imagePullPolicy: Always | ||
# livenessProbe: | ||
# failureThreshold: 3 | ||
# httpGet: | ||
# path: /notebook/%NAMESPACE%/jupyter-nb-kube-3aadmin/api | ||
# port: notebook-port | ||
# scheme: HTTP | ||
# initialDelaySeconds: 10 | ||
# periodSeconds: 5 | ||
# successThreshold: 1 | ||
# timeoutSeconds: 1 | ||
name: jupyter-nb-kube-3aadmin | ||
ports: | ||
- containerPort: 8888 | ||
name: notebook-port | ||
protocol: TCP | ||
resources: | ||
limits: | ||
cpu: "2" | ||
memory: 3Gi | ||
requests: | ||
cpu: "1" | ||
memory: 3Gi | ||
volumeMounts: | ||
- mountPath: /opt/app-root/src | ||
name: jupyterhub-nb-kube-3aadmin-pvc | ||
- mountPath: /opt/app-root/notebooks-%JOBTYPE% | ||
name: notebooks-%JOBTYPE% | ||
workingDir: /opt/app-root/src | ||
- args: | ||
- --provider=openshift | ||
- --https-address=:8443 | ||
- --http-address= | ||
- --openshift-service-account=jupyter-nb-kube-3aadmin | ||
- --cookie-secret-file=/etc/oauth/config/cookie_secret | ||
- --cookie-expire=24h0m0s | ||
- --tls-cert=/etc/tls/private/tls.crt | ||
- --tls-key=/etc/tls/private/tls.key | ||
- --upstream=http://localhost:8888 | ||
- --upstream-ca=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt | ||
- --skip-auth-regex=^(?:/notebook/$(NAMESPACE)/jupyter-nb-kube-3aadmin)?/api$ | ||
- --email-domain=* | ||
- --skip-provider-button | ||
- --openshift-sar={"verb":"get","resource":"notebooks","resourceAPIGroup":"kubeflow.org","resourceName":"jupyter-nb-kube-3aadmin","namespace":"$(NAMESPACE)"} | ||
- --logout-url=https://odh-dashboard-%ODH_NAMESPACE%.%INGRESS%/notebookController/kube-3aadmin/home | ||
env: | ||
- name: NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
image: registry.redhat.io/openshift4/ose-oauth-proxy:v4.10 | ||
imagePullPolicy: Always | ||
livenessProbe: | ||
failureThreshold: 3 | ||
httpGet: | ||
path: /oauth/healthz | ||
port: oauth-proxy | ||
scheme: HTTPS | ||
initialDelaySeconds: 30 | ||
periodSeconds: 5 | ||
successThreshold: 1 | ||
timeoutSeconds: 1 | ||
name: oauth-proxy | ||
ports: | ||
- containerPort: 8443 | ||
name: oauth-proxy | ||
protocol: TCP | ||
readinessProbe: | ||
failureThreshold: 3 | ||
httpGet: | ||
path: /oauth/healthz | ||
port: oauth-proxy | ||
scheme: HTTPS | ||
initialDelaySeconds: 5 | ||
periodSeconds: 5 | ||
successThreshold: 1 | ||
timeoutSeconds: 1 | ||
resources: | ||
limits: | ||
cpu: 100m | ||
memory: 64Mi | ||
requests: | ||
cpu: 100m | ||
memory: 64Mi | ||
volumeMounts: | ||
- mountPath: /etc/oauth/config | ||
name: oauth-config | ||
- mountPath: /etc/tls/private | ||
name: tls-certificates | ||
enableServiceLinks: false | ||
serviceAccountName: jupyter-nb-kube-3aadmin | ||
volumes: | ||
- name: jupyterhub-nb-kube-3aadmin-pvc | ||
persistentVolumeClaim: | ||
claimName: jupyterhub-nb-kube-3aadmin-pvc | ||
- name: oauth-config | ||
secret: | ||
defaultMode: 420 | ||
secretName: jupyter-nb-kube-3aadmin-oauth-config | ||
- name: tls-certificates | ||
secret: | ||
defaultMode: 420 | ||
secretName: jupyter-nb-kube-3aadmin-tls | ||
- name: notebooks-%JOBTYPE% | ||
configMap: | ||
name: notebooks-%JOBTYPE% | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: jupyterhub-nb-kube-3aadmin-pvc | ||
namespace: %NAMESPACE% | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 10Gi |
Oops, something went wrong.