Skip to content

Commit

Permalink
job: call deploy agent after merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Mar 20, 2024
1 parent 96d0288 commit 1cd0e4e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ func (*jobService) CreateJob(ctx context.Context, job *jobTypes.Job, user *authT
}

// updateDeployOptions updates the job's deployOptions if the job's image has changed
func updateDeployOptions(ctx context.Context, oldJob, newJob *jobTypes.Job) error {
func updateDeployOptions(oldJob, newJob *jobTypes.Job) (hasChanged bool, err error) {
// we have to ensure oldJob has deployOptions, for compatibility with legacy way of creating jobs
if err := ensureDeployOptions(oldJob); err != nil {
return err
return false, err
}
// if newJob doesn't have any info about deployOptions, it means client did not pass job.Spec.Container.Image nor job.DeployOptions
// so it doesnt want to change the deployOptions
Expand All @@ -270,16 +270,10 @@ func updateDeployOptions(ctx context.Context, oldJob, newJob *jobTypes.Job) erro
if err == jobTypes.ErrInvalidDeployKind {
newJob.DeployOptions = oldJob.DeployOptions
} else {
return err
return false, err
}
}
if !reflect.DeepEqual(newJob.DeployOptions, oldJob.DeployOptions) {
err := buildWithDeployAgent(ctx, newJob)
if err != nil {
return err
}
}
return nil
return !reflect.DeepEqual(newJob.DeployOptions, oldJob.DeployOptions), nil
}

// UpdateJob updates an existing cronjob.
Expand All @@ -304,7 +298,8 @@ func (*jobService) UpdateJob(ctx context.Context, newJob, oldJob *jobTypes.Job,
}
newJobActiveDeadlineSeconds := buildActiveDeadline(newJob.Spec.ActiveDeadlineSeconds)

if err := updateDeployOptions(ctx, oldJob, newJob); err != nil {
deployOptionsHasChanged, err := updateDeployOptions(oldJob, newJob)
if err != nil {
return err
}

Expand All @@ -315,6 +310,14 @@ func (*jobService) UpdateJob(ctx context.Context, newJob, oldJob *jobTypes.Job,
if err := mergo.Merge(newJob, oldJob); err != nil {
return err
}

if deployOptionsHasChanged {
err = buildWithDeployAgent(ctx, newJob)
if err != nil {
return err
}
}

if newJobActiveDeadlineSeconds != nil {
newJob.Spec.ActiveDeadlineSeconds = newJobActiveDeadlineSeconds
}
Expand Down

0 comments on commit 1cd0e4e

Please sign in to comment.