Skip to content

Commit

Permalink
Remediate only if machine object wasn't changed previously to avoid c…
Browse files Browse the repository at this point in the history
…onflicts

Signed-off-by: Nir <niry@redhat.com>
  • Loading branch information
n1r1 committed Apr 3, 2020
1 parent 1922fbd commit 6ae2e49
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/cloud/baremetal/actuators/machine/actuator.go
Expand Up @@ -134,7 +134,7 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
return err
}

err = a.ensureAnnotation(ctx, machine, host)
err, _ = a.ensureAnnotation(ctx, machine, host)
if err != nil {
return err
}
Expand Down Expand Up @@ -250,13 +250,15 @@ func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machi
return nil
}

err = a.ensureAnnotation(ctx, machine, host)
err, dirty := a.ensureAnnotation(ctx, machine, host)
if err != nil {
return err
}

if err := a.remediateIfNeeded(ctx, machine, host); err != nil {
return err
if !dirty {
if err := a.remediateIfNeeded(ctx, machine, host); err != nil {
return err
}
}

if err := a.updateMachineStatus(ctx, machine, host); err != nil {
Expand Down Expand Up @@ -464,26 +466,26 @@ func (a *Actuator) setHostSpec(ctx context.Context, host *bmh.BareMetalHost, mac

// ensureAnnotation makes sure the machine has an annotation that references the
// host and uses the API to update the machine if necessary.
func (a *Actuator) ensureAnnotation(ctx context.Context, machine *machinev1.Machine, host *bmh.BareMetalHost) error {
func (a *Actuator) ensureAnnotation(ctx context.Context, machine *machinev1.Machine, host *bmh.BareMetalHost) (error, bool) {
annotations := machine.ObjectMeta.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
hostKey, err := cache.MetaNamespaceKeyFunc(host)
if err != nil {
log.Printf("Error parsing annotation value \"%s\": %v", hostKey, err)
return err
return err, false
}
existing, ok := annotations[HostAnnotation]
if ok {
if existing == hostKey {
return nil
return nil, false
}
log.Printf("Warning: found stray annotation for host %s on machine %s. Overwriting.", existing, machine.Name)
}
annotations[HostAnnotation] = hostKey
machine.ObjectMeta.SetAnnotations(annotations)
return a.client.Update(ctx, machine)
return a.client.Update(ctx, machine), true
}

// setError sets the ErrorMessage and ErrorReason fields on the machine and logs
Expand Down

0 comments on commit 6ae2e49

Please sign in to comment.