Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor reconcilor so each component is returning status
Browse files Browse the repository at this point in the history
Signed-off-by: Anish Asthana <[email protected]>
anishasthana committed Dec 30, 2024
1 parent 16ffc77 commit 6bb520f
Showing 2 changed files with 15 additions and 13 deletions.
17 changes: 9 additions & 8 deletions controllers/apiserver.go
Original file line number Diff line number Diff line change
@@ -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,50 +40,50 @@ 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()
}
}

for cmName, template := range samplePipelineTemplates {
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"
}
11 changes: 6 additions & 5 deletions controllers/dspipeline_controller.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 6bb520f

Please sign in to comment.