diff --git a/config/internal/apiserver/deployment.yaml.tmpl b/config/internal/apiserver/deployment.yaml.tmpl index 0a18293e..2e42d702 100644 --- a/config/internal/apiserver/deployment.yaml.tmpl +++ b/config/internal/apiserver/deployment.yaml.tmpl @@ -6,16 +6,19 @@ metadata: labels: app: ds-pipeline-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: selector: matchLabels: app: ds-pipeline-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: labels: app: ds-pipeline-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - env: diff --git a/config/internal/mariadb/deployment.yaml.tmpl b/config/internal/mariadb/deployment.yaml.tmpl index 0ae31f1b..88a9c1c5 100644 --- a/config/internal/mariadb/deployment.yaml.tmpl +++ b/config/internal/mariadb/deployment.yaml.tmpl @@ -7,6 +7,7 @@ metadata: labels: app: mariadb-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: strategy: # Need this since backing PVC is ReadWriteOnce, @@ -17,11 +18,13 @@ spec: matchLabels: app: mariadb-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: labels: app: mariadb-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - name: mariadb diff --git a/config/internal/minio/deployment.yaml.tmpl b/config/internal/minio/deployment.yaml.tmpl index 7c88621e..84a1c241 100644 --- a/config/internal/minio/deployment.yaml.tmpl +++ b/config/internal/minio/deployment.yaml.tmpl @@ -6,11 +6,13 @@ metadata: labels: app: minio-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: selector: matchLabels: app: minio-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} strategy: type: Recreate template: @@ -18,6 +20,7 @@ spec: labels: app: minio-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - args: diff --git a/config/internal/ml-metadata/metadata-envoy.deployment.yaml.tmpl b/config/internal/ml-metadata/metadata-envoy.deployment.yaml.tmpl index a7b1cc88..2ff91c07 100644 --- a/config/internal/ml-metadata/metadata-envoy.deployment.yaml.tmpl +++ b/config/internal/ml-metadata/metadata-envoy.deployment.yaml.tmpl @@ -6,12 +6,14 @@ metadata: labels: app: ds-pipeline-metadata-envoy-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: replicas: 1 selector: matchLabels: app: ds-pipeline-metadata-envoy-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: annotations: @@ -19,6 +21,7 @@ spec: labels: app: ds-pipeline-metadata-envoy-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - image: {{.MLMD.Envoy.Image}} diff --git a/config/internal/ml-metadata/metadata-grpc.deployment.yaml.tmpl b/config/internal/ml-metadata/metadata-grpc.deployment.yaml.tmpl index e6470200..543d03b6 100644 --- a/config/internal/ml-metadata/metadata-grpc.deployment.yaml.tmpl +++ b/config/internal/ml-metadata/metadata-grpc.deployment.yaml.tmpl @@ -6,17 +6,20 @@ metadata: labels: app: ds-pipeline-metadata-grpc-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: replicas: 1 selector: matchLabels: app: ds-pipeline-metadata-grpc-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: labels: app: ds-pipeline-metadata-grpc-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - args: diff --git a/config/internal/ml-metadata/metadata-writer.deployment.yaml.tmpl b/config/internal/ml-metadata/metadata-writer.deployment.yaml.tmpl index d6ff143c..39068eaf 100644 --- a/config/internal/ml-metadata/metadata-writer.deployment.yaml.tmpl +++ b/config/internal/ml-metadata/metadata-writer.deployment.yaml.tmpl @@ -6,17 +6,20 @@ metadata: labels: app: ds-pipeline-metadata-writer-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: replicas: 1 selector: matchLabels: app: ds-pipeline-metadata-writer-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: labels: app: ds-pipeline-metadata-writer-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - env: diff --git a/config/internal/mlpipelines-ui/deployment.yaml.tmpl b/config/internal/mlpipelines-ui/deployment.yaml.tmpl index c4f49b72..b85feebc 100644 --- a/config/internal/mlpipelines-ui/deployment.yaml.tmpl +++ b/config/internal/mlpipelines-ui/deployment.yaml.tmpl @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-ui-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: selector: matchLabels: app: ds-pipeline-ui-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-ui-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - env: diff --git a/config/internal/persistence-agent/deployment.yaml.tmpl b/config/internal/persistence-agent/deployment.yaml.tmpl index 2fd0d8ca..1c160ec5 100644 --- a/config/internal/persistence-agent/deployment.yaml.tmpl +++ b/config/internal/persistence-agent/deployment.yaml.tmpl @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-persistenceagent-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: selector: matchLabels: app: ds-pipeline-persistenceagent-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-persistenceagent-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - env: diff --git a/config/internal/scheduled-workflow/deployment.yaml.tmpl b/config/internal/scheduled-workflow/deployment.yaml.tmpl index ce2f5bf3..c5a5da5b 100644 --- a/config/internal/scheduled-workflow/deployment.yaml.tmpl +++ b/config/internal/scheduled-workflow/deployment.yaml.tmpl @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-scheduledworkflow-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: selector: matchLabels: app: ds-pipeline-scheduledworkflow-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-scheduledworkflow-{{.Name}} component: data-science-pipelines + dspa: {{.Name}} spec: containers: - env: diff --git a/controllers/config/defaults.go b/controllers/config/defaults.go index 628445ae..fdf841b9 100644 --- a/controllers/config/defaults.go +++ b/controllers/config/defaults.go @@ -67,12 +67,23 @@ const ( MlmdWriterImagePath = "Images.MlmdWriter" ) +// DSPA Status Condition Types +const ( + APIServerReady = "APIServerReady" + PersistenceAgentReady = "PersistenceAgentReady" + ScheduledWorkflowReady = "ScheduledWorkflowReady" + CrReady = "Ready" +) + +// DSPA Ready Status Condition Reasons +// As per k8s api convention: Reason is intended +// to be used in concise output, such as one-line +// kubectl get output, and in summarizing +// occurrences of causes const ( - APIServerReady = "APIServerReady" - PersistenceAgentReady = "PersistenceAgentReady" - ScheduledWorkflowReady = "ScheduledWorkflowReady" - CrReady = "Ready" MinimumReplicasAvailable = "MinimumReplicasAvailable" + FailingToDeploy = "FailingToDeploy" + Deploying = "Deploying" ) // Any required Configmap paths can be added here, diff --git a/controllers/dspipeline_controller.go b/controllers/dspipeline_controller.go index 90e47dd5..e790037b 100644 --- a/controllers/dspipeline_controller.go +++ b/controllers/dspipeline_controller.go @@ -19,11 +19,11 @@ package controllers import ( "context" "fmt" - "github.com/go-logr/logr" mf "github.com/manifestival/manifestival" dspav1alpha1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1" "github.com/opendatahub-io/data-science-pipelines-operator/controllers/config" + "github.com/opendatahub-io/data-science-pipelines-operator/controllers/util" routev1 "github.com/openshift/api/route/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -35,6 +35,9 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" ) const finalizerName = "datasciencepipelinesapplications.opendatahub.io/finalizer" @@ -119,26 +122,6 @@ func (r *DSPAReconciler) buildCondition(conditionType string, dspa *dspav1alpha1 return condition } -func (r *DSPAReconciler) isDeploymentAvailable(ctx context.Context, dspa *dspav1alpha1.DataSciencePipelinesApplication, name string) bool { - found := &appsv1.Deployment{} - - // Every Deployment in DSPA is the name followed by the DSPA CR name - component := name + "-" + dspa.Name - - err := r.Get(ctx, types.NamespacedName{Name: component, Namespace: dspa.Namespace}, found) - if err == nil { - if found.Spec.Replicas != nil && *found.Spec.Replicas == 0 { - return false - } - for _, s := range found.Status.Conditions { - if s.Type == "Available" && s.Status == corev1.ConditionTrue { - return true - } - } - } - return false -} - //+kubebuilder:rbac:groups=datasciencepipelinesapplications.opendatahub.io,resources=datasciencepipelinesapplications,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=datasciencepipelinesapplications.opendatahub.io,resources=datasciencepipelinesapplications/status,verbs=get;update;patch //+kubebuilder:rbac:groups=datasciencepipelinesapplications.opendatahub.io,resources=datasciencepipelinesapplications/finalizers,verbs=update @@ -222,9 +205,6 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. return ctrl.Result{}, nil } - // Initialize conditions - var conditions []metav1.Condition - err = r.ReconcileDatabase(ctx, dspa, params) if err != nil { return ctrl.Result{}, err @@ -240,39 +220,21 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. return ctrl.Result{}, err } - apiServerReady := r.buildCondition(config.APIServerReady, dspa, config.MinimumReplicasAvailable) err = r.ReconcileAPIServer(ctx, dspa, params) if err != nil { return ctrl.Result{}, err } - if r.isDeploymentAvailable(ctx, dspa, "ds-pipeline") { - apiServerReady.Status = metav1.ConditionTrue - } - conditions = append(conditions, apiServerReady) - - persistenceAgentReady := r.buildCondition(config.PersistenceAgentReady, dspa, config.MinimumReplicasAvailable) err = r.ReconcilePersistenceAgent(dspa, params) if err != nil { return ctrl.Result{}, err } - if r.isDeploymentAvailable(ctx, dspa, "ds-pipeline-persistenceagent") { - persistenceAgentReady.Status = metav1.ConditionTrue - } - conditions = append(conditions, persistenceAgentReady) - - scheduledWorkflowReady := r.buildCondition(config.ScheduledWorkflowReady, dspa, config.MinimumReplicasAvailable) err = r.ReconcileScheduledWorkflow(dspa, params) if err != nil { return ctrl.Result{}, err } - if r.isDeploymentAvailable(ctx, dspa, "ds-pipeline-scheduledworkflow") { - scheduledWorkflowReady.Status = metav1.ConditionTrue - } - conditions = append(conditions, scheduledWorkflowReady) - err = r.ReconcileUI(dspa, params) if err != nil { return ctrl.Result{}, err @@ -291,16 +253,187 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. return ctrl.Result{}, err } + conditions, err := r.GenerateStatus(ctx, dspa) + if err != nil { + log.Info(err.Error()) + return ctrl.Result{}, err + } + dspa.Status.Conditions = conditions + + // Update Status + err = r.Status().Update(ctx, dspa) + if err != nil { + log.Info(err.Error()) + return ctrl.Result{}, err + } + + r.PublishMetrics( + dspa, + util.GetConditionByType(config.APIServerReady, conditions), + util.GetConditionByType(config.PersistenceAgentReady, conditions), + util.GetConditionByType(config.ScheduledWorkflowReady, conditions), + util.GetConditionByType(config.CrReady, conditions), + ) + + return ctrl.Result{}, nil +} + +// handleReadyCondition evaluates if condition with "name" is in condition of type "conditionType". +// this procedure is valid only for conditions with bool status type, for conditions of non bool type +// results are undefined. +func (r *DSPAReconciler) handleReadyCondition( + ctx context.Context, + dspa *dspav1alpha1.DataSciencePipelinesApplication, + name string, + condition string, +) (metav1.Condition, error) { + readyCondition := r.buildCondition(condition, dspa, config.MinimumReplicasAvailable) + deployment := &appsv1.Deployment{} + + // Every Deployment in DSPA is the name followed by the DSPA CR name + component := name + "-" + dspa.Name + + err := r.Get(ctx, types.NamespacedName{Name: component, Namespace: dspa.Namespace}, deployment) + if err != nil { + return metav1.Condition{}, err + } + + // First check if deployment is scaled down, if it is, component is deemed not ready + if deployment.Spec.Replicas != nil && *deployment.Spec.Replicas == 0 { + readyCondition.Reason = config.MinimumReplicasAvailable + readyCondition.Status = metav1.ConditionFalse + readyCondition.Message = fmt.Sprintf("Deployment for component \"%s\" is scaled down.", component) + return readyCondition, nil + } + + // At this point component is not minimally available, possible scenarios: + // 1. Component deployment has encountered errors + // 2. Component is still deploying + // We check for (1), and if no errors are found we presume (2) + + progressingCond := util.GetDeploymentCondition(deployment.Status, appsv1.DeploymentProgressing) + availableCond := util.GetDeploymentCondition(deployment.Status, appsv1.DeploymentAvailable) + replicaFailureCond := util.GetDeploymentCondition(deployment.Status, appsv1.DeploymentReplicaFailure) + + if availableCond != nil && availableCond.Status == corev1.ConditionTrue { + // If this DSPA component is minimally available, we are done. + readyCondition.Reason = config.MinimumReplicasAvailable + readyCondition.Status = metav1.ConditionTrue + readyCondition.Message = fmt.Sprintf("Component [%s] is minimally available.", component) + return readyCondition, nil + } + + // There are two possible reasons for progress failing, deadline and replica create error: + // https://github.com/kubernetes/kubernetes/blob/release-1.27/pkg/controller/deployment/util/deployment_util.go#L69 + // We check for both to investigate potential issues during deployment + if progressingCond != nil && progressingCond.Status == corev1.ConditionFalse && + (progressingCond.Reason == "ProgressDeadlineExceeded" || progressingCond.Reason == "ReplicaSetCreateError") { + readyCondition.Reason = config.FailingToDeploy + readyCondition.Status = metav1.ConditionFalse + readyCondition.Message = fmt.Sprintf("Component [%s] has failed to progress. Reason: [%s]. "+ + "Message: [%s]", component, progressingCond.Reason, progressingCond.Message) + return readyCondition, nil + } + + if replicaFailureCond != nil && replicaFailureCond.Status == corev1.ConditionTrue { + readyCondition.Reason = config.FailingToDeploy + readyCondition.Status = metav1.ConditionFalse + readyCondition.Message = fmt.Sprintf("Component's replica [%s] has failed to create. Reason: [%s]. "+ + "Message: [%s]", component, replicaFailureCond.Reason, replicaFailureCond.Message) + return readyCondition, nil + } + + // Search through the pods associated with this deployment + // if a failed pod is encountered, report Ready=false with failure + // message + podList := &corev1.PodList{} + opts := []client.ListOption{ + client.MatchingLabels(deployment.Spec.Selector.MatchLabels), + } + err = r.Client.List(ctx, podList, opts...) + if err != nil { + return metav1.Condition{}, err + } + + hasPodFailures := false + podFailureMessage := "" + // We loop through all pods within this deployment and inspect their statuses for failures + // Any failure detected in any pod results in FailingToDeploy status + for _, p := range podList.Items { + if p.Status.Phase == corev1.PodFailed { + hasPodFailures = true + podFailureMessage += fmt.Sprintf("Pod named [%s] that is associated with this component [%s] "+ + "is in failed phase.", p.Name, component) + } + // We loop through the containers in each pod, as in some cases the Pod can be in pending state + // but an individual container may be failing due to runtime errors. + for _, c := range p.Status.ContainerStatuses { + if c.State.Waiting != nil && c.State.Waiting.Reason == "CrashLoopBackOff" { + readyCondition.Reason = config.FailingToDeploy + readyCondition.Status = metav1.ConditionFalse + // We concatenate messages from all failing containers. + readyCondition.Message = fmt.Sprintf("Component [%s] is in CrashLoopBackOff. "+ + "Message from pod: [%s]", component, c.State.Waiting.Message) + return readyCondition, nil + } + } + } + + if hasPodFailures { + readyCondition.Status = metav1.ConditionFalse + readyCondition.Reason = config.FailingToDeploy + readyCondition.Message = podFailureMessage + return readyCondition, nil + } + + // No errors encountered, assume deployment is progressing successfully + // If this DSPA component is minimally available, we are done. + readyCondition.Reason = config.Deploying + readyCondition.Status = metav1.ConditionFalse + readyCondition.Message = fmt.Sprintf("Component [%s] is deploying.", component) + return readyCondition, nil + +} + +func (r *DSPAReconciler) GenerateStatus(ctx context.Context, dspa *dspav1alpha1.DataSciencePipelinesApplication) ([]metav1.Condition, error) { + + apiServerReady, err := r.handleReadyCondition(ctx, dspa, "ds-pipeline", config.APIServerReady) + if err != nil { + return []metav1.Condition{}, err + } + persistenceAgentReady, err := r.handleReadyCondition(ctx, dspa, "ds-pipeline-persistenceagent", config.PersistenceAgentReady) + if err != nil { + return []metav1.Condition{}, err + } + scheduledWorkflowReady, err := r.handleReadyCondition(ctx, dspa, "ds-pipeline-scheduledworkflow", config.ScheduledWorkflowReady) + if err != nil { + return []metav1.Condition{}, err + } + var conditions []metav1.Condition + conditions = append(conditions, apiServerReady) + conditions = append(conditions, persistenceAgentReady) + conditions = append(conditions, scheduledWorkflowReady) + + // Compute Ready Logic for the CR crReady := r.buildCondition(config.CrReady, dspa, config.MinimumReplicasAvailable) crReady.Type = config.CrReady - // Compute Ready Logic for the CR - if (apiServerReady.Status == metav1.ConditionTrue) && - (persistenceAgentReady.Status == metav1.ConditionTrue) && - (scheduledWorkflowReady.Status == metav1.ConditionTrue) { + componentConditions := []metav1.Condition{apiServerReady, persistenceAgentReady, scheduledWorkflowReady} + allReady := true + failureMessages := "" + for _, c := range componentConditions { + if c.Status == metav1.ConditionFalse { + allReady = false + failureMessages += fmt.Sprintf("%s \n", c.Message) + } + } + + if allReady { crReady.Status = metav1.ConditionTrue + crReady.Message = "All components are ready." } else { crReady.Status = metav1.ConditionFalse + crReady.Message = failureMessages } conditions = append(conditions, crReady) @@ -309,18 +442,8 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. conditions[i].LastTransitionTime = condition.LastTransitionTime } } - dspa.Status.Conditions = conditions - - // Update Status - err = r.Status().Update(ctx, dspa) - if err != nil { - log.Info(err.Error()) - return ctrl.Result{}, err - } - r.PublishMetrics(dspa, apiServerReady, persistenceAgentReady, scheduledWorkflowReady, crReady) - - return ctrl.Result{}, nil + return conditions, nil } func (r *DSPAReconciler) PublishMetrics(dspa *dspav1alpha1.DataSciencePipelinesApplication, @@ -374,6 +497,33 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error { Owns(&rbacv1.Role{}). Owns(&rbacv1.RoleBinding{}). Owns(&routev1.Route{}). + // Watch for Pods belonging to DSPA + Watches(&source.Kind{Type: &corev1.Pod{}}, + handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { + log := r.Log.WithValues("namespace", o.GetNamespace()) + + component, hasComponentLabel := o.GetLabels()["component"] + + if !hasComponentLabel || (component != "data-science-pipelines") { + return []reconcile.Request{} + } + + dspaName, hasDSPALabel := o.GetLabels()["dspa"] + if !hasDSPALabel { + msg := fmt.Sprintf("Pod with data-science-pipelines label encountered, but is missing dspa "+ + "label, could not reconcile on [Pod: %s] ", o.GetName()) + log.V(1).Info(msg) + return []reconcile.Request{} + } + + log.V(1).Info(fmt.Sprintf("Reconcile event triggered by [Pod: %s] ", o.GetName())) + namespacedName := types.NamespacedName{ + Name: dspaName, + Namespace: o.GetNamespace(), + } + reconcileRequests := append([]reconcile.Request{}, reconcile.Request{NamespacedName: namespacedName}) + return reconcileRequests + })). // TODO: Add watcher for ui cluster rbac since it has no owner Complete(r) } diff --git a/controllers/dspipeline_params.go b/controllers/dspipeline_params.go index 0a35e0e1..bac9946b 100644 --- a/controllers/dspipeline_params.go +++ b/controllers/dspipeline_params.go @@ -320,8 +320,8 @@ func (p *DSPAParams) SetupObjectParams(ctx context.Context, dsp *dspa.DataScienc p.ObjectStorageConnection.SecretAccessKey = base64.StdEncoding.EncodeToString([]byte(generatedPass)) createNewSecret = true } else { - log.Error(err, fmt.Sprintf("Storage secret %s was specified in CR but does not exist.", - p.ObjectStorageConnection.CredentialsSecret.SecretName)) + log.Error(err, fmt.Sprintf("Storage secret [%s] was specified in CR but does not exist.", + credsSecretName)) return err } } else if err != nil { 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 3db41f0a..fa277a79 100644 --- a/controllers/testdata/declarative/case_0/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_0/expected/created/apiserver_deployment.yaml @@ -6,16 +6,19 @@ metadata: labels: app: ds-pipeline-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: selector: matchLabels: app: ds-pipeline-testdsp0 component: data-science-pipelines + dspa: testdsp0 template: metadata: labels: app: ds-pipeline-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: containers: - env: 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 92682abd..20aad1f7 100644 --- a/controllers/testdata/declarative/case_0/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_0/expected/created/mariadb_deployment.yaml @@ -7,6 +7,7 @@ metadata: labels: app: mariadb-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: strategy: type: Recreate # Need this since backing PVC is ReadWriteOnce, which creates resource lock condition in default Rolling strategy @@ -14,11 +15,13 @@ spec: matchLabels: app: mariadb-testdsp0 component: data-science-pipelines + dspa: testdsp0 template: metadata: labels: app: mariadb-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: containers: - name: mariadb 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 3cda498b..bf0171dc 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-persistenceagent-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: selector: matchLabels: app: ds-pipeline-persistenceagent-testdsp0 component: data-science-pipelines + dspa: testdsp0 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-persistenceagent-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: containers: - env: 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 5885adbb..d069ca8f 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-scheduledworkflow-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: selector: matchLabels: app: ds-pipeline-scheduledworkflow-testdsp0 component: data-science-pipelines + dspa: testdsp0 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-scheduledworkflow-testdsp0 component: data-science-pipelines + dspa: testdsp0 spec: containers: - env: 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 0ae55256..5c126382 100644 --- a/controllers/testdata/declarative/case_2/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/apiserver_deployment.yaml @@ -6,16 +6,19 @@ metadata: labels: app: ds-pipeline-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: selector: matchLabels: app: ds-pipeline-testdsp2 component: data-science-pipelines + dspa: testdsp2 template: metadata: labels: app: ds-pipeline-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: containers: - env: 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 9076adf1..d122f60d 100644 --- a/controllers/testdata/declarative/case_2/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/mariadb_deployment.yaml @@ -7,6 +7,7 @@ metadata: labels: app: mariadb-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: strategy: type: Recreate # Need this since backing PVC is ReadWriteOnce, which creates resource lock condition in default Rolling strategy @@ -14,11 +15,13 @@ spec: matchLabels: app: mariadb-testdsp2 component: data-science-pipelines + dspa: testdsp2 template: metadata: labels: app: mariadb-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: containers: - name: mariadb 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 65b55da1..8bf87f74 100644 --- a/controllers/testdata/declarative/case_2/expected/created/minio_deployment.yaml +++ b/controllers/testdata/declarative/case_2/expected/created/minio_deployment.yaml @@ -6,11 +6,13 @@ metadata: labels: app: minio-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: selector: matchLabels: app: minio-testdsp2 component: data-science-pipelines + dspa: testdsp2 strategy: type: Recreate template: @@ -18,6 +20,7 @@ spec: labels: app: minio-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: containers: - args: 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 06cfba85..4430c650 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-ui-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: selector: matchLabels: app: ds-pipeline-ui-testdsp2 component: data-science-pipelines + dspa: testdsp2 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-ui-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: containers: - env: 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 9c5a77ad..8342eace 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-persistenceagent-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: selector: matchLabels: app: ds-pipeline-persistenceagent-testdsp2 component: data-science-pipelines + dspa: testdsp2 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-persistenceagent-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: containers: - env: 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 1f889d32..f912bc2f 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-scheduledworkflow-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: selector: matchLabels: app: ds-pipeline-scheduledworkflow-testdsp2 component: data-science-pipelines + dspa: testdsp2 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-scheduledworkflow-testdsp2 component: data-science-pipelines + dspa: testdsp2 spec: containers: - env: 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 accfd5e7..0b617788 100644 --- a/controllers/testdata/declarative/case_3/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_3/expected/created/apiserver_deployment.yaml @@ -6,16 +6,19 @@ metadata: labels: app: ds-pipeline-testdsp3 component: data-science-pipelines + dspa: testdsp3 spec: selector: matchLabels: app: ds-pipeline-testdsp3 component: data-science-pipelines + dspa: testdsp3 template: metadata: labels: app: ds-pipeline-testdsp3 component: data-science-pipelines + dspa: testdsp3 spec: containers: - env: 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 dd80d9d2..94524294 100644 --- a/controllers/testdata/declarative/case_4/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/apiserver_deployment.yaml @@ -6,16 +6,19 @@ metadata: labels: app: ds-pipeline-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: selector: matchLabels: app: ds-pipeline-testdsp4 component: data-science-pipelines + dspa: testdsp4 template: metadata: labels: app: ds-pipeline-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: containers: - env: 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 54df48ea..3130c29a 100644 --- a/controllers/testdata/declarative/case_4/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/mariadb_deployment.yaml @@ -7,6 +7,7 @@ metadata: labels: app: mariadb-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: strategy: type: Recreate # Need this since backing PVC is ReadWriteOnce, which creates resource lock condition in default Rolling strategy @@ -14,11 +15,13 @@ spec: matchLabels: app: mariadb-testdsp4 component: data-science-pipelines + dspa: testdsp4 template: metadata: labels: app: mariadb-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: containers: - name: mariadb 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 5a672b60..df569957 100644 --- a/controllers/testdata/declarative/case_4/expected/created/minio_deployment.yaml +++ b/controllers/testdata/declarative/case_4/expected/created/minio_deployment.yaml @@ -6,11 +6,13 @@ metadata: labels: app: minio-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: selector: matchLabels: app: minio-testdsp4 component: data-science-pipelines + dspa: testdsp4 strategy: type: Recreate template: @@ -18,6 +20,7 @@ spec: labels: app: minio-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: containers: - args: 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 abc6f1f0..131b3cca 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-ui-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: selector: matchLabels: app: ds-pipeline-ui-testdsp4 component: data-science-pipelines + dspa: testdsp4 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-ui-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: containers: - env: 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 08fee7bd..da750bb9 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-persistenceagent-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: selector: matchLabels: app: ds-pipeline-persistenceagent-testdsp4 component: data-science-pipelines + dspa: testdsp4 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-persistenceagent-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: containers: - env: 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 2e3d9c80..0d7e88db 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 @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-scheduledworkflow-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: selector: matchLabels: app: ds-pipeline-scheduledworkflow-testdsp4 component: data-science-pipelines + dspa: testdsp4 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-scheduledworkflow-testdsp4 component: data-science-pipelines + dspa: testdsp4 spec: containers: - env: 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 7ecef37a..92f6ac5b 100644 --- a/controllers/testdata/declarative/case_5/expected/created/apiserver_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/apiserver_deployment.yaml @@ -6,16 +6,19 @@ metadata: labels: app: ds-pipeline-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: selector: matchLabels: app: ds-pipeline-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: labels: app: ds-pipeline-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - env: 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 94df4daf..95276f7f 100644 --- a/controllers/testdata/declarative/case_5/expected/created/mariadb_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/mariadb_deployment.yaml @@ -7,6 +7,7 @@ metadata: labels: app: mariadb-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: strategy: type: Recreate # Need this since backing PVC is ReadWriteOnce, which creates resource lock condition in default Rolling strategy @@ -14,11 +15,13 @@ spec: matchLabels: app: mariadb-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: labels: app: mariadb-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - name: mariadb diff --git a/controllers/testdata/declarative/case_5/expected/created/metadata-envoy_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/metadata-envoy_deployment.yaml index b8dfebe7..d1137512 100644 --- a/controllers/testdata/declarative/case_5/expected/created/metadata-envoy_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/metadata-envoy_deployment.yaml @@ -6,12 +6,14 @@ metadata: labels: app: ds-pipeline-metadata-envoy-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: replicas: 1 selector: matchLabels: app: ds-pipeline-metadata-envoy-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: annotations: @@ -19,6 +21,7 @@ spec: labels: app: ds-pipeline-metadata-envoy-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - image: metadata-envoy:test5 diff --git a/controllers/testdata/declarative/case_5/expected/created/metadata-grpc_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/metadata-grpc_deployment.yaml index 6c202e0f..48b8e395 100644 --- a/controllers/testdata/declarative/case_5/expected/created/metadata-grpc_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/metadata-grpc_deployment.yaml @@ -6,17 +6,20 @@ metadata: labels: app: ds-pipeline-metadata-grpc-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: replicas: 1 selector: matchLabels: app: ds-pipeline-metadata-grpc-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: labels: app: ds-pipeline-metadata-grpc-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - args: diff --git a/controllers/testdata/declarative/case_5/expected/created/metadata-writer_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/metadata-writer_deployment.yaml index 4248db02..908cf42c 100644 --- a/controllers/testdata/declarative/case_5/expected/created/metadata-writer_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/metadata-writer_deployment.yaml @@ -6,17 +6,20 @@ metadata: labels: app: ds-pipeline-metadata-writer-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: replicas: 1 selector: matchLabels: app: ds-pipeline-metadata-writer-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: labels: app: ds-pipeline-metadata-writer-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - env: diff --git a/controllers/testdata/declarative/case_5/expected/created/mlpipelines-ui_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/mlpipelines-ui_deployment.yaml index d9664634..da690063 100644 --- a/controllers/testdata/declarative/case_5/expected/created/mlpipelines-ui_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/mlpipelines-ui_deployment.yaml @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-ui-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: selector: matchLabels: app: ds-pipeline-ui-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-ui-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - env: diff --git a/controllers/testdata/declarative/case_5/expected/created/persistence-agent_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/persistence-agent_deployment.yaml index 0d4ccd5d..3255d128 100644 --- a/controllers/testdata/declarative/case_5/expected/created/persistence-agent_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/persistence-agent_deployment.yaml @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-persistenceagent-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: selector: matchLabels: app: ds-pipeline-persistenceagent-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-persistenceagent-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - env: diff --git a/controllers/testdata/declarative/case_5/expected/created/scheduled-workflow_deployment.yaml b/controllers/testdata/declarative/case_5/expected/created/scheduled-workflow_deployment.yaml index fb06409b..d03c4daf 100644 --- a/controllers/testdata/declarative/case_5/expected/created/scheduled-workflow_deployment.yaml +++ b/controllers/testdata/declarative/case_5/expected/created/scheduled-workflow_deployment.yaml @@ -6,11 +6,13 @@ metadata: labels: app: ds-pipeline-scheduledworkflow-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: selector: matchLabels: app: ds-pipeline-scheduledworkflow-testdsp5 component: data-science-pipelines + dspa: testdsp5 template: metadata: annotations: @@ -18,6 +20,7 @@ spec: labels: app: ds-pipeline-scheduledworkflow-testdsp5 component: data-science-pipelines + dspa: testdsp5 spec: containers: - env: diff --git a/controllers/util/util.go b/controllers/util/util.go new file mode 100644 index 00000000..7aef462e --- /dev/null +++ b/controllers/util/util.go @@ -0,0 +1,42 @@ +/* +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 util + +import ( + appsv1 "k8s.io/api/apps/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// GetConditionByType returns condition of type condType if it exists in conditions, otherwise +// return empty condition struct. +func GetConditionByType(condType string, conditions []metav1.Condition) metav1.Condition { + for _, c := range conditions { + if c.Type == condType { + return c + } + } + return metav1.Condition{} +} + +func GetDeploymentCondition(status appsv1.DeploymentStatus, condType appsv1.DeploymentConditionType) *appsv1.DeploymentCondition { + for _, c := range status.Conditions { + if c.Type == condType { + return &c + } + } + return nil +}