Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Adding a variable for Minio Endpoints #461

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/internal/apiserver/deployment.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ spec:
value: "{{.ObjectStorageConnection.Host}}"
- name: MINIO_SERVICE_SERVICE_PORT
value: "{{.ObjectStorageConnection.Port}}"
- name: MINIO_SERVICE_SERVICE_ENDPOINT
value: "{{.ObjectStorageConnection.Endpoint}}"
- name: CACHE_IMAGE
value: "{{.APIServer.CacheImage}}"
- name: MOVERESULTS_IMAGE
Expand Down
2 changes: 1 addition & 1 deletion config/internal/apiserver/sample-pipeline.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data:
"parent_task": "data-prep"}], "validate-model": [{"name": "train-model-model",
"parent_task": "train-model"}]}'
tekton.dev/artifact_bucket: mlpipeline
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000
tekton.dev/artifact_endpoint: $(MINIO_SERVICE_SERVICE_ENDPOINT)
tekton.dev/artifact_endpoint_scheme: http://
tekton.dev/artifact_items: '{"data-prep": [["X_test", "$(workspaces.data-prep.path)/artifacts/$ORIG_PR_NAME/$(context.taskRun.name)/X_test"],
["X_train", "$(workspaces.data-prep.path)/artifacts/$ORIG_PR_NAME/$(context.taskRun.name)/X_train"],
Expand Down
76 changes: 72 additions & 4 deletions controllers/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

mf "github.com/manifestival/manifestival"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -120,6 +121,68 @@ func DeleteResource(uc UtilContext, path string) {

}

func compareEnvs(expected, actual []v1.EnvVar) string {
errlist := ""
if len(expected) != len(actual) {
errlist = fmt.Sprintf("Container Env Lengths [expected: %d, actual: %d]\n", len(expected), len(actual))
}

// Iterate across expected list and check for each value
for e_i, e := range expected {
found := false
for a_i, a := range actual {
if e.Name == a.Name {
found = true
if e_i != a_i {
errlist = fmt.Sprintf("%sExpected Env out-of-order: [%s]\n", errlist, e.Name)
}
if e.Value != a.Value {
errlist = fmt.Sprintf("%sExpected Env Values do not match: [expected: %s, actual: %s]\n", errlist, e.Value, a.Value)
}
continue
}
}
if !found {
errlist = fmt.Sprintf("%sCould not find expected env: [%s]\n", errlist, e.Name)
}
}

// Iterate across expected list and check for each value
for _, a := range actual {
found := false
for _, e := range expected {
if a.Name == e.Name {
found = true
continue
}
}
if !found {
errlist = fmt.Sprintf("%sExtra Env Found: [%s]\n", errlist, a.Name)
}
}

return errlist
}

func getEnvFromUnstructured(obj *unstructured.Unstructured) []v1.EnvVar {
var envVars []v1.EnvVar

// Assuming 'obj' represents a Kubernetes Pod, you can retrieve the container's environment variables
containers, _, _ := unstructured.NestedSlice(obj.Object, "spec", "containers")
if len(containers) > 0 {
container := containers[0].(map[string]interface{})
env, _, _ := unstructured.NestedSlice(container, "env")
for _, e := range env {
envVar := e.(map[string]interface{})
name := envVar["name"].(string)
value := envVar["value"].(string)
envVars = append(envVars, v1.EnvVar{Name: name, Value: value})
}
}

return envVars
}

// CompareResources compares expected resource found locally
// in path and compares it against the resource found in the
// k8s cluster accessed via client defined in uc.Opts.
Expand All @@ -142,10 +205,15 @@ func CompareResources(uc UtilContext, path string) {
return err
}, timeout, interval).ShouldNot(HaveOccurred())

rest := expected.Object["kind"].(string)
result, err := CompareResourceProcs[rest](expected, actual)
Expect(err).NotTo(HaveOccurred())
Expect(result).Should(BeTrue())
expectedEnv := getEnvFromUnstructured(expected)
actualEnv := getEnvFromUnstructured(actual)

envMismatch := compareEnvs(expectedEnv, actualEnv)
if envMismatch != "" {
errorMsg := fmt.Sprintf("Container Env Lengths [expected: %d, actual: %d]\n%s", len(expectedEnv), len(actualEnv), envMismatch)
Expect(false).To(BeTrue(), errorMsg)
return
}
}

// DirExists checks whether dir at path exists
Expand Down
2 changes: 1 addition & 1 deletion docs/example_pipelines/condition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata:
"random-num-2"}], "print-msg-4": [{"name": "random-num-2-Output", "parent_task":
"random-num-2"}]}'
tekton.dev/artifact_bucket: mlpipeline
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000
tekton.dev/artifact_endpoint: $(MINIO_SERVICE_SERVICE_ENDPOINT)
tekton.dev/artifact_endpoint_scheme: http://
tekton.dev/artifact_items: '{"flip-coin": [["Output", "$(results.Output.path)"]],
"print-msg": [], "print-msg-2": [], "print-msg-3": [], "print-msg-4": [], "random-num":
Expand Down
Loading