Skip to content
Open
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
16 changes: 15 additions & 1 deletion pkg/controller/build/imagebuilder/jobimagebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,21 @@ func (j *jobImageBuilder) start(ctx context.Context) (*batchv1.Job, error) {
}

if k8serrors.IsAlreadyExists(err) {
return j.getBuildJobStrict(ctx)
existingJob, getErr := j.getBuildJobStrict(ctx)
if getErr != nil {
return nil, getErr
}

klog.Infof("Build job %q already exists for MachineOSBuild %q, reusing", existingJob.Name, mosbName)

if j.mosb != nil {
metav1.SetMetaDataAnnotation(&j.mosb.ObjectMeta, constants.JobUIDAnnotationKey, string(existingJob.UID))
if _, updateErr := j.mcfgclient.MachineconfigurationV1().MachineOSBuilds().Update(ctx, j.mosb, metav1.UpdateOptions{}); updateErr != nil && !k8serrors.IsNotFound(updateErr) {
return nil, fmt.Errorf("could not update MachineOSBuild %s with job UID annotation: %w", mosbName, updateErr)
}
}

return existingJob, nil
}

return nil, fmt.Errorf("could not create build job: %w", err)
Expand Down
9 changes: 6 additions & 3 deletions pkg/controller/build/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,15 +1362,18 @@ func (b *buildReconciler) reconcilePoolChange(ctx context.Context, mcp *mcfgv1.M
// old pool
old := mcp.DeepCopy()
old.Spec.Configuration.Name = mcp.Status.Configuration.Name
if firstOptIn == "" {
return fmt.Errorf("no current build annotation on MachineOSConfig %q", mosc.Name)
}

needsImageRebuild, err := b.reconcileImageRebuild(old, mcp)
if err != nil {
return err
}

// No action needed if the rendered config has not changed and we have an annotation
if oldRendered == newRendered && firstOptIn != "" {
klog.V(4).Infof("pool %q: Configuration unchanged (%s), no action needed", mcp.Name, oldRendered)
return nil
}

// This is our trigger point
if (oldRendered != newRendered && needsImageRebuild) || firstOptIn == "" {
klog.Infof("pool %q: rendered config changed and requires an image rebuild. Verifying if a valid build already exists...", mcp.Name)
Expand Down