diff --git a/api/v1alpha1/extension_types.go b/api/v1alpha1/extension_types.go index f10349088..4da6e00b9 100644 --- a/api/v1alpha1/extension_types.go +++ b/api/v1alpha1/extension_types.go @@ -20,15 +20,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -type ExtensionManagedState string - -const ( - // Peform reconcilliation of this Extension - ManagedStateActive ExtensionManagedState = "Active" - // Pause reconcilliation of this Extension - ManagedStatePaused ExtensionManagedState = "Paused" -) - const ( SourceTypePackage = "package" ) @@ -78,12 +69,10 @@ type ExtensionSource struct { // ExtensionSpec defines the desired state of Extension type ExtensionSpec struct { - //+kubebuilder:validation:Enum:=Active;Paused - //+kubebuilder:default:=Active //+kubebuilder:Optional // - // managed controls the management state of the extension. "Active" means this extension will be reconciled and "Paused" means this extension will be ignored. - Managed ExtensionManagedState `json:"managed,omitempty"` + // paused controls the management state of the extension. If the extension is paused, it will be ignored by the extension controller. + Paused bool `json:"paused,omitempty"` //+kubebuilder:validation:MaxLength:=253 //+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$ @@ -97,6 +86,9 @@ type ExtensionSpec struct { // ExtensionStatus defines the observed state of Extension type ExtensionStatus struct { + // paused indicates the current reconciliation state of this extension + Paused bool `json:"paused"` + // +optional InstalledBundleResource string `json:"installedBundleResource,omitempty"` // +optional @@ -111,7 +103,7 @@ type ExtensionStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -//+kubebuilder:printcolumn:name="Managed",type=string,JSONPath=`.spec.managed`,description="The current reconciliation state of this extension" +//+kubebuilder:printcolumn:name="Paused",type=string,JSONPath=`.status.paused`,description="The current reconciliation state of this extension" // Extension is the Schema for the extensions API type Extension struct { diff --git a/config/crd/bases/olm.operatorframework.io_extensions.yaml b/config/crd/bases/olm.operatorframework.io_extensions.yaml index 9d9e7a66c..b6394dc0b 100644 --- a/config/crd/bases/olm.operatorframework.io_extensions.yaml +++ b/config/crd/bases/olm.operatorframework.io_extensions.yaml @@ -16,8 +16,8 @@ spec: versions: - additionalPrinterColumns: - description: The current reconciliation state of this extension - jsonPath: .spec.managed - name: Managed + jsonPath: .status.paused + name: Paused type: string name: v1alpha1 schema: @@ -39,15 +39,11 @@ spec: spec: description: ExtensionSpec defines the desired state of Extension properties: - managed: - default: Active - description: managed controls the management state of the extension. - "Active" means this extension will be reconciled and "Paused" means - this extension will be ignored. - enum: - - Active - - Paused - type: string + paused: + description: paused controls the management state of the extension. + If the extension is paused, it will be ignored by the extension + controller. + type: boolean serviceAccountName: description: serviceAccountName is the name of a service account in the Extension's namespace that will be used to manage the installation @@ -186,8 +182,14 @@ spec: x-kubernetes-list-type: map installedBundleResource: type: string + paused: + description: paused indicates the current reconciliation state of + this extension + type: boolean resolvedBundleResource: type: string + required: + - paused type: object type: object served: true diff --git a/internal/controllers/extension_controller.go b/internal/controllers/extension_controller.go index 4a53a1198..2a3f58964 100644 --- a/internal/controllers/extension_controller.go +++ b/internal/controllers/extension_controller.go @@ -117,7 +117,8 @@ func (r *ExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alpha1.Ext } // Don't do anything if Paused - if ext.Spec.Managed == ocv1alpha1.ManagedStatePaused { + ext.Status.Paused = ext.Spec.Paused + if ext.Spec.Paused { l.Info("resource is paused", "name", ext.GetName(), "namespace", ext.GetNamespace()) return ctrl.Result{}, nil } diff --git a/internal/controllers/extension_controller_test.go b/internal/controllers/extension_controller_test.go index b567a046b..9998cd07f 100644 --- a/internal/controllers/extension_controller_test.go +++ b/internal/controllers/extension_controller_test.go @@ -54,12 +54,13 @@ func TestExtensionReconcile(t *testing.T) { {"feature gate enabled and paused", true, true, func(t *testing.T, res ctrl.Result, err error, ext *ocv1alpha1.Extension) { assert.Equal(t, ctrl.Result{}, res) assert.NoError(t, err) - assert.Equal(t, ocv1alpha1.ExtensionStatus{}, ext.Status) + assert.Equal(t, ocv1alpha1.ExtensionStatus{Paused: true}, ext.Status) }}, {"feature gate enabled and active", true, false, func(t *testing.T, res ctrl.Result, err error, ext *ocv1alpha1.Extension) { assert.Equal(t, ctrl.Result{}, res) assert.NoError(t, err) verifyExtensionInvariants(t, ext) + assert.False(t, ext.Status.Paused) assert.Empty(t, ext.Status.InstalledBundleResource) assert.Empty(t, ext.Status.ResolvedBundleResource) for _, cond := range ext.Status.Conditions { @@ -74,15 +75,11 @@ func TestExtensionReconcile(t *testing.T) { ext := &ocv1alpha1.Extension{ ObjectMeta: metav1.ObjectMeta{Name: extKey.Name, Namespace: extKey.Namespace}, Spec: ocv1alpha1.ExtensionSpec{ + Paused: tc.paused, ServiceAccountName: "test-service-account", Source: ocv1alpha1.ExtensionSource{SourceType: ocv1alpha1.SourceTypePackage, Package: &ocv1alpha1.ExtensionSourcePackage{Name: "test-package"}}, }, } - if tc.paused { - ext.Spec.Managed = ocv1alpha1.ManagedStatePaused - } else { - ext.Spec.Managed = ocv1alpha1.ManagedStateActive - } require.NoError(t, c.Create(ctx, ext)) defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.EnableExtensionAPI, tc.featureGateEnabled)()