Skip to content

Commit

Permalink
add publish not ready headless service to jobset
Browse files Browse the repository at this point in the history
  • Loading branch information
kannon92 committed Apr 13, 2024
1 parent a315ef0 commit 18e28a2
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 33 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,5 @@ golangci-lint: ## Download golangci-lint locally if necessary.
GOTESTSUM = $(shell pwd)/bin/gotestsum
.PHONY: gotestsum
gotestsum: ## Download gotestsum locally if necessary.
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install gotest.tools/gotestsum@v1.8.2
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install gotest.tools/gotestsum@v1.8.2

6 changes: 6 additions & 0 deletions api/jobset/v1alpha2/jobset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ type Network struct {
// Defaults to <jobSet.name> if not set.
// +optional
Subdomain string `json:"subdomain,omitempty"`

// PublishNotReadyAddresses indicates that any agent
// which deals with endpoints for this Service should disregard any indications of ready/not-ready.
// Defaults to true if not set
// +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.

6 changes: 6 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,12 @@ 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: |-
PublishNotReadyAddresses indicates that any agent
which deals with endpoints for this Service should disregard any indications of ready/not-ready.
Defaults to true if not set
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": "PublishNotReadyAddresses indicates that any agent which deals with endpoints for this Service should disregard any indications of ready/not-ready. Defaults to true if not set",
"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

0 comments on commit 18e28a2

Please sign in to comment.