Skip to content

Commit f064bc1

Browse files
committed
Fixes and additions pending & unpack path
Signed-off-by: Brett Tofel <[email protected]>
1 parent 1003542 commit f064bc1

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

api/v1alpha1/clusterextension_types.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const (
9292
TypePackageDeprecated = "PackageDeprecated"
9393
TypeChannelDeprecated = "ChannelDeprecated"
9494
TypeBundleDeprecated = "BundleDeprecated"
95+
TypeUnpacked = "Unpacked"
9596

9697
ReasonErrorGettingClient = "ErrorGettingClient"
9798
ReasonBundleLoadFailed = "BundleLoadFailed"
@@ -101,9 +102,11 @@ const (
101102
ReasonInstallationSucceeded = "InstallationSucceeded"
102103
ReasonResolutionFailed = "ResolutionFailed"
103104

104-
ReasonSuccess = "Success"
105-
ReasonDeprecated = "Deprecated"
106-
ReasonUpgradeFailed = "UpgradeFailed"
105+
ReasonSuccess = "Success"
106+
ReasonDeprecated = "Deprecated"
107+
ReasonUpgradeFailed = "UpgradeFailed"
108+
ReasonHasValidBundleUnknown = "HasValidBundleUnknown"
109+
ReasonUnpackPending = "UnpackPending"
107110
)
108111

109112
func init() {
@@ -116,6 +119,7 @@ func init() {
116119
TypePackageDeprecated,
117120
TypeChannelDeprecated,
118121
TypeBundleDeprecated,
122+
TypeUnpacked,
119123
)
120124
// TODO(user): add Reasons from above
121125
conditionsets.ConditionReasons = append(conditionsets.ConditionReasons,
@@ -130,6 +134,8 @@ func init() {
130134
// TODO: this reason is not being used in the reconciler, it will be removed
131135
// when we fix the tests. Avoiding removal here, to reduce diffs.
132136
ReasonInstallationStatusUnknown,
137+
ReasonHasValidBundleUnknown,
138+
ReasonUnpackPending,
133139
)
134140
}
135141

internal/controllers/clusterextension_controller.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
238238
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
239239
return ctrl.Result{}, err
240240
}
241+
// set deprecation status after _successful_ resolution
242+
SetDeprecationStatus(ext, bundle)
241243

242244
bundleVersion, err := bundle.Version()
243245
if err != nil {
@@ -262,12 +264,17 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
262264

263265
switch unpackResult.State {
264266
case rukpaksource.StatePending:
265-
updateStatusUnpackPending(&ext.Status, unpackResult)
267+
updateStatusUnpackPending(&ext.Status, unpackResult, ext.GetGeneration())
266268
// There must be a limit to number of entries if status is stuck at
267269
// unpack pending.
270+
setHasValidBundleUnknown(&ext.Status.Conditions, "unpack pending", ext.GetGeneration())
271+
setInstalledStatusConditionUnknown(&ext.Status.Conditions, "installation has not been attempted as unpack is pending", ext.GetGeneration())
272+
268273
return ctrl.Result{}, nil
269274
case rukpaksource.StateUnpacking:
270275
updateStatusUnpacking(&ext.Status, unpackResult)
276+
setHasValidBundleUnknown(&ext.Status.Conditions, "unpack pending", ext.GetGeneration())
277+
setInstalledStatusConditionUnknown(&ext.Status.Conditions, "installation has not been attempted as unpack is pending", ext.GetGeneration())
271278
return ctrl.Result{}, nil
272279
case rukpaksource.StateUnpacked:
273280
// TODO: Add finalizer to clean the stored bundles, after https://github.com/operator-framework/rukpak/pull/897

internal/controllers/clusterextension_controller_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ func TestClusterExtensionChannelExistsNoVersion(t *testing.T) {
243243
require.Equal(t, metav1.ConditionFalse, unpackedCond.Status)
244244
require.Equal(t, rukpakv1alpha2.ReasonUnpackPending, unpackedCond.Reason)
245245

246+
verifyInvariants(ctx, t, reconciler.Client, clusterExtension)
246247
require.NoError(t, cl.DeleteAllOf(ctx, &ocv1alpha1.ClusterExtension{}))
247248
}
248249

internal/controllers/common_controller.go

+28-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ func setResolvedStatusConditionSuccess(conditions *[]metav1.Condition, message s
4646
})
4747
}
4848

49+
// setInstalledStatusConditionUnknown sets the installed status condition to unknown.
50+
func setInstalledStatusConditionUnknown(conditions *[]metav1.Condition, message string, generation int64) {
51+
apimeta.SetStatusCondition(conditions, metav1.Condition{
52+
Type: ocv1alpha1.TypeInstalled,
53+
Status: metav1.ConditionUnknown,
54+
Reason: ocv1alpha1.ReasonInstallationStatusUnknown,
55+
Message: message,
56+
ObservedGeneration: generation,
57+
})
58+
}
59+
60+
// setHasValidBundleUnknown sets the installed status condition to unknown.
61+
func setHasValidBundleUnknown(conditions *[]metav1.Condition, message string, generation int64) {
62+
apimeta.SetStatusCondition(conditions, metav1.Condition{
63+
Type: ocv1alpha1.TypeHasValidBundle,
64+
Status: metav1.ConditionUnknown,
65+
Reason: ocv1alpha1.ReasonHasValidBundleUnknown,
66+
Message: message,
67+
ObservedGeneration: generation,
68+
})
69+
}
70+
4971
// setResolvedStatusConditionFailed sets the resolved status condition to failed.
5072
func setResolvedStatusConditionFailed(conditions *[]metav1.Condition, message string, generation int64) {
5173
apimeta.SetStatusCondition(conditions, metav1.Condition{
@@ -111,13 +133,14 @@ func updateStatusUnpackFailing(status *ocv1alpha1.ClusterExtensionStatus, err er
111133
}
112134

113135
// TODO: verify if we need to update the installBundle status or leave it as is.
114-
func updateStatusUnpackPending(status *ocv1alpha1.ClusterExtensionStatus, result *source.Result) {
136+
func updateStatusUnpackPending(status *ocv1alpha1.ClusterExtensionStatus, result *source.Result, generation int64) {
115137
status.InstalledBundle = nil
116138
meta.SetStatusCondition(&status.Conditions, metav1.Condition{
117-
Type: rukpakv1alpha2.TypeUnpacked,
118-
Status: metav1.ConditionFalse,
119-
Reason: rukpakv1alpha2.ReasonUnpackPending,
120-
Message: result.Message,
139+
Type: rukpakv1alpha2.TypeUnpacked,
140+
Status: metav1.ConditionFalse,
141+
Reason: rukpakv1alpha2.ReasonUnpackPending,
142+
Message: result.Message,
143+
ObservedGeneration: generation,
121144
})
122145
}
123146

0 commit comments

Comments
 (0)