Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add publish not ready headless service to jobset #505

Merged
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/jobset/v1alpha2/jobset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ type Network struct {
// Defaults to <jobSet.name> if not set.
// +optional
Subdomain string `json:"subdomain,omitempty"`

// Indicates if DNS records of pods should be published before the pods are ready.
// Defaults to True.
// +optional
PublishNotReadyAddresses *bool `json:"publishNotReadyAddresses,omitempty"`
}

// Operator defines the target of a SuccessPolicy or FailurePolicy.
Expand Down
7 changes: 7 additions & 0 deletions api/jobset/v1alpha2/openapi_generated.go

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

5 changes: 5 additions & 0 deletions api/jobset/v1alpha2/zz_generated.deepcopy.go

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

13 changes: 11 additions & 2 deletions client-go/applyconfiguration/jobset/v1alpha2/network.go

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

5 changes: 5 additions & 0 deletions config/components/crd/bases/jobset.x-k8s.io_jobsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ spec:
Pods will be reachable using the fully qualified pod hostname:
<jobSet.name>-<spec.replicatedJob.name>-<job-index>-<pod-index>.<subdomain>
type: boolean
publishNotReadyAddresses:
description: |-
Indicates if DNS records of pods should be published before the pods are ready.
Defaults to True.
type: boolean
subdomain:
description: |-
Subdomain is an explicit choice for a network subdomain name
Expand Down
4 changes: 4 additions & 0 deletions hack/python-sdk/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
"description": "EnableDNSHostnames allows pods to be reached via their hostnames. Pods will be reachable using the fully qualified pod hostname: \u003cjobSet.name\u003e-\u003cspec.replicatedJob.name\u003e-\u003cjob-index\u003e-\u003cpod-index\u003e.\u003csubdomain\u003e",
"type": "boolean"
},
"publishNotReadyAddresses": {
"description": "Indicates if DNS records of pods should be published before the pods are ready. Defaults to True.",
"type": "boolean"
},
"subdomain": {
"description": "Subdomain is an explicit choice for a network subdomain name When set, any replicated job in the set is added to this network. Defaults to \u003cjobSet.name\u003e if not set.",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ func (r *JobSetReconciler) createHeadlessSvcIfNecessary(ctx context.Context, js
Selector: map[string]string{
jobset.JobSetNameKey: js.Name,
},
PublishNotReadyAddresses: ptr.Deref(js.Spec.Network.PublishNotReadyAddresses, true),
},
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/util/testing/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,18 @@ func (j *JobSetWrapper) NetworkSubdomain(val string) *JobSetWrapper {
return j
}

// EnableDNSHostnames sets the value of ReplicatedJob.Network.EnableDNSHostnames.
// EnableDNSHostnames sets the value of JobSet.Network.EnableDNSHostnames.
func (j *JobSetWrapper) EnableDNSHostnames(val bool) *JobSetWrapper {
j.JobSet.Spec.Network.EnableDNSHostnames = ptr.To(val)
return j
}

// PublishNotReadyAddresses sets the value of JobSet.Network.PublishNotReadyAddresses.
func (j *JobSetWrapper) PublishNotReadyAddresses(val bool) *JobSetWrapper {
j.JobSet.Spec.Network.PublishNotReadyAddresses = ptr.To(val)
return j
}

// TTLSecondsAfterFinished sets the value of JobSet.Spec.TTLSecondsAfterFinished
func (j *JobSetWrapper) TTLSecondsAfterFinished(seconds int32) *JobSetWrapper {
j.Spec.TTLSecondsAfterFinished = &seconds
Expand Down
19 changes: 11 additions & 8 deletions pkg/webhooks/jobset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,23 @@ func (j *jobSetWebhook) Default(ctx context.Context, obj runtime.Object) error {
if js.Spec.ReplicatedJobs[i].Template.Spec.CompletionMode == nil {
js.Spec.ReplicatedJobs[i].Template.Spec.CompletionMode = completionModePtr(batchv1.IndexedCompletion)
}
// Enable DNS hostnames by default.
if js.Spec.Network == nil {
js.Spec.Network = &jobset.Network{}
}
if js.Spec.Network.EnableDNSHostnames == nil {
js.Spec.Network.EnableDNSHostnames = ptr.To(true)
}

// Default pod restart policy to OnFailure.
if js.Spec.ReplicatedJobs[i].Template.Spec.Template.Spec.RestartPolicy == "" {
js.Spec.ReplicatedJobs[i].Template.Spec.Template.Spec.RestartPolicy = corev1.RestartPolicyOnFailure
}
}

// Enable DNS hostnames by default.
if js.Spec.Network == nil {
js.Spec.Network = &jobset.Network{}
}
if js.Spec.Network.EnableDNSHostnames == nil {
js.Spec.Network.EnableDNSHostnames = ptr.To(true)
}
if js.Spec.Network.PublishNotReadyAddresses == nil {
js.Spec.Network.PublishNotReadyAddresses = ptr.To(true)
}

if js.Spec.ManagedBy == nil {
js.Spec.ManagedBy = ptr.To(jobset.JobSetControllerName)
}
Expand Down
Loading