diff --git a/controllers/cluster_controller_test.go b/controllers/cluster_controller_test.go index 799e28f7a4eb..7ff79d37a26e 100644 --- a/controllers/cluster_controller_test.go +++ b/controllers/cluster_controller_test.go @@ -728,7 +728,23 @@ func TestClusterReconcilerReconcileSelfManagedClusterConditions(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(gomock.Any(), gomock.Any(), gomock.Any()).Times(1) + providerReconciler.EXPECT().Reconcile(gomock.Any(), gomock.Any(), gomock.Any()).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 + } + + conditions.MarkTrue(cluster, anywherev1.DefaultCNIConfiguredCondition) + }, + ) mhcReconciler.EXPECT().Reconcile(logCtx, gomock.AssignableToTypeOf(logr.Logger{}), sameName(config.Cluster)).Return(nil) r := controllers.NewClusterReconciler(testClient, registry, iam, clusterValidator, mockPkgs, mhcReconciler) diff --git a/pkg/controller/clusters/status.go b/pkg/controller/clusters/status.go index af31607cc7ed..9480b5137315 100644 --- a/pkg/controller/clusters/status.go +++ b/pkg/controller/clusters/status.go @@ -68,21 +68,6 @@ func UpdateClusterStatusForCNI(ctx context.Context, cluster *anywherev1.Cluster) conditions.MarkFalse(cluster, anywherev1.DefaultCNIConfiguredCondition, anywherev1.ControlPlaneNotReadyReason, clusterv1.ConditionSeverityInfo, "") return } - - // Self managed clusters do not use the CNI reconciler, so this status would never get resolved. - // TODO: Remove after self-managed clusters are created with the controller in the CLI - if cluster.IsSelfManaged() { - ciliumCfg := cluster.Spec.ClusterNetwork.CNIConfig.Cilium - // Though it may be installed initially to successfully create the cluster, - // if the CNI is configured to skip upgrades, we mark the condition as "False" - if ciliumCfg != nil && !ciliumCfg.IsManaged() { - conditions.MarkFalse(cluster, anywherev1.DefaultCNIConfiguredCondition, anywherev1.SkipUpgradesForDefaultCNIConfiguredReason, clusterv1.ConditionSeverityWarning, "Configured to skip default Cilium CNI upgrades") - return - } - - // Otherwise, since the control plane is fully ready we can assume the CNI has been configured. - conditions.MarkTrue(cluster, anywherev1.DefaultCNIConfiguredCondition) - } } // updateConditionsForEtcdAndControlPlane updates the ControlPlaneReady condition if etcdadm cluster is not ready. diff --git a/pkg/controller/clusters/status_test.go b/pkg/controller/clusters/status_test.go index d6b05a7a8921..70ce00c84ab9 100644 --- a/pkg/controller/clusters/status_test.go +++ b/pkg/controller/clusters/status_test.go @@ -1045,36 +1045,6 @@ func TestUpdateClusterStatusForCNI(t *testing.T) { Status: "True", }, }, - { - name: "cilium is unmanaged", - skipUpgrade: ptr.Bool(true), - conditions: []anywherev1.Condition{ - { - Type: anywherev1.ControlPlaneReadyCondition, - Status: "True", - }, - }, - wantCondition: &anywherev1.Condition{ - Type: anywherev1.DefaultCNIConfiguredCondition, - Reason: anywherev1.SkipUpgradesForDefaultCNIConfiguredReason, - Status: "False", - Severity: clusterv1.ConditionSeverityWarning, - }, - }, - { - name: "cilium is managed", - skipUpgrade: ptr.Bool(false), - conditions: []anywherev1.Condition{ - { - Type: anywherev1.ControlPlaneReadyCondition, - Status: "True", - }, - }, - wantCondition: &anywherev1.Condition{ - Type: anywherev1.DefaultCNIConfiguredCondition, - Status: "True", - }, - }, } for _, tt := range tests {