Skip to content

Commit

Permalink
Add environment variable configs to compiler tests
Browse files Browse the repository at this point in the history
Signed-off-by: carter.fendley <carter.fendley@gmail.com>
  • Loading branch information
CarterFendley committed Oct 15, 2024
1 parent b665356 commit 714901f
Show file tree
Hide file tree
Showing 3 changed files with 526 additions and 0 deletions.
24 changes: 24 additions & 0 deletions backend/src/v2/compiler/argocompiler/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"

Expand All @@ -36,6 +37,7 @@ func Test_argo_compiler(t *testing.T) {
jobPath string // path of input PipelineJob to compile
platformSpecPath string // path of possible input PlatformSpec to compile
argoYAMLPath string // path of expected output argo workflow YAML
envVars []string
}{
{
jobPath: "../testdata/hello_world.json",
Expand All @@ -57,10 +59,32 @@ func Test_argo_compiler(t *testing.T) {
platformSpecPath: "../testdata/create_pod_metadata.json",
argoYAMLPath: "testdata/create_pod_metadata.yaml",
},
// With envOptions
{
jobPath: "../testdata/hello_world.json",
platformSpecPath: "",
argoYAMLPath: "testdata/with_logging/hello_world.yaml",
envVars: []string{"DRIVER_LOG_LEVEL=5", "LAUNCHER_LOG_LEVEL=5"},
},
{
jobPath: "../testdata/importer.json",
platformSpecPath: "",
argoYAMLPath: "testdata/with_logging/importer.yaml",
envVars: []string{"DRIVER_LOG_LEVEL=5", "LAUNCHER_LOG_LEVEL=5"},
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%+v", tt), func(t *testing.T) {
job, platformSpec := load(t, tt.jobPath, tt.platformSpecPath)
if tt.envVars != nil {
for _, envVar := range tt.envVars {
parts := strings.Split(strings.ReplaceAll(envVar, " ", ""), "=")
os.Setenv(parts[0], parts[1])

// Unset after test cases has ended
defer os.Unsetenv(parts[0])
}
}
if *update {
wf, err := argocompiler.Compile(job, platformSpec, nil)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
creationTimestamp: null
generateName: hello-world-
spec:
arguments:
parameters:
- name: components-203fce8adabe0cfa7da54b9d3ff79c772136c926974659b51c378727c7ccdfb7
value: '{"executorLabel":"exec-hello-world","inputDefinitions":{"parameters":{"text":{"type":"STRING"}}}}'
- name: implementations-203fce8adabe0cfa7da54b9d3ff79c772136c926974659b51c378727c7ccdfb7
value: '{"args":["--text","{{$.inputs.parameters[''text'']}}"],"command":["sh","-ec","program_path=$(mktemp)\nprintf
\"%s\" \"$0\" \u003e \"$program_path\"\npython3 -u \"$program_path\" \"$@\"\n","def
hello_world(text):\n print(text)\n return text\n\nimport argparse\n_parser
= argparse.ArgumentParser(prog=''Hello world'', description='''')\n_parser.add_argument(\"--text\",
dest=\"text\", type=str, required=True, default=argparse.SUPPRESS)\n_parsed_args
= vars(_parser.parse_args())\n\n_outputs = hello_world(**_parsed_args)\n"],"image":"python:3.9"}'
- name: components-root
value: '{"dag":{"tasks":{"hello-world":{"cachingOptions":{"enableCache":true},"componentRef":{"name":"comp-hello-world"},"inputs":{"parameters":{"text":{"componentInputParameter":"text"}}},"taskInfo":{"name":"hello-world"}}}},"inputDefinitions":{"parameters":{"text":{"type":"STRING"}}}}'
entrypoint: entrypoint
podMetadata:
annotations:
pipelines.kubeflow.org/v2_component: "true"
labels:
pipelines.kubeflow.org/v2_component: "true"
serviceAccountName: pipeline-runner
templates:
- container:
args:
- --type
- CONTAINER
- --pipeline_name
- namespace/n1/pipeline/hello-world
- --run_id
- '{{workflow.uid}}'
- --dag_execution_id
- '{{inputs.parameters.parent-dag-id}}'
- --component
- '{{inputs.parameters.component}}'
- --task
- '{{inputs.parameters.task}}'
- --container
- '{{inputs.parameters.container}}'
- --iteration_index
- '{{inputs.parameters.iteration-index}}'
- --cached_decision_path
- '{{outputs.parameters.cached-decision.path}}'
- --pod_spec_patch_path
- '{{outputs.parameters.pod-spec-patch.path}}'
- --condition_path
- '{{outputs.parameters.condition.path}}'
- --kubernetes_config
- '{{inputs.parameters.kubernetes-config}}'
- --log_level
- "5"
command:
- driver
image: gcr.io/ml-pipeline/kfp-driver
name: ""
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 64Mi
inputs:
parameters:
- name: component
- name: task
- name: container
- name: parent-dag-id
- default: "-1"
name: iteration-index
- default: ""
name: kubernetes-config
metadata: {}
name: system-container-driver
outputs:
parameters:
- name: pod-spec-patch
valueFrom:
default: ""
path: /tmp/outputs/pod-spec-patch
- default: "false"
name: cached-decision
valueFrom:
default: "false"
path: /tmp/outputs/cached-decision
- name: condition
valueFrom:
default: "true"
path: /tmp/outputs/condition
- dag:
tasks:
- arguments:
parameters:
- name: pod-spec-patch
value: '{{inputs.parameters.pod-spec-patch}}'
name: executor
template: system-container-impl
when: '{{inputs.parameters.cached-decision}} != true'
inputs:
parameters:
- name: pod-spec-patch
- default: "false"
name: cached-decision
metadata: {}
name: system-container-executor
outputs: {}
- container:
command:
- should-be-overridden-during-runtime
env:
- name: KFP_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: KFP_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
envFrom:
- configMapRef:
name: metadata-grpc-configmap
optional: true
image: gcr.io/ml-pipeline/should-be-overridden-during-runtime
name: ""
resources: {}
volumeMounts:
- mountPath: /kfp-launcher
name: kfp-launcher
- mountPath: /gcs
name: gcs-scratch
- mountPath: /s3
name: s3-scratch
- mountPath: /minio
name: minio-scratch
- mountPath: /.local
name: dot-local-scratch
- mountPath: /.cache
name: dot-cache-scratch
- mountPath: /.config
name: dot-config-scratch
initContainers:
- args:
- --copy
- /kfp-launcher/launch
- --log_level
- "5"
command:
- launcher-v2
image: gcr.io/ml-pipeline/kfp-launcher
name: kfp-launcher
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 100m
volumeMounts:
- mountPath: /kfp-launcher
name: kfp-launcher
inputs:
parameters:
- name: pod-spec-patch
metadata: {}
name: system-container-impl
outputs: {}
podSpecPatch: '{{inputs.parameters.pod-spec-patch}}'
volumes:
- emptyDir: {}
name: kfp-launcher
- emptyDir: {}
name: gcs-scratch
- emptyDir: {}
name: s3-scratch
- emptyDir: {}
name: minio-scratch
- emptyDir: {}
name: dot-local-scratch
- emptyDir: {}
name: dot-cache-scratch
- emptyDir: {}
name: dot-config-scratch
- dag:
tasks:
- arguments:
parameters:
- name: component
value: '{{workflow.parameters.components-203fce8adabe0cfa7da54b9d3ff79c772136c926974659b51c378727c7ccdfb7}}'
- name: task
value: '{"cachingOptions":{"enableCache":true},"componentRef":{"name":"comp-hello-world"},"inputs":{"parameters":{"text":{"componentInputParameter":"text"}}},"taskInfo":{"name":"hello-world"}}'
- name: container
value: '{{workflow.parameters.implementations-203fce8adabe0cfa7da54b9d3ff79c772136c926974659b51c378727c7ccdfb7}}'
- name: parent-dag-id
value: '{{inputs.parameters.parent-dag-id}}'
name: hello-world-driver
template: system-container-driver
- arguments:
parameters:
- name: pod-spec-patch
value: '{{tasks.hello-world-driver.outputs.parameters.pod-spec-patch}}'
- default: "false"
name: cached-decision
value: '{{tasks.hello-world-driver.outputs.parameters.cached-decision}}'
depends: hello-world-driver.Succeeded
name: hello-world
template: system-container-executor
inputs:
parameters:
- name: parent-dag-id
metadata: {}
name: root
outputs: {}
- container:
args:
- --type
- '{{inputs.parameters.driver-type}}'
- --pipeline_name
- namespace/n1/pipeline/hello-world
- --run_id
- '{{workflow.uid}}'
- --dag_execution_id
- '{{inputs.parameters.parent-dag-id}}'
- --component
- '{{inputs.parameters.component}}'
- --task
- '{{inputs.parameters.task}}'
- --runtime_config
- '{{inputs.parameters.runtime-config}}'
- --iteration_index
- '{{inputs.parameters.iteration-index}}'
- --execution_id_path
- '{{outputs.parameters.execution-id.path}}'
- --iteration_count_path
- '{{outputs.parameters.iteration-count.path}}'
- --condition_path
- '{{outputs.parameters.condition.path}}'
- --log_level
- "5"
command:
- driver
image: gcr.io/ml-pipeline/kfp-driver
name: ""
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 64Mi
inputs:
parameters:
- name: component
- default: ""
name: runtime-config
- default: ""
name: task
- default: "0"
name: parent-dag-id
- default: "-1"
name: iteration-index
- default: DAG
name: driver-type
metadata: {}
name: system-dag-driver
outputs:
parameters:
- name: execution-id
valueFrom:
path: /tmp/outputs/execution-id
- name: iteration-count
valueFrom:
default: "0"
path: /tmp/outputs/iteration-count
- name: condition
valueFrom:
default: "true"
path: /tmp/outputs/condition
- dag:
tasks:
- arguments:
parameters:
- name: component
value: '{{workflow.parameters.components-root}}'
- name: runtime-config
value: '{"parameters":{"text":{"stringValue":"hi there"}}}'
- name: driver-type
value: ROOT_DAG
name: root-driver
template: system-dag-driver
- arguments:
parameters:
- name: parent-dag-id
value: '{{tasks.root-driver.outputs.parameters.execution-id}}'
- name: condition
value: ""
depends: root-driver.Succeeded
name: root
template: root
inputs: {}
metadata: {}
name: entrypoint
outputs: {}
status:
finishedAt: null
startedAt: null
Loading

0 comments on commit 714901f

Please sign in to comment.