Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bc02c8e
Delay Machine deletion until BaremetalHost deprovisioned
zaneb Jun 17, 2019
4841e88
controller watches BareMetalHosts and enqueues corresponding Machines
mhrivnak Jun 21, 2019
5412fd9
updates vendor for watching BareMetalHosts
mhrivnak Jun 21, 2019
54df54a
Don't remove MachineRef from Host before Machine deleted
zaneb Jun 22, 2019
a23a763
Merge pull request #90 from mhrivnak/watch-hosts
russellb Jun 25, 2019
89992ea
Bump to latest baremetal-operator
bcrochet Jun 25, 2019
130aa84
Set the hostname from HardwareDetails
bcrochet Jun 25, 2019
4f2aef9
Merge pull request #86 from zaneb/delete-deprovision
dhellmann Jun 26, 2019
75e08e0
update baremetal-operator and cluster-api code before API change
dhellmann Jun 17, 2019
77a5839
update baremetal-operator to include ConsumerRef field
dhellmann Jun 25, 2019
11b6830
switch to using ConsumerRef instead of MachineRef
dhellmann Jun 25, 2019
58c3f6d
include Kind field in tests
dhellmann Jun 25, 2019
98f4e2e
update mapper use of MachineRef
dhellmann Jun 25, 2019
914ee99
include more details in consumer reference comparison
dhellmann Jun 25, 2019
45ac184
require machine api version to match in mapper
dhellmann Jun 26, 2019
ce9f572
use real machine API version details in tests
dhellmann Jun 26, 2019
1b117a3
fix clearing of consumer ref
dhellmann Jun 26, 2019
91db04c
compare consumer ref to machine more carefully
dhellmann Jun 26, 2019
3e044f9
include metadata in test machines
dhellmann Jun 26, 2019
c28b256
Merge pull request #91 from bcrochet/hostname-details
russellb Jun 27, 2019
936e162
Merge pull request #92 from dhellmann/consumer-id
dhellmann Jun 28, 2019
98c4d24
Merge branch 'master' into openshift-update-bmo-20190701
dhellmann Jul 1, 2019
af00e36
gofmt fix
dhellmann Jul 1, 2019
e8327d4
import the machine type from the openshift fork of cluster-api
dhellmann Jul 1, 2019
b57e80d
import webhook definitions from the location vendored in this repo
dhellmann Jul 1, 2019
1079e36
import cluster error from the openshift fork of cluster-api
dhellmann Jul 1, 2019
9888765
fixup machine api import
dhellmann Jul 1, 2019
6c1e3cf
update wrapper to use the manager API from the controller runtime in …
dhellmann Jul 1, 2019
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
4 changes: 4 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
bmoapis "github.com/metal3-io/baremetal-operator/pkg/apis"
"github.com/metal3-io/cluster-api-provider-baremetal/pkg/apis"
"github.com/metal3-io/cluster-api-provider-baremetal/pkg/cloud/baremetal/actuators/machine"
"github.com/metal3-io/cluster-api-provider-baremetal/pkg/manager/wrapper"
clusterapis "github.com/openshift/cluster-api/pkg/apis"
capimachine "github.com/openshift/cluster-api/pkg/controller/machine"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -93,7 +94,8 @@ func main() {
panic(err)
}

capimachine.AddWithActuator(mgr, machineActuator)
// the manager wrapper will add an extra Watch to the controller
capimachine.AddWithActuator(wrapper.New(mgr), machineActuator)

if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
entryLog.Error(err, "unable to run manager")
Expand Down
62 changes: 53 additions & 9 deletions pkg/cloud/baremetal/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,34 @@ func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machi
if err != nil {
return err
}
if host != nil && host.Spec.MachineRef != nil {
// don't remove the MachineRef if it references some other machine
if host.Spec.MachineRef.Name == machine.Name {
host.Spec.MachineRef = nil
if host != nil && host.Spec.ConsumerRef != nil {
// don't remove the ConsumerRef if it references some other machine
if !consumerRefMatches(host.Spec.ConsumerRef, machine) {
log.Printf("host associated with %v, not machine %v.",
host.Spec.ConsumerRef.Name, machine.Name)
return nil
}
if host.Spec.Image != nil || host.Spec.Online || host.Spec.UserData != nil {
host.Spec.Image = nil
host.Spec.Online = false
host.Spec.UserData = nil
err = a.client.Update(ctx, host)
if err != nil && !errors.IsNotFound(err) {
return err
}
return &clustererror.RequeueAfterError{}
}
switch host.Status.Provisioning.State {
default:
return &clustererror.RequeueAfterError{RequeueAfter: requeueAfter}
case bmh.StateRegistrationError, bmh.StateRegistering,
bmh.StateMatchProfile, bmh.StateInspecting,
bmh.StateReady, bmh.StateValidationError:
host.Spec.ConsumerRef = nil
err = a.client.Update(ctx, host)
if err != nil && !errors.IsNotFound(err) {
return err
}
}
}
log.Printf("finished deleting machine %v.", machine.Name)
Expand Down Expand Up @@ -309,8 +326,8 @@ func (a *Actuator) chooseHost(ctx context.Context, machine *machinev1.Machine,
} else {
log.Printf("Host '%s' did not match hostSelector for Machine '%s'", host.Name, machine.Name)
}
} else if host.Spec.MachineRef != nil && host.Spec.MachineRef.Name == machine.Name && host.Spec.MachineRef.Namespace == machine.Namespace {
log.Printf("found host %s with existing MachineRef", host.Name)
} else if host.Spec.ConsumerRef != nil && consumerRefMatches(host.Spec.ConsumerRef, machine) {
log.Printf("found host %s with existing ConsumerRef", host.Name)
return &hosts.Items[i], nil
}
}
Expand All @@ -326,15 +343,35 @@ func (a *Actuator) chooseHost(ctx context.Context, machine *machinev1.Machine,
return chosenHost, nil
}

// consumerRefMatches returns a boolean based on whether the consumer
// reference and machine metadata match
func consumerRefMatches(consumer *corev1.ObjectReference, machine *machinev1.Machine) bool {
if consumer.Name != machine.Name {
return false
}
if consumer.Namespace != machine.Namespace {
return false
}
if consumer.Kind != machine.Kind {
return false
}
if consumer.APIVersion != machine.APIVersion {
return false
}
return true
}

// setHostSpec will ensure the host's Spec is set according to the machine's
// details. It will then update the host via the kube API. If UserData does not
// include a Namespace, it will default to the Machine's namespace.
func (a *Actuator) setHostSpec(ctx context.Context, host *bmh.BareMetalHost, machine *machinev1.Machine,
config *bmv1alpha1.BareMetalMachineProviderSpec) error {

host.Spec.MachineRef = &corev1.ObjectReference{
Name: machine.Name,
Namespace: machine.Namespace,
host.Spec.ConsumerRef = &corev1.ObjectReference{
Kind: "Machine",
Name: machine.Name,
Namespace: machine.Namespace,
APIVersion: machine.APIVersion,
}

host.Spec.Image = &bmh.Image{
Expand Down Expand Up @@ -465,5 +502,12 @@ func (a *Actuator) nodeAddresses(host *bmh.BareMetalHost) ([]corev1.NodeAddress,
addrs = append(addrs, address)
}

if host.Status.HardwareDetails.Hostname != "" {
addrs = append(addrs, corev1.NodeAddress{
Type: corev1.NodeHostName,
Address: host.Status.HardwareDetails.Hostname,
})
}

return addrs, nil
}
Loading