Skip to content
Draft
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
1 change: 1 addition & 0 deletions cloud/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type MachineGetter interface {
Project() string
Role() string
IsControlPlane() bool
IsMachineProvisioned() bool
ControlPlaneGroupName() string
GetInstanceID() *string
GetProviderID() string
Expand Down
11 changes: 11 additions & 0 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ func (m *MachineScope) IsControlPlane() bool {
return IsControlPlaneMachine(m.Machine)
}

// IsMachineProvisioned returns true if the machine has been provisioned.
func (m *MachineScope) IsMachineProvisioned() bool {
// return m.Machine.Status.GetTypedPhase() == clusterv1.MachinePhaseProvisioned
for _, condition := range m.Machine.Status.Conditions {
if condition.Type == clusterv1.MachineNodeHealthyCondition && condition.Reason == clusterv1.WaitingForNodeRefReason {
return true
}
}
return false
}

// Role returns the machine role from the labels.
func (m *MachineScope) Role() string {
if IsControlPlaneMachine(m.Machine) {
Expand Down
9 changes: 7 additions & 2 deletions cloud/services/compute/instances/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ func (s *Service) Reconcile(ctx context.Context) error {
s.scope.SetInstanceStatus(infrav1.InstanceStatus(instance.Status))

if s.scope.IsControlPlane() {
if err := s.registerControlPlaneInstance(ctx, instance); err != nil {
return err
if s.scope.IsMachineProvisioned() {
log.V(2).Info("[DEBUG] Registering control plane instance in the instancegroup", "name", instance.Name)
if err := s.registerControlPlaneInstance(ctx, instance); err != nil {
return err
}
} else {
log.V(2).Info("[DEBUG] Skipping registering control plane instance in the instancegroup because machine is not yet provisioned", "name", instance.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments with more background on the problem would be helpful for our future selves I think!

}
}

Expand Down
33 changes: 32 additions & 1 deletion controllers/gcpmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
"sigs.k8s.io/cluster-api/util/predicates"
"sigs.k8s.io/cluster-api/util/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"
)

Expand All @@ -63,6 +66,33 @@
Watches(
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(util.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("GCPMachine"))),
builder.WithPredicates(predicate.Funcs{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary?

UpdateFunc: func(e event.UpdateEvent) bool {
oldMachine := e.ObjectOld.(*clusterv1.Machine)
newMachine := e.ObjectNew.(*clusterv1.Machine)

// Reconcile if the spec changes.
if newMachine.GetGeneration() != oldMachine.GetGeneration() {
return true
}

// Reconcile if the machine just transitioned to the Provisioned phase.
if newMachine.Status.GetTypedPhase() == clusterv1.MachinePhaseProvisioned && oldMachine.Status.GetTypedPhase() != clusterv1.MachinePhaseProvisioned {
return true
}

for _, condition := range newMachine.Status.Conditions {
if condition.Type == clusterv1.MachineNodeHealthyCondition {
// TODO: Reconcile if the MachineNodeHealthyCondition condition changed.

Check failure on line 86 in controllers/gcpmachine_controller.go

View workflow job for this annotation

GitHub Actions / lint

Line contains TODO/BUG/FIXME: "TODO: Reconcile if the MachineNodeHealth..." (godox)
if condition.Type == clusterv1.MachineNodeHealthyCondition && condition.Reason == clusterv1.WaitingForNodeRefReason {
return true
}
}
}

return false
},
}),
).
Watches(
&infrav1.GCPCluster{},
Expand Down Expand Up @@ -224,7 +254,8 @@
return ctrl.Result{}, err
}

if err := instances.New(machineScope).Reconcile(ctx); err != nil {
instancesSvc := instances.New(machineScope)
if err := instancesSvc.Reconcile(ctx); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly I don't think this is important to this PR.

log.Error(err, "Error reconciling instance resources")
record.Warnf(machineScope.GCPMachine, "GCPMachineReconcile", "Reconcile error - %v", err)
return ctrl.Result{}, err
Expand Down
Loading