Skip to content

Commit

Permalink
Implements logic for new status cond. and fields
Browse files Browse the repository at this point in the history
Signed-off-by: Joaquim Moreno Prusi <joaquim@redhat.com>
  • Loading branch information
jmprusi authored and tmshort committed May 16, 2023
1 parent bfb8716 commit 4ea83e6
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 6 deletions.
44 changes: 44 additions & 0 deletions controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
// Set the TypeResolved condition to Unknown to indicate that the resolution
// hasn't been attempted yet, due to the spec being invalid.
op.Status.ResolvedBundleResource = ""
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
Type: operatorsv1alpha1.TypeResolved,
Status: metav1.ConditionUnknown,
Reason: operatorsv1alpha1.ReasonResolutionUnknown,
Message: "validation has not been attempted as spec is invalid",
ObservedGeneration: op.GetGeneration(),
})
return ctrl.Result{}, nil
}
// run resolution
Expand All @@ -125,6 +135,14 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
op.Status.ResolvedBundleResource = ""
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
Type: operatorsv1alpha1.TypeResolved,
Status: metav1.ConditionFalse,
Reason: operatorsv1alpha1.ReasonResolutionFailed,
Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
return ctrl.Result{}, err
}

Expand All @@ -139,6 +157,14 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
op.Status.ResolvedBundleResource = ""
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
Type: operatorsv1alpha1.TypeResolved,
Status: metav1.ConditionFalse,
Reason: operatorsv1alpha1.ReasonResolutionFailed,
Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
return ctrl.Result{}, err
}

Expand All @@ -152,9 +178,27 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
op.Status.ResolvedBundleResource = ""
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
Type: operatorsv1alpha1.TypeResolved,
Status: metav1.ConditionFalse,
Reason: operatorsv1alpha1.ReasonResolutionFailed,
Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
return ctrl.Result{}, err
}

// Now we can set the Resolved Condition, and the resolvedBundleSource field to the bundleImage value.
op.Status.ResolvedBundleResource = bundleImage
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
Type: operatorsv1alpha1.TypeResolved,
Status: metav1.ConditionTrue,
Reason: operatorsv1alpha1.ReasonSuccess,
Message: fmt.Sprintf("resolved to %q", bundleImage),
ObservedGeneration: op.GetGeneration(),
})

// Ensure a BundleDeployment exists with its bundle source from the bundle
// image we just looked up in the solution.
dep := r.generateExpectedBundleDeployment(*op, bundleImage)
Expand Down
Loading

0 comments on commit 4ea83e6

Please sign in to comment.