Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
refactor noderef code
Browse files Browse the repository at this point in the history
Signed-off-by: Chuck Ha <chuckh@vmware.com>
  • Loading branch information
chuckha committed Jun 21, 2019
1 parent bae8376 commit 333da2a
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions actuators/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,9 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
fmt.Printf("%+v", err)
return err
}
nodeRef := &apicorev1.ObjectReference{
Kind: "Node",
APIVersion: apicorev1.SchemeGroupVersion.String(),
Name: controlPlaneNode.Name(),
UID: types.UID(nodeUID),
}
providerID := providerID(controlPlaneNode.Name())
machine.Spec.ProviderID = &providerID
return m.save(old, machine, nodeRef)
return m.save(old, machine, getNodeRef(controlPlaneNode.Name(), nodeUID))
}

fmt.Println("Creating a brand new cluster")
Expand All @@ -121,17 +115,10 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
fmt.Printf("%+v", err)
return err
}
nodeRef := &apicorev1.ObjectReference{
Kind: "Node",
APIVersion: apicorev1.SchemeGroupVersion.String(),
Name: controlPlaneNode.Name(),
UID: types.UID(nodeUID),
}

// set the machine's providerID
providerID := providerID(controlPlaneNode.Name())
machine.Spec.ProviderID = &providerID
if err := m.save(old, machine, nodeRef); err != nil {
if err := m.save(old, machine, getNodeRef(controlPlaneNode.Name(), nodeUID)); err != nil {
fmt.Printf("%+v\n", err)
return err
}
Expand Down Expand Up @@ -167,13 +154,7 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
fmt.Printf("%+v", err)
return err
}
nodeRef := &apicorev1.ObjectReference{
Kind: "Node",
APIVersion: apicorev1.SchemeGroupVersion.String(),
Name: worker.Name(),
UID: types.UID(nodeUID),
}
return m.save(old, machine, nodeRef)
return m.save(old, machine, getNodeRef(worker.Name(), nodeUID))
}

// Delete returns nil when the machine no longer exists or when a successful delete has happened.
Expand Down Expand Up @@ -262,3 +243,12 @@ func CAPIroleToKindRole(CAPIRole string) string {
}
return CAPIRole
}

func getNodeRef(name, uid string) *apicorev1.ObjectReference {
return &apicorev1.ObjectReference{
Kind: "Node",
APIVersion: apicorev1.SchemeGroupVersion.String(),
Name: name,
UID: types.UID(uid),
}
}

0 comments on commit 333da2a

Please sign in to comment.