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
5 changes: 5 additions & 0 deletions api/v1beta2/appwrapper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type AppWrapperSpec struct {
// Suspend suspends the AppWrapper when set to true
//+optional
Suspend bool `json:"suspend,omitempty"`

// ManagedBy is used to indicate the controller or entity that manages the AppWrapper.
ManagedBy *string `json:"managedBy,omitempty"`
}

// AppWrapperComponent describes a single wrapped Kubernetes resource
Expand Down Expand Up @@ -176,6 +179,8 @@ const (
RetryableExitCodesAnnotation = "workload.codeflare.dev.appwrapper/retryableExitCodes"
)

const AppWrapperControllerName = "workload.codeflare.dev/appwrapper-controller"

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=`.status.phase`
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions config/crd/bases/workload.codeflare.dev_appwrappers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ spec:
- template
type: object
type: array
managedBy:
description: ManagedBy is used to indicate the controller or entity
that manages the AppWrapper.
type: string
suspend:
description: Suspend suspends the AppWrapper when set to true
type: boolean
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/appwrapper/appwrapper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, nil
}

// stop reconciliation if managed by another controller
if aw.Spec.ManagedBy != nil && *aw.Spec.ManagedBy != workloadv1beta2.AppWrapperControllerName {
return ctrl.Result{}, nil
}

// handle deletion first
if !aw.DeletionTimestamp.IsZero() {
if controllerutil.ContainsFinalizer(aw, AppWrapperFinalizer) {
Expand Down
10 changes: 10 additions & 0 deletions internal/webhook/appwrapper_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func (w *AppWrapperWebhook) Default(ctx context.Context, obj runtime.Object) err
username := utils.SanitizeLabel(userInfo.Username)
aw.Labels = utilmaps.MergeKeepFirst(map[string]string{AppWrapperUsernameLabel: username, AppWrapperUserIDLabel: userInfo.UID}, aw.Labels)

// do not inject finalizer if managed by another controller
if aw.Spec.ManagedBy != nil && *aw.Spec.ManagedBy != workloadv1beta2.AppWrapperControllerName {
return nil
}

// inject finalizer now (avoid reconcilier errors between the AppWrapper and WorkloadControllers when it is admitted by a ClusterQueue almost immediately)
controllerutil.AddFinalizer(aw, awc.AppWrapperFinalizer)

Expand Down Expand Up @@ -275,6 +280,11 @@ func (w *AppWrapperWebhook) validateAppWrapperUpdate(old *workloadv1beta2.AppWra
allErrors = append(allErrors, field.Forbidden(field.NewPath("metadata").Child("labels").Key(AppWrapperUserIDLabel), msg))
}

// ensure managedBy field is immutable
if old.Spec.ManagedBy != new.Spec.ManagedBy {
allErrors = append(allErrors, field.Forbidden(field.NewPath("spec").Child("managedBy"), msg))
}

return allErrors
}

Expand Down