Skip to content

✨ Cleaner Condition Types & Reasons #1007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 22, 2024
17 changes: 6 additions & 11 deletions api/v1alpha1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,17 @@ const (
ReasonErrorGettingClient = "ErrorGettingClient"
ReasonBundleLoadFailed = "BundleLoadFailed"

ReasonInstallationFailed = "InstallationFailed"
ReasonInstallationStatusUnknown = "InstallationStatusUnknown"
ReasonInstallationSucceeded = "InstallationSucceeded"
ReasonResolutionFailed = "ResolutionFailed"
ReasonInstallationFailed = "InstallationFailed"
ReasonResolutionFailed = "ResolutionFailed"

ReasonSuccess = "Success"
ReasonDeprecated = "Deprecated"
ReasonUpgradeFailed = "UpgradeFailed"

ReasonUnpackPending = "UnpackPending"
ReasonUnpackSuccess = "UnpackSuccess"
ReasonUnpackFailed = "UnpackFailed"

ReasonErrorGettingReleaseState = "ErrorGettingReleaseState"
ReasonCreateDynamicWatchFailed = "CreateDynamicWatchFailed"
)

func init() {
Expand All @@ -158,20 +154,16 @@ func init() {
)
// TODO(user): add Reasons from above
conditionsets.ConditionReasons = append(conditionsets.ConditionReasons,
ReasonInstallationSucceeded,
ReasonResolutionFailed,
ReasonInstallationFailed,
ReasonSuccess,
ReasonDeprecated,
ReasonUpgradeFailed,
ReasonBundleLoadFailed,
ReasonErrorGettingClient,
ReasonInstallationStatusUnknown,
ReasonUnpackPending,
ReasonUnpackSuccess,
ReasonUnpackFailed,
ReasonErrorGettingReleaseState,
ReasonCreateDynamicWatchFailed,
)
}

Expand All @@ -180,8 +172,11 @@ type BundleMetadata struct {
Version string `json:"version"`
}

// ClusterExtensionStatus defines the observed state of ClusterExtension
// ClusterExtensionStatus defines the observed state of ClusterExtension.
type ClusterExtensionStatus struct {
// InstalledBundle should only be modified when a new bundle is successfully installed. This ensures that if there
// is a previously successfully installed a bundle, and an upgrade fails, it is still communicated that there is
// still a bundle that is currently installed and owned by the ClusterExtension.
// +optional
InstalledBundle *BundleMetadata `json:"installedBundle,omitempty"`
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ spec:
- serviceAccount
type: object
status:
description: ClusterExtensionStatus defines the observed state of ClusterExtension
description: ClusterExtensionStatus defines the observed state of ClusterExtension.
properties:
conditions:
items:
Expand Down Expand Up @@ -188,6 +188,10 @@ spec:
- type
x-kubernetes-list-type: map
installedBundle:
description: |-
InstalledBundle should only be modified when a new bundle is successfully installed. This ensures that if there
is a previously successfully installed a bundle, and an upgrade fails, it is still communicated that there is
still a bundle that is currently installed and owned by the ClusterExtension.
properties:
name:
type: string
Expand Down
9 changes: 4 additions & 5 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,8 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp

switch unpackResult.State {
case rukpaksource.StatePending:
setStatusUnpackPending(ext, unpackResult.Message)
setInstalledStatusConditionUnknown(ext, "installation has not been attempted as unpack is pending")

setStatusUnpackFailed(ext, unpackResult.Message)
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonUnpackFailed, "unpack pending")
return ctrl.Result{}, nil
case rukpaksource.StateUnpacked:
setStatusUnpacked(ext, fmt.Sprintf("unpack successful: %v", unpackResult.Message))
Expand Down Expand Up @@ -400,7 +399,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
l.V(1).Info("configuring watches for release objects")
relObjects, err := util.ManifestObjects(strings.NewReader(rel.Manifest), fmt.Sprintf("%s-release-manifest", rel.Name))
if err != nil {
setInstalledStatusConditionFailed(ext, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonCreateDynamicWatchFailed, err))
setInstalledStatusConditionFailed(ext, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonInstallationFailed, err))
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -430,7 +429,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
return nil
}(); err != nil {
ext.Status.InstalledBundle = nil
setInstalledStatusConditionFailed(ext, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonCreateDynamicWatchFailed, err))
setInstalledStatusConditionFailed(ext, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonInstallationFailed, err))
return ctrl.Result{}, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/clusterextension_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestClusterExtensionResolutionSucceeds(t *testing.T) {
unpackedCond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeUnpacked)
require.NotNil(t, unpackedCond)
require.Equal(t, metav1.ConditionFalse, unpackedCond.Status)
require.Equal(t, ocv1alpha1.ReasonUnpackPending, unpackedCond.Reason)
require.Equal(t, ocv1alpha1.ReasonUnpackFailed, unpackedCond.Reason)

require.NoError(t, cl.DeleteAllOf(ctx, &ocv1alpha1.ClusterExtension{}))
}
Expand Down
23 changes: 0 additions & 23 deletions internal/controllers/common_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ func setResolvedStatusConditionSuccess(ext *ocv1alpha1.ClusterExtension, message
})
}

// setInstalledStatusConditionUnknown sets the installed status condition to unknown.
func setInstalledStatusConditionUnknown(ext *ocv1alpha1.ClusterExtension, message string) {
apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{
Type: ocv1alpha1.TypeInstalled,
Status: metav1.ConditionUnknown,
Reason: ocv1alpha1.ReasonInstallationStatusUnknown,
Message: message,
ObservedGeneration: ext.GetGeneration(),
})
}

// setResolvedStatusConditionFailed sets the resolved status condition to failed.
func setResolvedStatusConditionFailed(ext *ocv1alpha1.ClusterExtension, message string) {
apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{
Expand Down Expand Up @@ -109,18 +98,6 @@ func setStatusUnpackFailed(ext *ocv1alpha1.ClusterExtension, message string) {
})
}

// TODO: verify if we need to update the installBundle status or leave it as is.
func setStatusUnpackPending(ext *ocv1alpha1.ClusterExtension, message string) {
ext.Status.InstalledBundle = nil
apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{
Type: ocv1alpha1.TypeUnpacked,
Status: metav1.ConditionFalse,
Reason: ocv1alpha1.ReasonUnpackPending,
Message: message,
ObservedGeneration: ext.GetGeneration(),
})
}

func setStatusUnpacked(ext *ocv1alpha1.ClusterExtension, message string) {
apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{
Type: ocv1alpha1.TypeUnpacked,
Expand Down
Loading