Skip to content

Commit

Permalink
Added an additional check to make sure etcdadm and capi clusters are …
Browse files Browse the repository at this point in the history
…available for workoad cluster
  • Loading branch information
panktishah26 committed Oct 13, 2023
1 parent 3c6cece commit 5bc1e3f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 17 deletions.
3 changes: 3 additions & 0 deletions pkg/api/v1alpha1/condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const (
// RollingUpgradeInProgress reports the Cluster is executing a rolling upgrading to align the nodes to
// a new desired machine spec.
RollingUpgradeInProgress = "RollingUpgradeInProgress"

// ExternalEtcdNotAvailable reports the Cluster status is waiting for Etcd to be available.
ExternalEtcdNotAvailable = "ExternalEtcdNotAvailable"
)

const (
Expand Down
18 changes: 14 additions & 4 deletions pkg/controller/clusters/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

// UpdateClusterStatusForControlPlane checks the current state of the Cluster's control plane and updates the
// Cluster status information.
// There is a posibility that UpdateClusterStatusForControlPlane does not update the
// controleplane status specially in case where it still waiting for cluster objects to be created.
func UpdateClusterStatusForControlPlane(ctx context.Context, client client.Client, cluster *anywherev1.Cluster) error {
kcp, err := controller.GetKubeadmControlPlane(ctx, client, cluster)
if err != nil {
Expand All @@ -29,10 +31,11 @@ func UpdateClusterStatusForControlPlane(ctx context.Context, client client.Clien
if err != nil {
return errors.Wrap(err, "getting capi cluster")
}

etcdadmCluster, err = getEtcdadmCluster(ctx, client, capiCluster)
if err != nil {
return errors.Wrap(err, "reading etcdadm cluster")
if capiCluster != nil {
etcdadmCluster, err = getEtcdadmCluster(ctx, client, capiCluster)
if err != nil {
return errors.Wrap(err, "reading etcdadm cluster")
}

Check warning on line 38 in pkg/controller/clusters/status.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/clusters/status.go#L37-L38

Added lines #L37 - L38 were not covered by tests
}
}

Expand Down Expand Up @@ -85,6 +88,13 @@ func UpdateClusterStatusForCNI(ctx context.Context, cluster *anywherev1.Cluster)
// updateConditionsForEtcdAndControlPlane updates the ControlPlaneReady condition if etcdadm cluster is not ready.
func updateConditionsForEtcdAndControlPlane(cluster *anywherev1.Cluster, kcp *controlplanev1.KubeadmControlPlane, etcdadmCluster *etcdv1.EtcdadmCluster) {
// Make sure etcd cluster is ready before marking ControlPlaneReady status to true
// This condition happens while creating a workload cluster from the management cluster using controller
// where it tries to get the etcdadm cluster for the first time before it generates the resources.
if cluster.Spec.ExternalEtcdConfiguration != nil && etcdadmCluster == nil {
conditions.MarkFalse(cluster, anywherev1.ControlPlaneReadyCondition, anywherev1.ExternalEtcdNotAvailable, clusterv1.ConditionSeverityInfo, "Etcd cluster is not available")
return
}
// Make sure etcd machine is ready before marking ControlPlaneReady status to true
if cluster.Spec.ExternalEtcdConfiguration != nil && !etcdadmClusterReady(etcdadmCluster) {
conditions.MarkFalse(cluster, anywherev1.ControlPlaneReadyCondition, anywherev1.RollingUpgradeInProgress, clusterv1.ConditionSeverityInfo, "Etcd is not ready")
return
Expand Down
72 changes: 59 additions & 13 deletions pkg/controller/clusters/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestUpdateClusterStatusForControlPlane(t *testing.T) {
wantCondition *anywherev1.Condition
externalEtcdCount int
externalEtcdCluster *etcdv1.EtcdadmCluster
capiCluster *clusterv1.Cluster
}{
{
name: "kcp is nil",
Expand Down Expand Up @@ -429,6 +430,18 @@ func TestUpdateClusterStatusForControlPlane(t *testing.T) {
Type: anywherev1.ControlPlaneReadyCondition,
Status: "True",
},
capiCluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: constants.EksaSystemNamespace,
},
Spec: clusterv1.ClusterSpec{
ManagedExternalEtcdRef: &corev1.ObjectReference{
Kind: "EtcdadmCluster",
Name: fmt.Sprintf("%s-etcd", "test-cluster"),
},
},
},
},
{
name: "with external etcd not ready",
Expand Down Expand Up @@ -469,6 +482,50 @@ func TestUpdateClusterStatusForControlPlane(t *testing.T) {
Message: "Etcd is not ready",
Status: "False",
},
capiCluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: constants.EksaSystemNamespace,
},
Spec: clusterv1.ClusterSpec{
ManagedExternalEtcdRef: &corev1.ObjectReference{
Kind: "EtcdadmCluster",
Name: fmt.Sprintf("%s-etcd", "test-cluster"),
},
},
},
},
{
name: "with external etcd, etcd not reconciled",
kcp: test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Status.Replicas = 3
kcp.Status.ReadyReplicas = 3
kcp.Status.UpdatedReplicas = 3

kcp.Status.Conditions = []clusterv1.Condition{
{
Type: clusterv1.ReadyCondition,
Status: "True",
},
}
}),
controlPlaneCount: 3,
conditions: []anywherev1.Condition{
{
Type: anywherev1.ControlPlaneInitializedCondition,
Status: "True",
},
},
externalEtcdCount: 1,
externalEtcdCluster: &etcdv1.EtcdadmCluster{},
wantCondition: &anywherev1.Condition{
Type: anywherev1.ControlPlaneReadyCondition,
Reason: anywherev1.ExternalEtcdNotAvailable,
Severity: clusterv1.ConditionSeverityInfo,
Message: "Etcd cluster is not available",
Status: "False",
},
capiCluster: &clusterv1.Cluster{},
},
}

Expand Down Expand Up @@ -497,22 +554,11 @@ func TestUpdateClusterStatusForControlPlane(t *testing.T) {
Name: fmt.Sprintf("%s-etcd", cluster.Name),
},
}
capiCluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: cluster.Name,
Namespace: constants.EksaSystemNamespace,
},
Spec: clusterv1.ClusterSpec{
ManagedExternalEtcdRef: &corev1.ObjectReference{
Kind: "EtcdadmCluster",
Name: fmt.Sprintf("%s-etcd", cluster.Name),
},
},
}

tt.externalEtcdCluster.Name = fmt.Sprintf("%s-etcd", cluster.Name)
tt.externalEtcdCluster.Namespace = cluster.Namespace

objs = append(objs, capiCluster)
objs = append(objs, tt.capiCluster)
objs = append(objs, tt.externalEtcdCluster)
}

Expand Down

0 comments on commit 5bc1e3f

Please sign in to comment.