Skip to content

Commit

Permalink
Check k3s-serving secret to determine controlPlane.Status.Initialized
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti committed May 14, 2024
1 parent 0527d86 commit 76fdec5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion controlplane/controllers/kthreescontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/k3s/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,6 +35,7 @@ import (
const (
kubeProxyKey = "kube-proxy"
labelNodeRoleControlPlane = "node-role.kubernetes.io/master"
k3sServingSecretKey = "k3s-serving"
)

var (
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 76fdec5

Please sign in to comment.