Skip to content

Commit 566a2e7

Browse files
authored
Implement spec.managedBy field (#249)
1 parent 56f8f99 commit 566a2e7

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

api/v1beta2/appwrapper_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type AppWrapperSpec struct {
3030
// Suspend suspends the AppWrapper when set to true
3131
//+optional
3232
Suspend bool `json:"suspend,omitempty"`
33+
34+
// ManagedBy is used to indicate the controller or entity that manages the AppWrapper.
35+
ManagedBy *string `json:"managedBy,omitempty"`
3336
}
3437

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

182+
const AppWrapperControllerName = "workload.codeflare.dev/appwrapper-controller"
183+
179184
//+kubebuilder:object:root=true
180185
//+kubebuilder:subresource:status
181186
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=`.status.phase`

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/workload.codeflare.dev_appwrappers.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ spec:
160160
- template
161161
type: object
162162
type: array
163+
managedBy:
164+
description: ManagedBy is used to indicate the controller or entity
165+
that manages the AppWrapper.
166+
type: string
163167
suspend:
164168
description: Suspend suspends the AppWrapper when set to true
165169
type: boolean

internal/controller/appwrapper/appwrapper_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
106106
return ctrl.Result{}, nil
107107
}
108108

109+
// stop reconciliation if managed by another controller
110+
if aw.Spec.ManagedBy != nil && *aw.Spec.ManagedBy != workloadv1beta2.AppWrapperControllerName {
111+
return ctrl.Result{}, nil
112+
}
113+
109114
// handle deletion first
110115
if !aw.DeletionTimestamp.IsZero() {
111116
if controllerutil.ContainsFinalizer(aw, AppWrapperFinalizer) {

internal/webhook/appwrapper_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func (w *AppWrapperWebhook) Default(ctx context.Context, obj runtime.Object) err
8989
username := utils.SanitizeLabel(userInfo.Username)
9090
aw.Labels = utilmaps.MergeKeepFirst(map[string]string{AppWrapperUsernameLabel: username, AppWrapperUserIDLabel: userInfo.UID}, aw.Labels)
9191

92+
// do not inject finalizer if managed by another controller
93+
if aw.Spec.ManagedBy != nil && *aw.Spec.ManagedBy != workloadv1beta2.AppWrapperControllerName {
94+
return nil
95+
}
96+
9297
// inject finalizer now (avoid reconcilier errors between the AppWrapper and WorkloadControllers when it is admitted by a ClusterQueue almost immediately)
9398
controllerutil.AddFinalizer(aw, awc.AppWrapperFinalizer)
9499

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

283+
// ensure managedBy field is immutable
284+
if old.Spec.ManagedBy != new.Spec.ManagedBy {
285+
allErrors = append(allErrors, field.Forbidden(field.NewPath("spec").Child("managedBy"), msg))
286+
}
287+
278288
return allErrors
279289
}
280290

0 commit comments

Comments
 (0)