diff --git a/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml b/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml index 8eea820e..380aaeb5 100644 --- a/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml +++ b/config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml @@ -859,7 +859,7 @@ spec: status: {} - deprecated: true deprecationWarning: datasciencepipelinesapplications.opendatahub.io/v1alpha1 is - deprecated + deprecated. name: v1alpha1 schema: openAPIV3Schema: diff --git a/controllers/config/defaults.go b/controllers/config/defaults.go index 728daa57..63c92bc5 100644 --- a/controllers/config/defaults.go +++ b/controllers/config/defaults.go @@ -27,10 +27,13 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) +const DSPV2VersionString = "v2" +const DSPVersionk8sLabel = "dsp-version" + +var SupportedDSPVersions = []string{DSPV2VersionString} + const ( - DSPDefaultVersion = "v2" - DSPV2VersionString = DSPDefaultVersion - DefaultImageValue = "MustSetInConfig" + DefaultImageValue = "MustSetInConfig" CustomCABundleRootMountPath = "/dsp-custom-certs" @@ -222,3 +225,7 @@ func GetDefaultDBExtraParams(params DBExtraParams, log logr.Logger) (string, err } return string(extraParamsJson), nil } + +func GetSupportedDSPAVersions() []string { + return SupportedDSPVersions +} diff --git a/controllers/dspipeline_controller.go b/controllers/dspipeline_controller.go index 16cf8252..c972705a 100644 --- a/controllers/dspipeline_controller.go +++ b/controllers/dspipeline_controller.go @@ -19,7 +19,6 @@ package controllers import ( "context" "fmt" - "github.com/opendatahub-io/data-science-pipelines-operator/controllers/dspastatus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -82,18 +81,25 @@ func (r *DSPAReconciler) Apply(owner mf.Owner, params *DSPAParams, template stri if err != nil { return fmt.Errorf("error loading template (%s) yaml: %w", template, err) } + + // Apply the owner injection transformation tmplManifest, err = tmplManifest.Transform( mf.InjectOwner(owner), + // Apply dsp-version= label on all resources managed by this dspo + util.AddLabelTransformer(config.DSPVersionk8sLabel, params.DSPVersion), + util.AddDeploymentPodLabelTransformer(config.DSPVersionk8sLabel, params.DSPVersion), ) if err != nil { return err } + // Apply dsp-version labels to all manifests tmplManifest, err = tmplManifest.Transform(fns...) if err != nil { return err } + // Apply the manifest return tmplManifest.Apply() } @@ -188,7 +194,7 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. defer r.updateStatus(ctx, dspa, dspaStatus, log, req) - if dspa.Spec.DSPVersion != config.DSPV2VersionString { + if !util.DSPAWithSupportedDSPVersion(dspa) { err1 := fmt.Errorf("unsupported DSP version %s detected. Please manually remove "+ "this DSP resource and re-apply with a supported version field set", dspa.Spec.DSPVersion) dspaStatus.SetDatabaseNotReady(err1, config.UnsupportedVersion) @@ -594,7 +600,6 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error { // Watch for global ca bundle, if one is added to this namespace // we need to reconcile on all the dspa's in this namespace // so they may mount this cert in the appropriate containers - WatchesRawSource(source.Kind(mgr.GetCache(), &corev1.ConfigMap{}), handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request { cm := o.(*corev1.ConfigMap) @@ -605,8 +610,6 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error { return nil } - log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change in event on Global CA Bundle: %s", cm.Name)) - var dspaList dspav1.DataSciencePipelinesApplicationList if err := r.List(ctx, &dspaList, client.InNamespace(thisNamespace)); err != nil { log.Error(err, "unable to list DSPA's when attempting to handle Global CA Bundle event.") @@ -615,11 +618,18 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error { var reconcileRequests []reconcile.Request for _, dspa := range dspaList.Items { - namespacedName := types.NamespacedName{ - Name: dspa.Name, - Namespace: thisNamespace, + // Only update supported DSP versions + if util.DSPAWithSupportedDSPVersion(&dspa) { + namespacedName := types.NamespacedName{ + Name: dspa.Name, + Namespace: thisNamespace, + } + reconcileRequests = append(reconcileRequests, reconcile.Request{NamespacedName: namespacedName}) } - reconcileRequests = append(reconcileRequests, reconcile.Request{NamespacedName: namespacedName}) + } + + if len(reconcileRequests) > 0 { + log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change in event on Global CA Bundle: %s", cm.Name)) } return reconcileRequests @@ -635,6 +645,12 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error { return nil } + // Silently skip reconcile on this pod if the resource was owned + // by an unsupported dspa + if !util.HasSupportedDSPVersionLabel(pod.Labels) { + return nil + } + dspaName, hasDSPALabel := pod.Labels["dspa"] if !hasDSPALabel { msg := fmt.Sprintf("Pod with data-science-pipelines label encountered, but is missing dspa "+ @@ -659,9 +675,6 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error { if secret.Annotations["openshift.io/owning-component"] != "service-ca" { return nil } - - log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change on Secret owned by service-ca: %s", secret.Name)) - serviceName := secret.Annotations["service.beta.openshift.io/originating-service-name"] namespacedServiceName := types.NamespacedName{ @@ -675,17 +688,22 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return nil } - dspaName, hasDSPALabel := service.Labels["dspa"] if !hasDSPALabel { return nil } - log.V(1).Info(fmt.Sprintf("Reconcile event triggered by [Service: %s] ", serviceName)) + // Silently skip reconcile on this ervice if the resource was owned + // by an unsupported DSPA + if !util.HasSupportedDSPVersionLabel(service.Labels) { + return nil + } + namespacedDspaName := types.NamespacedName{ Name: dspaName, Namespace: secret.Namespace, } + log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change on Secret: %s owned by service-ca: %s", secret.Name, serviceName)) return []reconcile.Request{{NamespacedName: namespacedDspaName}} }), ). diff --git a/controllers/testdata/declarative/case_0/expected/created/apiserver_deployment.yaml b/controllers/testdata/declarative/case_0/expected/created/apiserver_deployment.yaml index c6a01bf5..4a952983 100644 --- a/controllers/testdata/declarative/case_0/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_0/expected/created/apiserver_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-testdsp0 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp0 component: data-science-pipelines dspa: testdsp0 @@ -16,6 +17,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-testdsp0 component: data-science-pipelines dspa: testdsp0 diff --git a/controllers/testdata/declarative/case_0/expected/created/configmap_server_config.yaml b/controllers/testdata/declarative/case_0/expected/created/configmap_server_config.yaml index a8d8ad45..20b920a7 100644 --- a/controllers/testdata/declarative/case_0/expected/created/configmap_server_config.yaml +++ b/controllers/testdata/declarative/case_0/expected/created/configmap_server_config.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-server-config-testdsp0 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp0 component: data-science-pipelines data: diff --git a/controllers/testdata/declarative/case_0/expected/created/mariadb_deployment.yaml b/controllers/testdata/declarative/case_0/expected/created/mariadb_deployment.yaml index 20aad1f7..3a2c4adf 100644 --- a/controllers/testdata/declarative/case_0/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_0/expected/created/mariadb_deployment.yaml @@ -5,6 +5,7 @@ metadata: name: mariadb-testdsp0 namespace: default labels: + dsp-version: v2 app: mariadb-testdsp0 component: data-science-pipelines dspa: testdsp0 @@ -19,6 +20,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: mariadb-testdsp0 component: data-science-pipelines dspa: testdsp0 diff --git a/controllers/testdata/declarative/case_0/expected/created/persistence-agent_deployment.yaml b/controllers/testdata/declarative/case_0/expected/created/persistence-agent_deployment.yaml index ed2a1897..d0029e97 100644 --- a/controllers/testdata/declarative/case_0/expected/created/persistence-agent_deployment.yaml +++ b/controllers/testdata/declarative/case_0/expected/created/persistence-agent_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-persistenceagent-testdsp0 namespace: default labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp0 component: data-science-pipelines dspa: testdsp0 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp0 component: data-science-pipelines dspa: testdsp0 diff --git a/controllers/testdata/declarative/case_0/expected/created/scheduled-workflow_deployment.yaml b/controllers/testdata/declarative/case_0/expected/created/scheduled-workflow_deployment.yaml index 7ba917a4..9c476cf6 100644 --- a/controllers/testdata/declarative/case_0/expected/created/scheduled-workflow_deployment.yaml +++ b/controllers/testdata/declarative/case_0/expected/created/scheduled-workflow_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-scheduledworkflow-testdsp0 namespace: default labels: + dsp-version: v2 app: ds-pipeline-scheduledworkflow-testdsp0 component: data-science-pipelines dspa: testdsp0 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-scheduledworkflow-testdsp0 component: data-science-pipelines dspa: testdsp0 diff --git a/controllers/testdata/declarative/case_2/expected/created/apiserver_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/apiserver_deployment.yaml index 4a19db47..66c7e833 100644 --- a/controllers/testdata/declarative/case_2/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/apiserver_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-testdsp2 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -16,6 +17,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_2/expected/created/mariadb_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/mariadb_deployment.yaml index d122f60d..9d64497c 100644 --- a/controllers/testdata/declarative/case_2/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/mariadb_deployment.yaml @@ -5,6 +5,7 @@ metadata: name: mariadb-testdsp2 namespace: default labels: + dsp-version: v2 app: mariadb-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -19,6 +20,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: mariadb-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_2/expected/created/minio_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/minio_deployment.yaml index c3150158..7387e072 100644 --- a/controllers/testdata/declarative/case_2/expected/created/minio_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/minio_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: minio-testdsp2 namespace: default labels: + dsp-version: v2 app: minio-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -18,6 +19,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: minio-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_2/expected/created/mlmd_envoy_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/mlmd_envoy_deployment.yaml index da126350..91040713 100644 --- a/controllers/testdata/declarative/case_2/expected/created/mlmd_envoy_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/mlmd_envoy_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-metadata-envoy-testdsp2 namespace: default labels: + dsp-version: v2 app: ds-pipeline-metadata-envoy-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -19,6 +20,7 @@ spec: annotations: sidecar.istio.io/inject: "false" labels: + dsp-version: v2 app: ds-pipeline-metadata-envoy-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_2/expected/created/mlmd_grpc_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/mlmd_grpc_deployment.yaml index c7f1e903..7b81e773 100644 --- a/controllers/testdata/declarative/case_2/expected/created/mlmd_grpc_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/mlmd_grpc_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-metadata-grpc-testdsp2 namespace: default labels: + dsp-version: v2 app: ds-pipeline-metadata-grpc-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -17,6 +18,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-metadata-grpc-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_2/expected/created/mlpipelines-ui_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/mlpipelines-ui_deployment.yaml index 53b19793..37148477 100644 --- a/controllers/testdata/declarative/case_2/expected/created/mlpipelines-ui_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/mlpipelines-ui_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-ui-testdsp2 namespace: default labels: + dsp-version: v2 app: ds-pipeline-ui-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-ui-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_2/expected/created/persistence-agent_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/persistence-agent_deployment.yaml index 67c750f3..500a95d5 100644 --- a/controllers/testdata/declarative/case_2/expected/created/persistence-agent_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/persistence-agent_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-persistenceagent-testdsp2 namespace: default labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_2/expected/created/sample-config.yaml.tmpl b/controllers/testdata/declarative/case_2/expected/created/sample-config.yaml.tmpl index 99fa4fd1..aca6d21e 100644 --- a/controllers/testdata/declarative/case_2/expected/created/sample-config.yaml.tmpl +++ b/controllers/testdata/declarative/case_2/expected/created/sample-config.yaml.tmpl @@ -4,6 +4,7 @@ metadata: name: sample-config-testdsp2 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp2 component: data-science-pipelines data: diff --git a/controllers/testdata/declarative/case_2/expected/created/scheduled-workflow_deployment.yaml b/controllers/testdata/declarative/case_2/expected/created/scheduled-workflow_deployment.yaml index 16d31488..b855c94d 100644 --- a/controllers/testdata/declarative/case_2/expected/created/scheduled-workflow_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/scheduled-workflow_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-scheduledworkflow-testdsp2 namespace: default labels: + dsp-version: v2 app: ds-pipeline-scheduledworkflow-testdsp2 component: data-science-pipelines dspa: testdsp2 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-scheduledworkflow-testdsp2 component: data-science-pipelines dspa: testdsp2 diff --git a/controllers/testdata/declarative/case_3/expected/created/apiserver_deployment.yaml b/controllers/testdata/declarative/case_3/expected/created/apiserver_deployment.yaml index ab05ca09..8646f1ea 100644 --- a/controllers/testdata/declarative/case_3/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_3/expected/created/apiserver_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-testdsp3 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp3 component: data-science-pipelines dspa: testdsp3 @@ -16,6 +17,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-testdsp3 component: data-science-pipelines dspa: testdsp3 diff --git a/controllers/testdata/declarative/case_4/expected/created/apiserver_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/apiserver_deployment.yaml index a8dea314..b0474ff8 100644 --- a/controllers/testdata/declarative/case_4/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/apiserver_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-testdsp4 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -16,6 +17,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_4/expected/created/mariadb_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/mariadb_deployment.yaml index 3130c29a..a88cf751 100644 --- a/controllers/testdata/declarative/case_4/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/mariadb_deployment.yaml @@ -5,6 +5,7 @@ metadata: name: mariadb-testdsp4 namespace: default labels: + dsp-version: v2 app: mariadb-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -19,6 +20,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: mariadb-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_4/expected/created/minio_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/minio_deployment.yaml index 0ea9304b..dddd17f6 100644 --- a/controllers/testdata/declarative/case_4/expected/created/minio_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/minio_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: minio-testdsp4 namespace: default labels: + dsp-version: v2 app: minio-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -18,6 +19,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: minio-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_4/expected/created/mlmd_envoy_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/mlmd_envoy_deployment.yaml index cdf98087..0dc50500 100644 --- a/controllers/testdata/declarative/case_4/expected/created/mlmd_envoy_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/mlmd_envoy_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-metadata-envoy-testdsp4 namespace: default labels: + dsp-version: v2 app: ds-pipeline-metadata-envoy-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -19,6 +20,7 @@ spec: annotations: sidecar.istio.io/inject: "false" labels: + dsp-version: v2 app: ds-pipeline-metadata-envoy-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_4/expected/created/mlmd_grpc_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/mlmd_grpc_deployment.yaml index 136aa554..f8c79bc8 100644 --- a/controllers/testdata/declarative/case_4/expected/created/mlmd_grpc_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/mlmd_grpc_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-metadata-grpc-testdsp4 namespace: default labels: + dsp-version: v2 app: ds-pipeline-metadata-grpc-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -17,6 +18,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-metadata-grpc-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_4/expected/created/mlpipelines-ui_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/mlpipelines-ui_deployment.yaml index 62022305..fbeb5e5f 100644 --- a/controllers/testdata/declarative/case_4/expected/created/mlpipelines-ui_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/mlpipelines-ui_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-ui-testdsp4 namespace: default labels: + dsp-version: v2 app: ds-pipeline-ui-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-ui-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_4/expected/created/persistence-agent_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/persistence-agent_deployment.yaml index 3818ab38..f009d959 100644 --- a/controllers/testdata/declarative/case_4/expected/created/persistence-agent_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/persistence-agent_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-persistenceagent-testdsp4 namespace: default labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_4/expected/created/scheduled-workflow_deployment.yaml b/controllers/testdata/declarative/case_4/expected/created/scheduled-workflow_deployment.yaml index e36acc69..5f15836e 100644 --- a/controllers/testdata/declarative/case_4/expected/created/scheduled-workflow_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/scheduled-workflow_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-scheduledworkflow-testdsp4 namespace: default labels: + dsp-version: v2 app: ds-pipeline-scheduledworkflow-testdsp4 component: data-science-pipelines dspa: testdsp4 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-scheduledworkflow-testdsp4 component: data-science-pipelines dspa: testdsp4 diff --git a/controllers/testdata/declarative/case_5/expected/created/apiserver_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/apiserver_deployment.yaml index c0b04ebb..03a74eeb 100644 --- a/controllers/testdata/declarative/case_5/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/apiserver_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-testdsp5 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp5 component: data-science-pipelines dspa: testdsp5 @@ -16,6 +17,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-testdsp5 component: data-science-pipelines dspa: testdsp5 diff --git a/controllers/testdata/declarative/case_5/expected/created/configmap_dspa_trusted_ca.yaml b/controllers/testdata/declarative/case_5/expected/created/configmap_dspa_trusted_ca.yaml index 134b47fc..c136947a 100644 --- a/controllers/testdata/declarative/case_5/expected/created/configmap_dspa_trusted_ca.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/configmap_dspa_trusted_ca.yaml @@ -2,6 +2,8 @@ kind: ConfigMap apiVersion: v1 metadata: name: dsp-trusted-ca-testdsp5 + labels: + dsp-version: v2 data: testcabundleconfigmapkey5.crt: |- -----BEGIN CERTIFICATE----- diff --git a/controllers/testdata/declarative/case_5/expected/created/mariadb_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/mariadb_deployment.yaml index 06777e77..de101cf6 100644 --- a/controllers/testdata/declarative/case_5/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/mariadb_deployment.yaml @@ -5,6 +5,7 @@ metadata: name: mariadb-testdsp5 namespace: default labels: + dsp-version: v2 app: mariadb-testdsp5 component: data-science-pipelines dspa: testdsp5 @@ -19,6 +20,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: mariadb-testdsp5 component: data-science-pipelines dspa: testdsp5 diff --git a/controllers/testdata/declarative/case_6/expected/created/apiserver_deployment.yaml b/controllers/testdata/declarative/case_6/expected/created/apiserver_deployment.yaml index e72cdfe1..f4809db8 100644 --- a/controllers/testdata/declarative/case_6/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_6/expected/created/apiserver_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-testdsp6 namespace: default labels: + dsp-version: v2 app: ds-pipeline-testdsp6 component: data-science-pipelines dspa: testdsp6 @@ -16,6 +17,7 @@ spec: template: metadata: labels: + dsp-version: v2 app: ds-pipeline-testdsp6 component: data-science-pipelines dspa: testdsp6 diff --git a/controllers/testdata/declarative/case_6/expected/created/mlpipelines-ui_deployment.yaml b/controllers/testdata/declarative/case_6/expected/created/mlpipelines-ui_deployment.yaml index cd41b1b6..5d9d2f24 100644 --- a/controllers/testdata/declarative/case_6/expected/created/mlpipelines-ui_deployment.yaml +++ b/controllers/testdata/declarative/case_6/expected/created/mlpipelines-ui_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-ui-testdsp6 namespace: default labels: + dsp-version: v2 app: ds-pipeline-ui-testdsp6 component: data-science-pipelines dspa: testdsp6 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-ui-testdsp6 component: data-science-pipelines dspa: testdsp6 diff --git a/controllers/testdata/declarative/case_6/expected/created/persistence-agent_deployment.yaml b/controllers/testdata/declarative/case_6/expected/created/persistence-agent_deployment.yaml index f0d592c8..da50f82f 100644 --- a/controllers/testdata/declarative/case_6/expected/created/persistence-agent_deployment.yaml +++ b/controllers/testdata/declarative/case_6/expected/created/persistence-agent_deployment.yaml @@ -4,6 +4,7 @@ metadata: name: ds-pipeline-persistenceagent-testdsp6 namespace: default labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp6 component: data-science-pipelines dspa: testdsp6 @@ -18,6 +19,7 @@ spec: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "true" labels: + dsp-version: v2 app: ds-pipeline-persistenceagent-testdsp6 component: data-science-pipelines dspa: testdsp6 diff --git a/controllers/util/util.go b/controllers/util/util.go index 08276d52..469cbbc6 100644 --- a/controllers/util/util.go +++ b/controllers/util/util.go @@ -18,6 +18,9 @@ package util import ( "fmt" + mf "github.com/manifestival/manifestival" + dspav1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "os" "path/filepath" @@ -211,3 +214,69 @@ func GetSecret(ctx context.Context, secretName, ns string, client client.Client) } return secret, nil } + +// DSPAWithSupportedDSPVersion returns True if dspa's dsp version is supported, return False otherwise. +// Note that the procedure verifies the DSPA's .spec.dspVerson field. Not to be confused with the apiversion. +func DSPAWithSupportedDSPVersion(dspa *dspav1.DataSciencePipelinesApplication) bool { + isSupported := false + for _, supportedVersion := range config.GetSupportedDSPAVersions() { + if dspa.Spec.DSPVersion == supportedVersion { + isSupported = true + } + } + return isSupported +} + +// HasSupportedDSPVersionLabel returns true if labels (representing labels for a k8s resource) +// has the DSPVersionk8sLabel label AND the value belongs to a supported DSP Version +func HasSupportedDSPVersionLabel(labels map[string]string) bool { + version, ok := labels[config.DSPVersionk8sLabel] + if !ok { + return false + } + for _, supportedVersion := range config.GetSupportedDSPAVersions() { + if version == supportedVersion { + return true + } + } + return false +} + +func AddLabelTransformer(labelKey, labelValue string) mf.Transformer { + return func(mfObj *unstructured.Unstructured) error { + // Get existing labels + labels := mfObj.GetLabels() + if labels == nil { + labels = make(map[string]string) + } + // Add or override the label + labels[labelKey] = labelValue + // Set the labels back on the object + mfObj.SetLabels(labels) + return nil + } +} + +func AddDeploymentPodLabelTransformer(labelKey, labelValue string) mf.Transformer { + return func(mfObj *unstructured.Unstructured) error { + // Check if the resource is a Deployment + if mfObj.GetKind() == "Deployment" { + // Get the spec.template.metadata.labels (which are the Pod labels) + podLabels, found, err := unstructured.NestedStringMap(mfObj.Object, "spec", "template", "metadata", "labels") + if err != nil { + return err + } + if !found { + podLabels = make(map[string]string) + } + // Add or override the pod label + podLabels[labelKey] = labelValue + // Set the updated labels back to spec.template.metadata.labels + err = unstructured.SetNestedStringMap(mfObj.Object, podLabels, "spec", "template", "metadata", "labels") + if err != nil { + return fmt.Errorf("failed to set pod labels: %w", err) + } + } + return nil + } +}