Skip to content

Commit

Permalink
Consider DefaultCNIConfiguredCondition in Ready condition except when…
Browse files Browse the repository at this point in the history
… Skip Upgrades is enabled (#7118)

* consider default cni status in ready condition except for when skip upgrades reason

* add unit tests for default cni updates
  • Loading branch information
cxbrowne1207 authored Dec 6, 2023
1 parent c2a0d1f commit fec15e4
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 10 deletions.
20 changes: 15 additions & 5 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,23 @@ func (r *ClusterReconciler) updateStatus(ctx context.Context, log logr.Logger, c

clusters.UpdateClusterStatusForCNI(ctx, cluster)

summarizedConditionTypes := []anywherev1.ConditionType{
anywherev1.ControlPlaneInitializedCondition,
anywherev1.ControlPlaneReadyCondition,
anywherev1.WorkersReadyCondition,
}

defaultCNIConfiguredCondition := conditions.Get(cluster, anywherev1.DefaultCNIConfiguredCondition)
if defaultCNIConfiguredCondition == nil ||
(defaultCNIConfiguredCondition != nil &&
defaultCNIConfiguredCondition.Status == "False" &&
defaultCNIConfiguredCondition.Reason != anywherev1.SkipUpgradesForDefaultCNIConfiguredReason) {
summarizedConditionTypes = append(summarizedConditionTypes, anywherev1.DefaultCNIConfiguredCondition)
}

// Always update the readyCondition by summarizing the state of other conditions.
conditions.SetSummary(cluster,
conditions.WithConditions(
anywherev1.ControlPlaneInitializedCondition,
anywherev1.ControlPlaneReadyCondition,
anywherev1.WorkersReadyCondition,
),
conditions.WithConditions(summarizedConditionTypes...),
)

return nil
Expand Down
116 changes: 111 additions & 5 deletions controllers/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,16 @@ func TestClusterReconcilerReconcileConditions(t *testing.T) {
testCases := []struct {
testName string
skipCNIUpgrade bool
cniUpgradeInProgress bool
kcpStatus controlplanev1.KubeadmControlPlaneStatus
machineDeploymentStatus clusterv1.MachineDeploymentStatus
result ctrl.Result
wantConditions []anywherev1.Condition
}{
{
testName: "cluster not ready, control plane not initialized",
testName: "cluster not ready, control plane not initialized",
skipCNIUpgrade: false,
cniUpgradeInProgress: false,
kcpStatus: controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Expand All @@ -221,7 +224,9 @@ func TestClusterReconcilerReconcileConditions(t *testing.T) {
result: ctrl.Result{Requeue: false, RequeueAfter: 10 * time.Second},
},
{
testName: "cluster not ready, control plane initialized",
testName: "cluster not ready, control plane initialized",
skipCNIUpgrade: false,
cniUpgradeInProgress: false,
kcpStatus: controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Expand All @@ -245,7 +250,9 @@ func TestClusterReconcilerReconcileConditions(t *testing.T) {
result: ctrl.Result{Requeue: false, RequeueAfter: 10 * time.Second},
},
{
testName: "cluster not ready, control plane ready",
testName: "cluster not ready, control plane ready",
skipCNIUpgrade: false,
cniUpgradeInProgress: false,
kcpStatus: controlplanev1.KubeadmControlPlaneStatus{
ReadyReplicas: 1,
Replicas: 1,
Expand All @@ -269,13 +276,16 @@ func TestClusterReconcilerReconcileConditions(t *testing.T) {
wantConditions: []anywherev1.Condition{
*conditions.FalseCondition(anywherev1.ReadyCondition, anywherev1.ScalingUpReason, clusterv1.ConditionSeverityInfo, "Scaling up worker nodes, 1 expected (0 actual)"),
*conditions.TrueCondition(anywherev1.ControlPlaneReadyCondition),
*conditions.TrueCondition(anywherev1.DefaultCNIConfiguredCondition),
*conditions.FalseCondition(anywherev1.WorkersReadyCondition, anywherev1.ScalingUpReason, clusterv1.ConditionSeverityInfo, "Scaling up worker nodes, 1 expected (0 actual)"),
*conditions.TrueCondition(anywherev1.ControlPlaneInitializedCondition),
},
result: ctrl.Result{Requeue: false, RequeueAfter: 10 * time.Second},
},
{
testName: "cluster ready",
testName: "cluster ready",
skipCNIUpgrade: false,
cniUpgradeInProgress: false,
kcpStatus: controlplanev1.KubeadmControlPlaneStatus{
ReadyReplicas: 1,
Replicas: 1,
Expand Down Expand Up @@ -303,11 +313,86 @@ func TestClusterReconcilerReconcileConditions(t *testing.T) {
wantConditions: []anywherev1.Condition{
*conditions.TrueCondition(anywherev1.ReadyCondition),
*conditions.TrueCondition(anywherev1.ControlPlaneReadyCondition),
*conditions.TrueCondition(anywherev1.DefaultCNIConfiguredCondition),
*conditions.TrueCondition(anywherev1.WorkersReadyCondition),
*conditions.TrueCondition(anywherev1.ControlPlaneInitializedCondition),
},
result: ctrl.Result{},
},
{
testName: "cluster ready, skip upgrades for default cni",
skipCNIUpgrade: true,
cniUpgradeInProgress: false,
kcpStatus: controlplanev1.KubeadmControlPlaneStatus{
ReadyReplicas: 1,
Replicas: 1,
UpdatedReplicas: 1,
Conditions: clusterv1.Conditions{
{
Type: controlplanev1.ControlPlaneComponentsHealthyCondition,
Status: apiv1.ConditionStatus("True"),
},
{
Type: controlplanev1.AvailableCondition,
Status: apiv1.ConditionStatus("True"),
},
{
Type: clusterv1.ReadyCondition,
Status: apiv1.ConditionStatus("True"),
},
},
},
machineDeploymentStatus: clusterv1.MachineDeploymentStatus{
ReadyReplicas: 1,
Replicas: 1,
UpdatedReplicas: 1,
},
wantConditions: []anywherev1.Condition{
*conditions.TrueCondition(anywherev1.ReadyCondition),
*conditions.TrueCondition(anywherev1.ControlPlaneReadyCondition),
*conditions.FalseCondition(anywherev1.DefaultCNIConfiguredCondition, anywherev1.SkipUpgradesForDefaultCNIConfiguredReason, clusterv1.ConditionSeverityWarning, "Configured to skip default Cilium CNI upgrades"),
*conditions.TrueCondition(anywherev1.WorkersReadyCondition),
*conditions.TrueCondition(anywherev1.ControlPlaneInitializedCondition),
},
result: ctrl.Result{},
},
{
testName: "cluster not ready, default cni upgrade in progress",
skipCNIUpgrade: false,
cniUpgradeInProgress: true,
kcpStatus: controlplanev1.KubeadmControlPlaneStatus{
ReadyReplicas: 1,
Replicas: 1,
UpdatedReplicas: 1,
Conditions: clusterv1.Conditions{
{
Type: controlplanev1.ControlPlaneComponentsHealthyCondition,
Status: apiv1.ConditionStatus("True"),
},
{
Type: controlplanev1.AvailableCondition,
Status: apiv1.ConditionStatus("True"),
},
{
Type: clusterv1.ReadyCondition,
Status: apiv1.ConditionStatus("True"),
},
},
},
machineDeploymentStatus: clusterv1.MachineDeploymentStatus{
ReadyReplicas: 1,
Replicas: 1,
UpdatedReplicas: 1,
},
wantConditions: []anywherev1.Condition{
*conditions.FalseCondition(anywherev1.ReadyCondition, anywherev1.DefaultCNIUpgradeInProgressReason, clusterv1.ConditionSeverityInfo, "Cilium version upgrade needed"),
*conditions.TrueCondition(anywherev1.ControlPlaneReadyCondition),
*conditions.FalseCondition(anywherev1.DefaultCNIConfiguredCondition, anywherev1.DefaultCNIUpgradeInProgressReason, clusterv1.ConditionSeverityInfo, "Cilium version upgrade needed"),
*conditions.TrueCondition(anywherev1.WorkersReadyCondition),
*conditions.TrueCondition(anywherev1.ControlPlaneInitializedCondition),
},
result: ctrl.Result{Requeue: false, RequeueAfter: 10 * time.Second},
},
}
for _, tt := range testCases {
t.Run(tt.testName, func(t *testing.T) {
Expand Down Expand Up @@ -369,7 +454,28 @@ func TestClusterReconcilerReconcileConditions(t *testing.T) {

iam.EXPECT().EnsureCASecret(logCtx, gomock.AssignableToTypeOf(logr.Logger{}), sameName(config.Cluster)).Return(controller.Result{}, nil)
iam.EXPECT().Reconcile(logCtx, gomock.AssignableToTypeOf(logr.Logger{}), sameName(config.Cluster)).Return(controller.Result{}, nil)
providerReconciler.EXPECT().Reconcile(logCtx, gomock.AssignableToTypeOf(logr.Logger{}), sameName(config.Cluster)).Times(1)
providerReconciler.EXPECT().Reconcile(logCtx, gomock.AssignableToTypeOf(logr.Logger{}), sameName(config.Cluster)).Times(1).Do(
func(ctx context.Context, log logr.Logger, cluster *anywherev1.Cluster) {
kcpReadyCondition := conditions.Get(kcp, clusterv1.ReadyCondition)
if kcpReadyCondition == nil ||
(kcpReadyCondition != nil && kcpReadyCondition.Status == "False") {
conditions.MarkFalse(cluster, anywherev1.DefaultCNIConfiguredCondition, anywherev1.ControlPlaneNotReadyReason, clusterv1.ConditionSeverityInfo, "")
return
}

if tt.skipCNIUpgrade {
conditions.MarkFalse(cluster, anywherev1.DefaultCNIConfiguredCondition, anywherev1.SkipUpgradesForDefaultCNIConfiguredReason, clusterv1.ConditionSeverityWarning, "Configured to skip default Cilium CNI upgrades")
return
}

if tt.cniUpgradeInProgress {
conditions.MarkFalse(cluster, anywherev1.DefaultCNIConfiguredCondition, anywherev1.DefaultCNIUpgradeInProgressReason, clusterv1.ConditionSeverityInfo, "Cilium version upgrade needed")
return
}

conditions.MarkTrue(cluster, anywherev1.DefaultCNIConfiguredCondition)
},
)
clusterValidator.EXPECT().ValidateManagementClusterName(logCtx, gomock.AssignableToTypeOf(logr.Logger{}), sameName(config.Cluster)).Return(nil)

mockPkgs.EXPECT().Reconcile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
Expand Down

0 comments on commit fec15e4

Please sign in to comment.