diff --git a/controlplane/controllers/kthreescontrolplane_controller.go b/controlplane/controllers/kthreescontrolplane_controller.go index 07506b92..d74ddccf 100644 --- a/controlplane/controllers/kthreescontrolplane_controller.go +++ b/controlplane/controllers/kthreescontrolplane_controller.go @@ -397,9 +397,12 @@ func (r *KThreesControlPlaneReconciler) updateStatus(ctx context.Context, kcp *c kcp.Status.ReadyReplicas = status.ReadyNodes kcp.Status.UnavailableReplicas = replicas - status.ReadyNodes + if status.HasK3sServingSecret { + kcp.Status.Initialized = true + } + if kcp.Status.ReadyReplicas > 0 { kcp.Status.Ready = true - kcp.Status.Initialized = true conditions.MarkTrue(kcp, controlplanev1.AvailableCondition) } diff --git a/pkg/k3s/workload_cluster.go b/pkg/k3s/workload_cluster.go index 804e938d..1c438d11 100644 --- a/pkg/k3s/workload_cluster.go +++ b/pkg/k3s/workload_cluster.go @@ -25,6 +25,7 @@ import ( "sigs.k8s.io/cluster-api/util/collections" "sigs.k8s.io/cluster-api/util/conditions" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" controlplanev1 "github.com/k3s-io/cluster-api-k3s/controlplane/api/v1beta2" "github.com/k3s-io/cluster-api-k3s/pkg/etcd" @@ -34,6 +35,7 @@ import ( const ( kubeProxyKey = "kube-proxy" labelNodeRoleControlPlane = "node-role.kubernetes.io/master" + k3sServingSecretKey = "k3s-serving" ) var ( @@ -74,6 +76,8 @@ type ClusterStatus struct { Nodes int32 // ReadyNodes are the count of nodes that are reporting ready ReadyNodes int32 + // HasK3sServingSecret will be true if the k3s-serving secret has been uploaded, false otherwise. + HasK3sServingSecret bool } func (w *Workload) getControlPlaneNodes(ctx context.Context) (*corev1.NodeList, error) { @@ -105,6 +109,21 @@ func (w *Workload) ClusterStatus(ctx context.Context) (ClusterStatus, error) { } } + // find the k3s-serving secret + key := ctrlclient.ObjectKey{ + Name: k3sServingSecretKey, + Namespace: metav1.NamespaceSystem, + } + + err = w.Client.Get(ctx, key, &corev1.Secret{}) + // In case of error we do assume the control plane is not initialized yet. + if err != nil { + logger := log.FromContext(ctx) + logger.Info("Control Plane does not seem to be initialized yet.", "reason", err.Error()) + } + + status.HasK3sServingSecret = err == nil + return status, nil }