Skip to content

Commit

Permalink
Change implementation of JobSet controller manager to better align wi…
Browse files Browse the repository at this point in the history
…th how Job is implemented.
  • Loading branch information
Justin Edwins committed Mar 29, 2024
1 parent a82e440 commit 66b55c4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
6 changes: 3 additions & 3 deletions api/jobset/v1alpha2/jobset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const (
NamespacedJobKey string = "alpha.jobset.sigs.k8s.io/namespaced-job"
NoScheduleTaintKey string = "alpha.jobset.sigs.k8s.io/no-schedule"

// JobSetManager is used as the value for ManagedBy to identify the jobset controller manager
// as the manager of a specific JobSet.
JobSetManager = "jobset"
// JobSetControllerName is the reserved value for the managedBy field for the built-in
// JobSet controller.
JobSetControllerName = "jobset.sigs.k8s.io/jobset-controller"
)

type JobSetConditionType string
Expand Down
2 changes: 1 addition & 1 deletion api/jobset/v1alpha2/jobset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (js *JobSet) Default() {
}

if js.Spec.ManagedBy == nil {
js.Spec.ManagedBy = ptr.To(JobSetManager)
js.Spec.ManagedBy = ptr.To(JobSetControllerName)
}
}

Expand Down
36 changes: 18 additions & 18 deletions api/jobset/v1alpha2/jobset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -70,7 +70,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand All @@ -90,7 +90,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -108,7 +108,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand All @@ -128,7 +128,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -146,7 +146,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand All @@ -167,7 +167,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -185,7 +185,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand All @@ -208,7 +208,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -230,7 +230,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand All @@ -255,7 +255,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -277,7 +277,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand All @@ -301,7 +301,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -323,7 +323,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand All @@ -350,7 +350,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
want: &JobSet{
Expand All @@ -374,7 +374,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand Down Expand Up @@ -428,7 +428,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestJobSetDefaulting(t *testing.T) {
},
},
},
ManagedBy: ptr.To(JobSetManager),
ManagedBy: ptr.To(JobSetControllerName),
},
},
},
Expand Down
9 changes: 8 additions & 1 deletion pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *JobSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
log := ctrl.LoggerFrom(ctx).WithValues("jobset", klog.KObj(&js))
ctx = ctrl.LoggerInto(ctx, log)

if manager := ptr.Deref(js.Spec.ManagedBy, ""); js.Spec.ManagedBy != nil && manager != jobset.JobSetManager {
if manager := managedByExternalController(js); manager != nil {
log.V(5).Info("Skipping JobSet managed by a different controller", "managed-by", manager)
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -936,3 +936,10 @@ func findJobFailureTime(job *batchv1.Job) *metav1.Time {
}
return nil
}

func managedByExternalController(js jobset.JobSet) *string {
if controllerName := js.Spec.ManagedBy; controllerName != nil && *controllerName != jobset.JobSetControllerName {
return controllerName
}
return nil
}
2 changes: 1 addition & 1 deletion test/integration/webhook/jobset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ var _ = ginkgo.Describe("jobset webhook defaulting", func() {
Obj())
},
defaultsApplied: func(js *jobset.JobSet) bool {
return ptr.Deref(js.Spec.ManagedBy, "") == jobset.JobSetManager
return ptr.Deref(js.Spec.ManagedBy, "") == jobset.JobSetControllerName
},
updateJobSet: func(js *jobset.JobSet) {
js.Spec.ManagedBy = ptr.To("new-manager")
Expand Down

0 comments on commit 66b55c4

Please sign in to comment.