Skip to content
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
16 changes: 16 additions & 0 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ func assertImpersonationConfiguration[T Component](component T) (ImpersonationCo
return nil, false
}

// Check if given component or its spec implements SuspensionConfiguration (and return it).
func assertSuspensionConfiguration[T Component](component T) (SuspensionConfiguration, bool) {
if suspensionConfiguration, ok := Component(component).(SuspensionConfiguration); ok {
return suspensionConfiguration, true
}
if suspensionConfiguration, ok := getSpec(component).(SuspensionConfiguration); ok {
return suspensionConfiguration, true
}
return nil, false
}

// Check if given component or its spec implements RequeueConfiguration (and return it).
func assertRequeueConfiguration[T Component](component T) (RequeueConfiguration, bool) {
if requeueConfiguration, ok := Component(component).(RequeueConfiguration); ok {
Expand Down Expand Up @@ -176,6 +187,11 @@ func (s *ImpersonationSpec) GetImpersonationGroups() []string {
return nil
}

// Implement the SuspensionConfiguration interface.
func (s *SuspensionSpec) IsSuspended() bool {
return s.Suspend
}

// Implement the RequeueConfiguration interface.
func (s *RequeueSpec) GetRequeueInterval() time.Duration {
if s.RequeueInterval != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/component/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
ReadyConditionReasonReady = "Ready"
ReadyConditionReasonError = "Error"
ReadyConditionReasonTimeout = "Timeout"
ReadyConditionReasonSuspended = "Suspended"
ReadyConditionReasonDeletionRetrying = "DeletionRetrying"
ReadyConditionReasonDeletionBlocked = "DeletionBlocked"
ReadyConditionReasonDeletionProcessing = "DeletionProcessing"
Expand Down Expand Up @@ -456,6 +457,13 @@ func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (result
return ctrl.Result{RequeueAfter: time.Millisecond}, nil
}

if component.GetDeletionTimestamp().IsZero() {
if suspensionConfiguration, ok := assertSuspensionConfiguration(component); ok && suspensionConfiguration.IsSuspended() {
status.SetState(StatePending, ReadyConditionReasonSuspended, "Reconciliation is suspended")
return ctrl.Result{RequeueAfter: r.backoff.Next(req, ReadyConditionReasonSuspended)}, nil
}
}

// resolve references
componentDigest, err = resolveReferences(ctx, r.client, r.hookClient, component)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions pkg/component/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ type ImpersonationConfiguration interface {
GetImpersonationGroups() []string
}

// The SuspensionConfiguration interface is meant to be implemented by components (or their spec) which offer
// the ability to suspend reconciliation.
type SuspensionConfiguration interface {
// Whether the reconciliation (apply) or the implementing component is supended. If true the component goes
// into Pending state with reason Suspended. Note that deletion is not affected by this suspension.
IsSuspended() bool
}

// The RequeueConfiguration interface is meant to be implemented by components (or their spec) which offer
// tweaking the requeue interval (by default, it would be 10 minutes).
type RequeueConfiguration interface {
Expand Down Expand Up @@ -170,6 +178,16 @@ var _ ImpersonationConfiguration = &ImpersonationSpec{}

// +kubebuilder:object:generate=true

// SuspensionSpec defines whether the reconciliation (apply) or the implementing component is suspended.
// Components providing SuspensionConfiguration may include this into their spec.
type SuspensionSpec struct {
Suspend bool `json:"suspend,omitempty"`
}

var _ SuspensionConfiguration = &SuspensionSpec{}

// +kubebuilder:object:generate=true

// RequeueSpec defines the requeue interval, that is, the interval after which components will be re-reconciled after a successful reconciliation.
// Components providing RequeueConfiguration may include this into their spec.
type RequeueSpec struct {
Expand Down
15 changes: 15 additions & 0 deletions pkg/component/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions website/content/en/docs/concepts/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,21 @@ type ImpersonationConfiguration interface {

to use different user/groups for the deployment of dependent objects.

Note that, as mentioned above, the interfaces `PlacementConfiguration`, `ClientConfiguration` and `ImpersonationConfiguration` can be implemented by the component
itself as well as by its spec type. In the theoretical case that both is the case, the implementation on the component level takes higher precedence.
Sometimes it is desired to suspend the reconciliation of a component. In offer this, the compoent (or its spec) can implement the interface

```go
package component

// The SuspensionConfiguration interface is meant to be implemented by components (or their spec) which offer
// the ability to suspend reconciliation.
type SuspensionConfiguration interface {
// Whether the reconciliation (apply) or the implementing component is supended. If true the component goes
// into Pending state with reason Suspended. Note that deletion is not affected by this suspension.
IsSuspended() bool
}
```

Note that, as mentioned above, the interfaces `PlacementConfiguration`, `ClientConfiguration`, `ImpersonationConfiguration` and `SuspensionConfiguration` can be implemented by the component itself as well as by its spec type. In the theoretical case that both implement it, the component takes higher precedence.

## The Generator interface

Expand Down
Loading