Skip to content

Commit e038645

Browse files
PCP-5217: WLC Worker node receives static IP from IPAM pool even though IPAM is configured only for control-plane (#232) (#233)
(cherry picked from commit 18b8b48) Co-authored-by: Amit Sahastrabuddhe <[email protected]>
1 parent 72f36a3 commit e038645

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

controllers/maasmachine_controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,13 @@ func (r *MaasMachineReconciler) reconcileNormal(_ context.Context, machineScope
343343
return ctrl.Result{}, nil
344344
}
345345

346-
// If static IP is configured, make sure the IP field is populated by external controller.
347-
if staticIPConfig := machineScope.GetStaticIPConfig(); staticIPConfig != nil && machineScope.GetStaticIP() == "" {
348-
machineScope.Info("Static IP is configured but IP field is empty, waiting for external controller to populate it")
349-
conditions.MarkFalse(machineScope.MaasMachine, infrav1beta1.MachineDeployedCondition, infrav1beta1.WaitingForStaticIPReason, clusterv1.ConditionSeverityInfo, "")
350-
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
346+
// If control-plane static IP is configured, wait for IP assignment to be populated by external controller.
347+
if machineScope.IsControlPlane() {
348+
if staticIPConfig := machineScope.GetStaticIPConfig(); staticIPConfig != nil && machineScope.GetStaticIP() == "" {
349+
machineScope.Info("Static IP is configured for control-plane but IP field is empty, waiting for external controller to populate it")
350+
conditions.MarkFalse(machineScope.MaasMachine, infrav1beta1.MachineDeployedCondition, infrav1beta1.WaitingForStaticIPReason, clusterv1.ConditionSeverityInfo, "")
351+
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
352+
}
351353
}
352354

353355
machineSvc := maasmachine.NewService(machineScope)

pkg/maas/lxd/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ func (s *Service) isNodeLXDInitialized(machine *v1beta1.MaasMachine) (bool, erro
187187

188188
value, exists := node.Labels[LXDHostInitializedLabel]
189189
return exists && value == "true", nil
190-
}
190+
}

pkg/maas/machine/machine.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,15 @@ func (s *Service) DeployMachine(userDataB64 string) (_ *infrav1beta1.Machine, re
236236

237237
s.scope.Info("Swap disabled", "system-id", m.SystemID())
238238

239-
// Configure static IP before deployment
240-
if staticIP := s.scope.GetStaticIP(); staticIP != "" {
241-
staticIPConfig := s.scope.GetStaticIPConfig()
242-
if staticIPConfig != nil {
243-
err := s.setMachineStaticIP(m.SystemID(), staticIPConfig)
244-
if err != nil {
245-
return nil, errors.Wrapf(err, "failed to configure static IP")
239+
// Configure static IP before deployment (control-plane only)
240+
if s.scope.IsControlPlane() {
241+
if staticIP := s.scope.GetStaticIP(); staticIP != "" {
242+
staticIPConfig := s.scope.GetStaticIPConfig()
243+
if staticIPConfig != nil {
244+
err := s.setMachineStaticIP(m.SystemID(), staticIPConfig)
245+
if err != nil {
246+
return nil, errors.Wrapf(err, "failed to configure static IP")
247+
}
246248
}
247249
}
248250
}
@@ -276,10 +278,12 @@ func (s *Service) createVMViaMAAS(ctx context.Context, userDataB64 string) (*inf
276278
machineName := s.scope.Machine.Name
277279
vmName := fmt.Sprintf("vm-%s", machineName)
278280
_, _ = m.Modifier().SetHostname(vmName).Update(ctx)
279-
if staticIP := s.scope.GetStaticIP(); staticIP != "" {
280-
if err := s.setMachineStaticIP(m.SystemID(), &infrav1beta1.StaticIPConfig{IP: staticIP}); err != nil {
281-
// Fail fast so we don't attempt Deploy without a network link configured
282-
return nil, errors.Wrap(err, "failed to configure static IP before deploy")
281+
if s.scope.IsControlPlane() {
282+
if staticIP := s.scope.GetStaticIP(); staticIP != "" {
283+
if err := s.setMachineStaticIP(m.SystemID(), &infrav1beta1.StaticIPConfig{IP: staticIP}); err != nil {
284+
// Fail fast so we don't attempt Deploy without a network link configured
285+
return nil, errors.Wrap(err, "failed to configure static IP before deploy")
286+
}
283287
}
284288
}
285289
deployingM, err := m.Deployer().

0 commit comments

Comments
 (0)