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 12, 2023
1 parent bb2cd92 commit 6e02548
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 17 deletions.
16 changes: 12 additions & 4 deletions pkg/controller/clusters/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,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")
}
}
}

Expand Down Expand Up @@ -85,6 +86,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.RollingUpgradeInProgress, clusterv1.ConditionSeverityInfo, "Etcd cluster is not available yet")
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.RollingUpgradeInProgress,
Severity: clusterv1.ConditionSeverityInfo,
Message: "Etcd cluster is not available yet",
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 6e02548

Please sign in to comment.