diff --git a/controllers/apiserver.go b/controllers/apiserver.go index 929ede23..08d12e35 100644 --- a/controllers/apiserver.go +++ b/controllers/apiserver.go @@ -21,6 +21,7 @@ import ( dspav1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1" v1 "github.com/openshift/api/route/v1" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) @@ -39,31 +40,31 @@ var samplePipelineTemplates = map[string]string{ "sample-config": "apiserver/sample-pipeline/sample-config.yaml.tmpl", } -func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1.DataSciencePipelinesApplication, params *DSPAParams) error { +func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1.DataSciencePipelinesApplication, params *DSPAParams) (status metav1.ConditionStatus, description string) { log := r.Log.WithValues("namespace", dsp.Namespace).WithValues("dspa_name", dsp.Name) if !dsp.Spec.APIServer.Deploy { r.Log.Info("Skipping Application of APIServer Resources") - return nil + return metav1.ConditionTrue, "APIServer Deployment Skipped" } log.Info("Applying APIServer Resources") err := r.ApplyDir(dsp, params, apiServerTemplatesDir) if err != nil { - return err + return metav1.ConditionFalse, err.Error() } if dsp.Spec.APIServer.EnableRoute { err := r.Apply(dsp, params, serverRoute) if err != nil { - return err + return metav1.ConditionFalse, err.Error() } } else { route := &v1.Route{} namespacedNamed := types.NamespacedName{Name: "ds-pipeline-" + dsp.Name, Namespace: dsp.Namespace} err := r.DeleteResourceIfItExists(ctx, route, namespacedNamed) if err != nil { - return err + return metav1.ConditionFalse, err.Error() } } @@ -71,18 +72,18 @@ func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1.Dat if dsp.Spec.APIServer.EnableSamplePipeline { err := r.Apply(dsp, params, template) if err != nil { - return err + return metav1.ConditionFalse, err.Error() } } else { cm := &corev1.ConfigMap{} namespacedNamed := types.NamespacedName{Name: cmName + "-" + dsp.Name, Namespace: dsp.Namespace} err := r.DeleteResourceIfItExists(ctx, cm, namespacedNamed) if err != nil { - return err + return metav1.ConditionFalse, err.Error() } } } log.Info("Finished applying APIServer Resources") - return nil + return metav1.ConditionTrue, "APIServer Resources Deployed" } diff --git a/controllers/dspipeline_controller.go b/controllers/dspipeline_controller.go index 8f29d8da..28787016 100644 --- a/controllers/dspipeline_controller.go +++ b/controllers/dspipeline_controller.go @@ -19,6 +19,7 @@ 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" @@ -291,9 +292,9 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. return ctrl.Result{}, err } - err = r.ReconcileAPIServer(ctx, dspa, params) - if err != nil { - r.setStatusAsNotReady(config.APIServerReady, err, dspaStatus.SetApiServerStatus) + status, description := r.ReconcileAPIServer(ctx, dspa, params) + if status != metav1.ConditionTrue { + r.setStatusAsNotReady(config.APIServerReady, description, dspaStatus.SetApiServerStatus) return ctrl.Result{}, err } else { r.setStatus(ctx, params.APIServerDefaultResourceName, config.APIServerReady, dspa, @@ -364,8 +365,8 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. return ctrl.Result{}, nil } -func (r *DSPAReconciler) setStatusAsNotReady(conditionType string, err error, setStatus func(metav1.Condition)) { - condition := dspastatus.BuildFalseCondition(conditionType, config.FailingToDeploy, err.Error()) +func (r *DSPAReconciler) setStatusAsNotReady(conditionType string, description string, setStatus func(metav1.Condition)) { + condition := dspastatus.BuildFalseCondition(conditionType, config.FailingToDeploy, description) setStatus(condition) }