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

Get subdomain via a func instead of defaulting it on the jobset object #404

Merged
merged 1 commit into from
Feb 10, 2024
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
22 changes: 9 additions & 13 deletions pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ func (r *JobSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
ctx = ctrl.LoggerInto(ctx, log)
log.V(2).Info("Reconciling JobSet")

// If enableDNSHostnames is set, and subdomain is unset, default the subdomain to be the JobSet name.
// This must be done in the controller rather than in the request-time defaulting, since if a JobSet
// uses generateName rather than setting the name explicitly, the JobSet name will still be an empty
// string at that time.
if dnsHostnamesEnabled(&js) && js.Spec.Network.Subdomain == "" {
js.Spec.Network.Subdomain = js.Name
}

// Get Jobs owned by JobSet.
ownedJobs, err := r.getChildJobs(ctx, &js)
if err != nil {
Expand Down Expand Up @@ -423,10 +415,11 @@ func (r *JobSetReconciler) createHeadlessSvcIfNotExist(ctx context.Context, js *
// Spec.Network.Subdomain, with default of <jobSetName> set by the webhook.
// If the service doesn't exist in the same namespace, create it.
var headlessSvc corev1.Service
if err := r.Get(ctx, types.NamespacedName{Name: js.Spec.Network.Subdomain, Namespace: js.Namespace}, &headlessSvc); err != nil {
subdomain := GetSubdomain(js)
if err := r.Get(ctx, types.NamespacedName{Name: subdomain, Namespace: js.Namespace}, &headlessSvc); err != nil {
headlessSvc := corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: js.Spec.Network.Subdomain,
Name: subdomain,
Namespace: js.Namespace,
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -616,7 +609,7 @@ func constructJob(js *jobset.JobSet, rjob *jobset.ReplicatedJob, jobIdx int) (*b
// If enableDNSHostnames is set, update job spec to set subdomain as
// job name (a headless service with same name as job will be created later).
if dnsHostnamesEnabled(js) {
job.Spec.Template.Spec.Subdomain = js.Spec.Network.Subdomain
job.Spec.Template.Spec.Subdomain = GetSubdomain(js)
}

// If this job is using the nodeSelectorStrategy implementation of exclusive placement,
Expand Down Expand Up @@ -707,8 +700,11 @@ func JobFinished(job *batchv1.Job) (bool, batchv1.JobConditionType) {
return false, ""
}

func GenSubdomain(js *jobset.JobSet) string {
// If we have selected an explicit network name, use it
func GetSubdomain(js *jobset.JobSet) string {
// If enableDNSHostnames is set, and subdomain is unset, default the subdomain to be the JobSet name.
// This must be done in the controller rather than in the request-time defaulting, since if a JobSet
// uses generateName rather than setting the name explicitly, the JobSet name will still be an empty
// string at that time.
if js.Spec.Network.Subdomain != "" {
return js.Spec.Network.Subdomain
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/controller/jobset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ var _ = ginkgo.Describe("JobSet controller", func() {
// Fetch headless service created for replicated job and delete it.
jobSetUpdateFn: func(js *jobset.JobSet) {
var svc corev1.Service
gomega.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: controllers.GenSubdomain(js), Namespace: js.Namespace}, &svc)).To(gomega.Succeed())
gomega.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: controllers.GetSubdomain(js), Namespace: js.Namespace}, &svc)).To(gomega.Succeed())
gomega.Expect(k8sClient.Delete(ctx, &svc)).To(gomega.Succeed())
},
// Service should be recreated during reconciliation.
Expand Down