Skip to content

Commit

Permalink
chore: moves ArgoCD conditions to pipelines component (opendatahub-io…
Browse files Browse the repository at this point in the history
…#1071)

status.go is intended for general purpose funcs, not domain specific.
  • Loading branch information
bartoszmajsak authored Jun 20, 2024
1 parent 8e0998f commit 1268f3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
8 changes: 8 additions & 0 deletions components/datasciencepipelines/datasciencepipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
Expand Down Expand Up @@ -164,3 +167,8 @@ func UnmanagedArgoWorkFlowExists(ctx context.Context,
return fmt.Errorf("%s CRD already exists but not deployed by this operator. "+
"Remove existing Argo workflows or set `spec.components.datasciencepipelines.managementState` to Removed to proceed ", ArgoWorkflowCRD)
}

func SetExistingArgoCondition(conditions *[]conditionsv1.Condition, reason, message string) {
status.SetCondition(conditions, string(status.CapabilityDSPv2Argo), reason, message, corev1.ConditionFalse)
status.SetComponentCondition(conditions, ComponentName, status.ReconcileFailed, message, corev1.ConditionFalse)
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
instance, err = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dsc.DataScienceCluster) {
status.SetProgressingCondition(&saved.Status.Conditions, reason, message)
// Patch Degraded with True status
status.SetGeneralCondition(&saved.Status.Conditions, "Degraded", reason, message, corev1.ConditionTrue)
status.SetCondition(&saved.Status.Conditions, "Degraded", reason, message, corev1.ConditionTrue)
saved.Status.Phase = status.PhaseError
})
if err != nil {
Expand Down Expand Up @@ -211,7 +211,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
if err := datasciencepipelines.UnmanagedArgoWorkFlowExists(ctx, r.Client); err != nil {
message := fmt.Sprintf("Failed upgrade: %v ", err.Error())
_, err = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dsc.DataScienceCluster) {
status.SetExistingArgoCondition(&saved.Status.Conditions, status.ArgoWorkflowExist, message)
datasciencepipelines.SetExistingArgoCondition(&saved.Status.Conditions, status.ArgoWorkflowExist, message)
status.SetErrorCondition(&saved.Status.Conditions, status.ArgoWorkflowExist, message)
saved.Status.Phase = status.PhaseError
})
Expand Down Expand Up @@ -321,7 +321,7 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context
instance, _ = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dsc.DataScienceCluster) {
if enabled {
if strings.Contains(err.Error(), datasciencepipelines.ArgoWorkflowCRD+" CRD already exists") {
status.SetExistingArgoCondition(&saved.Status.Conditions, status.ArgoWorkflowExist, fmt.Sprintf("Component update failed: %v", err))
datasciencepipelines.SetExistingArgoCondition(&saved.Status.Conditions, status.ArgoWorkflowExist, fmt.Sprintf("Component update failed: %v", err))
} else {
status.SetComponentCondition(&saved.Status.Conditions, componentName, status.ReconcileFailed, fmt.Sprintf("Component reconciliation failed: %v", err), corev1.ConditionFalse)
}
Expand Down
40 changes: 10 additions & 30 deletions controllers/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package status
import (
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"

"github.com/opendatahub-io/opendatahub-operator/v2/components/datasciencepipelines"
)

// These constants represent the overall Phase as used by .Status.Phase.
Expand Down Expand Up @@ -191,41 +189,23 @@ func SetCompleteCondition(conditions *[]conditionsv1.Condition, reason string, m
conditionsv1.RemoveStatusCondition(conditions, CapabilityDSPv2Argo)
}

// SetComponentCondition appends Condition Type with const ReadySuffix for given component
// when component finished reconcile.
func SetComponentCondition(conditions *[]conditionsv1.Condition, component string, reason string, message string, status corev1.ConditionStatus) {
condtype := component + ReadySuffix
// SetCondition is a general purpose function to update any type of condition.
func SetCondition(conditions *[]conditionsv1.Condition, conditionType string, reason string, message string, status corev1.ConditionStatus) {
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{
Type: conditionsv1.ConditionType(condtype),
Type: conditionsv1.ConditionType(conditionType),
Status: status,
Reason: reason,
Message: message,
})
}

// RemoveComponentCondition remove Condition of giving component.
func RemoveComponentCondition(conditions *[]conditionsv1.Condition, component string) {
condType := component + ReadySuffix
conditionsv1.RemoveStatusCondition(conditions, conditionsv1.ConditionType(condType))
}

func SetExistingArgoCondition(conditions *[]conditionsv1.Condition, reason, message string) {
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{
Type: CapabilityDSPv2Argo,
Status: corev1.ConditionFalse,
Reason: reason,
Message: message,
})

SetComponentCondition(conditions, datasciencepipelines.ComponentName, ReconcileFailed, message, corev1.ConditionFalse)
// SetComponentCondition appends Condition Type with const ReadySuffix for given component
// when component finished reconcile.
func SetComponentCondition(conditions *[]conditionsv1.Condition, component string, reason string, message string, status corev1.ConditionStatus) {
SetCondition(conditions, component+ReadySuffix, reason, message, status)
}

// General function to patch any type of condition.
func SetGeneralCondition(conditions *[]conditionsv1.Condition, conditionType string, reason string, message string, status corev1.ConditionStatus) {
conditionsv1.SetStatusCondition(conditions, conditionsv1.Condition{
Type: conditionsv1.ConditionType(conditionType),
Status: status,
Reason: reason,
Message: message,
})
// RemoveComponentCondition remove Condition of giving component.
func RemoveComponentCondition(conditions *[]conditionsv1.Condition, component string) {
conditionsv1.RemoveStatusCondition(conditions, conditionsv1.ConditionType(component+ReadySuffix))
}

0 comments on commit 1268f3c

Please sign in to comment.