Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an additional check to make sure etcdadm and capi clusters are available #6806

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}
}

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
141 changes: 128 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,82 @@ 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{},
},
{
name: "with external etcd, malformed etcd",
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 +586,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 All @@ -532,6 +610,43 @@ func TestUpdateClusterStatusForControlPlane(t *testing.T) {
}
}

func TestUpdateClusterStatusForControlPlaneError(t *testing.T) {
g := NewWithT(t)
cluster := &anywherev1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: anywherev1.ClusterKind,
APIVersion: anywherev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster",
},
Spec: anywherev1.ClusterSpec{
ExternalEtcdConfiguration: &anywherev1.ExternalEtcdConfiguration{
Count: 1,
},
},
}
capiCluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster",
Namespace: constants.EksaSystemNamespace,
},
Spec: clusterv1.ClusterSpec{
ManagedExternalEtcdRef: &corev1.ObjectReference{
Kind: "EtcdadmCluster",
Name: fmt.Sprintf("%s-etcd", "test-cluster"),
},
},
}
objs := []runtime.Object{}
objs = append(objs, capiCluster)
objs = append(objs, &controlplanev1.KubeadmControlPlane{})
client := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()

err := clusters.UpdateClusterStatusForControlPlane(context.Background(), client, cluster)
g.Expect(err).NotTo(BeNil())
}

func TestUpdateClusterStatusForWorkers(t *testing.T) {
cluster := test.NewClusterSpec().Cluster
clusterName := "test-cluster"
Expand Down