Skip to content

Commit

Permalink
Merge pull request #487 from jedwins1998/dev
Browse files Browse the repository at this point in the history
Introduce `managedBy` field and Remove `managed-by` label
  • Loading branch information
k8s-ci-robot committed Mar 29, 2024
2 parents dc00552 + 80ac00c commit 9348439
Show file tree
Hide file tree
Showing 17 changed files with 243 additions and 79 deletions.
12 changes: 6 additions & 6 deletions api/jobset/v1alpha2/jobset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ const (
NamespacedJobKey string = "alpha.jobset.sigs.k8s.io/namespaced-job"
NoScheduleTaintKey string = "alpha.jobset.sigs.k8s.io/no-schedule"

// LabelManagedBy is used to indicate the controller or entity that manages an JobSet
LabelManagedBy = "alpha.jobset.sigs.k8s.io/managed-by"

// JobSetManager is used as the value for LabelManagedBy 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 Expand Up @@ -94,6 +91,9 @@ type JobSetSpec struct {

// Suspend suspends all running child Jobs when set to true.
Suspend *bool `json:"suspend,omitempty"`

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

// JobSetStatus defines the observed state of JobSet
Expand Down
23 changes: 17 additions & 6 deletions api/jobset/v1alpha2/jobset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import (
corev1 "k8s.io/api/core/v1"
)

// maximum lnegth of the value of the managedBy field
const maxManagedByLength = 63

const (
// This is the error message returned by IsDNS1035Label when the given input
// is longer than 63 characters.
Expand Down Expand Up @@ -93,11 +96,8 @@ func (js *JobSet) Default() {
}
}

if _, found := js.Labels[LabelManagedBy]; !found {
if js.Labels == nil {
js.Labels = make(map[string]string, 1)
}
js.Labels[LabelManagedBy] = JobSetManager
if js.Spec.ManagedBy == nil {
js.Spec.ManagedBy = ptr.To(JobSetControllerName)
}
}

Expand Down Expand Up @@ -128,6 +128,17 @@ func (js *JobSet) ValidateCreate() (admission.Warnings, error) {
}
}

if js.Spec.ManagedBy != nil {
manager := *js.Spec.ManagedBy
fieldPath := field.NewPath("spec", "managedBy")
for _, err := range validation.IsDomainPrefixedPath(fieldPath, manager) {
allErrs = append(allErrs, err)
}
if len(manager) > maxManagedByLength {
allErrs = append(allErrs, field.TooLongMaxLength(fieldPath, manager, maxManagedByLength))
}
}

for _, rjob := range js.Spec.ReplicatedJobs {
var parallelism int32 = 1
if rjob.Template.Spec.Parallelism != nil {
Expand Down Expand Up @@ -179,7 +190,7 @@ func (js *JobSet) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
}
// Note that SucccessPolicy and failurePolicy are made immutable via CEL.
errs := apivalidation.ValidateImmutableField(mungedSpec.ReplicatedJobs, oldJS.Spec.ReplicatedJobs, field.NewPath("spec").Child("replicatedJobs"))
errs = append(errs, apivalidation.ValidateImmutableField(js.Labels[LabelManagedBy], oldJS.Labels[LabelManagedBy], field.NewPath("metadata").Child("labels").Key(LabelManagedBy))...)
errs = append(errs, apivalidation.ValidateImmutableField(mungedSpec.ManagedBy, oldJS.Spec.ManagedBy, field.NewPath("spec").Child("labels").Key("managedBy"))...)
return nil, errs.ToAggregate()
}

Expand Down
Loading

0 comments on commit 9348439

Please sign in to comment.