Skip to content

Commit

Permalink
WIP Add ProviderID
Browse files Browse the repository at this point in the history
The cluster autoscaler expects this to be set on both machines
and nodes, and typically the cluster-api provider will set the
value in the spec for the machine e.g

https://github.com/openshift/cluster-api-provider-aws/blob/master/pkg/actuators/machine/reconciler.go#L280

In the baremetal case though there's no "provider" to set the value
on the node, so we also update that correspondingly (TODO)

https://bugzilla.redhat.com/show_bug.cgi?id=1852959
  • Loading branch information
Steven Hardy committed Jul 6, 2020
1 parent c682245 commit 5c74ca7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/cloud/baremetal/actuators/machine/actuator.go
Expand Up @@ -260,6 +260,11 @@ func (a *Actuator) Update(ctx context.Context, machine *machinev1beta1.Machine)
return err
}

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

if err := a.handleNodeFinalizer(ctx, machine); err != nil {
return err
}
Expand Down Expand Up @@ -498,6 +503,19 @@ func (a *Actuator) ensureAnnotation(ctx context.Context, machine *machinev1beta1
return true, a.client.Update(ctx, machine)
}

func (a *Actuator) ensureProviderID(ctx context.Context, machine *machinev1beta1.Machine, host *bmh.BareMetalHost) (error) {
if host.Status.Provisioning.ID != "" {
providerID := "baremetal:" + host.Status.Provisioning.ID
existingProviderID := machine.Spec.ProviderID
if existingProviderID == nil || *existingProviderID != providerID {
log.Printf("Setting ProviderID %s for machine %s.", providerID, machine.Name)
machine.Spec.ProviderID = &providerID
return a.client.Update(ctx, machine)
}
}
return nil
}

// handleNodeFinalizer adds finalizer to Node if not already exists
// it also store the node annotations and labels on Machine annotations
// upon node deletion
Expand Down

0 comments on commit 5c74ca7

Please sign in to comment.