Skip to content
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

✨ extension: spec.managed (enum) => spec.paused (bool), add status.paused #646

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions api/v1alpha1/extension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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]+)*$
Expand All @@ -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
Expand All @@ -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 {
Expand Down
24 changes: 13 additions & 11 deletions config/crd/bases/olm.operatorframework.io_extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/extension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 3 additions & 6 deletions internal/controllers/extension_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)()
Expand Down
Loading