Skip to content

Commit ff4c867

Browse files
PCP-5489: Allow worker nodes to be checked for lxd initialization (#286)
(cherry picked from commit c0b7c20)
1 parent e07b51c commit ff4c867

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

controllers/lxd_initializer_ds.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
appsv1 "k8s.io/api/apps/v1"
99
corev1 "k8s.io/api/core/v1"
1010
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
11-
"k8s.io/apimachinery/pkg/labels"
1211
"k8s.io/apimachinery/pkg/runtime/schema"
1312
"sigs.k8s.io/controller-runtime/pkg/client"
1413
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -35,7 +34,7 @@ func render(replacements map[string]string, tmpl string) string {
3534
return tmpl
3635
}
3736

38-
// ensureLXDInitializerDS creates or deletes the DaemonSet that initialises LXD on control-plane nodes
37+
// ensureLXDInitializerDS creates or deletes the DaemonSet that initialises LXD on all nodes (control-plane and worker)
3938
func (r *MaasClusterReconciler) ensureLXDInitializerDS(ctx context.Context, clusterScope *scope.ClusterScope) error {
4039
cluster := clusterScope.MaasCluster
4140

@@ -210,19 +209,17 @@ func (r *MaasClusterReconciler) enoughNodesReady(ctx context.Context, remoteClie
210209
return true
211210
}
212211

213-
// anyNodeNeedsInitialization returns true if any control-plane node needs initialization.
214-
// Only checks Ready control-plane nodes to avoid false positives from nodes that aren't ready yet.
212+
// anyNodeNeedsInitialization returns true if any node (control-plane or worker) needs initialization.
213+
// Only checks Ready nodes to avoid false positives from nodes that aren't ready yet.
215214
func (r *MaasClusterReconciler) anyNodeNeedsInitialization(ctx context.Context, remoteClient client.Client) bool {
216215
nodeList := &corev1.NodeList{}
217-
cpSelector := labels.SelectorFromSet(labels.Set{
218-
"node-role.kubernetes.io/control-plane": "",
219-
})
220-
if err := remoteClient.List(ctx, nodeList, &client.ListOptions{LabelSelector: cpSelector}); err != nil {
216+
// Check all nodes, not just control-plane, to include worker nodes
217+
if err := remoteClient.List(ctx, nodeList); err != nil {
221218
r.Log.Info("Failed to list nodes; proceeding to create initializer DS to be safe", "error", err)
222219
return true
223220
}
224221
if len(nodeList.Items) == 0 {
225-
r.Log.Info("No control-plane nodes reported yet; proceeding with initializer DS")
222+
r.Log.Info("No nodes reported yet; proceeding with initializer DS")
226223
return true
227224
}
228225

@@ -238,7 +235,12 @@ func (r *MaasClusterReconciler) anyNodeNeedsInitialization(ctx context.Context,
238235

239236
// If node is Ready but not initialized, it needs initialization
240237
if isReady && (n.Labels == nil || n.Labels["lxdhost.cluster.com/initialized"] != "true") {
241-
r.Log.Info("Ready control-plane node requires LXD initialization", "node", n.Name)
238+
// Determine node role for logging
239+
nodeRole := "worker"
240+
if n.Labels != nil && n.Labels["node-role.kubernetes.io/control-plane"] != "" {
241+
nodeRole = "control-plane"
242+
}
243+
r.Log.Info("Ready node requires LXD initialization", "node", n.Name, "role", nodeRole)
242244
return true
243245
}
244246

@@ -267,7 +269,7 @@ func (r *MaasClusterReconciler) deleteExistingInitializerDS(ctx context.Context,
267269
return nil
268270
}
269271

270-
// maybeShortCircuitDelete deletes the DS if all CP nodes are already initialized
272+
// maybeShortCircuitDelete deletes the DS if all nodes are already initialized
271273
// BUT only if we have exactly desiredCP nodes - avoids deleting during maintenance when new nodes are joining
272274
func (r *MaasClusterReconciler) maybeShortCircuitDelete(ctx context.Context, remoteClient client.Client, namespace string, desiredCP int32, dsName string) (bool, error) {
273275
shortCircuitNodes := &corev1.NodeList{}
@@ -306,7 +308,7 @@ func (r *MaasClusterReconciler) maybeShortCircuitDelete(ctx context.Context, rem
306308
_ = remoteClient.Delete(ctx, &ds)
307309
}
308310
}
309-
r.Log.Info("Deleted LXD initializer DaemonSet - all control-plane nodes are ready and initialized",
311+
r.Log.Info("Deleted LXD initializer DaemonSet - all nodes are ready and initialized",
310312
"desiredCP", desiredCP, "totalNodes", len(shortCircuitNodes.Items), "readyNodes", readyCount, "initializedNodes", initCount)
311313
return true, nil
312314
}

0 commit comments

Comments
 (0)