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

Move headless service creation outside of createJobs #483

Merged
merged 3 commits into from
Mar 28, 2024
Merged
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
20 changes: 13 additions & 7 deletions pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ func (r *JobSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}
}

// If pod DNS hostnames are enabled, create a headless service for the JobSet
if err := r.createHeadlessSvcIfNecessary(ctx, &js); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could have a log here also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added logging of the error here

log.Error(err, "creating headless service")
return ctrl.Result{}, err
}

// If job has not failed or succeeded, continue creating any
// jobs that are ready to be started.
if err := r.createJobs(ctx, &js, ownedJobs, status); err != nil {
Expand Down Expand Up @@ -411,12 +417,6 @@ func (r *JobSetReconciler) resumeJob(ctx context.Context, job *batchv1.Job, node
func (r *JobSetReconciler) createJobs(ctx context.Context, js *jobset.JobSet, ownedJobs *childJobs, replicatedJobStatus []jobset.ReplicatedJobStatus) error {
log := ctrl.LoggerFrom(ctx)

// If pod DNS hostnames are enabled, create a headless service for the JobSet
if dnsHostnamesEnabled(js) {
if err := r.createHeadlessSvcIfNotExist(ctx, js); err != nil {
return err
}
}
startupPolicy := js.Spec.StartupPolicy
var lock sync.Mutex
var finalErrs []error
Expand Down Expand Up @@ -486,9 +486,15 @@ func (r *JobSetReconciler) createJobs(ctx context.Context, js *jobset.JobSet, ow

// TODO: look into adopting service and updating the selector
// if it is not matching the job selector.
func (r *JobSetReconciler) createHeadlessSvcIfNotExist(ctx context.Context, js *jobset.JobSet) error {
func (r *JobSetReconciler) createHeadlessSvcIfNecessary(ctx context.Context, js *jobset.JobSet) error {
log := ctrl.LoggerFrom(ctx)

// Headless service is only necessary for indexed jobs whose pods need to communicate with
// eachother via pod hostnames.
if !dnsHostnamesEnabled(js) {
return nil
}

// Check if service already exists. The service name should match the subdomain specified in
// Spec.Network.Subdomain, with default of <jobSetName> set by the webhook.
// If the service doesn't exist in the same namespace, create it.
Expand Down