From 1a949d830d37dac974cdd253ffca50847f0e3eb9 Mon Sep 17 00:00:00 2001 From: whitewindmills Date: Mon, 19 Aug 2024 18:04:53 +0800 Subject: [PATCH] add new cluster condition: InvalidAPIEnablements Signed-off-by: whitewindmills --- pkg/apis/cluster/v1alpha1/types.go | 4 ++++ pkg/controllers/status/cluster_status_controller.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/apis/cluster/v1alpha1/types.go b/pkg/apis/cluster/v1alpha1/types.go index 29cfc61da0fc..aa98eccaeeab 100644 --- a/pkg/apis/cluster/v1alpha1/types.go +++ b/pkg/apis/cluster/v1alpha1/types.go @@ -278,6 +278,10 @@ type LocalSecretReference struct { const ( // ClusterConditionReady means the cluster is healthy and ready to accept workloads. ClusterConditionReady = "Ready" + + // ClusterConditionInvalidAPIEnablements means the cluster's APIEnablements are invalid. + // This condition usually occurs when the APIEnablements are not successfully collected. + ClusterConditionInvalidAPIEnablements = "InvalidAPIEnablements" ) // ClusterStatus contains information about the current status of a diff --git a/pkg/controllers/status/cluster_status_controller.go b/pkg/controllers/status/cluster_status_controller.go index 77f79aef3535..efaf427bacd7 100644 --- a/pkg/controllers/status/cluster_status_controller.go +++ b/pkg/controllers/status/cluster_status_controller.go @@ -67,6 +67,10 @@ const ( clusterNotReachableReason = "ClusterNotReachable" clusterNotReachableMsg = "cluster is not reachable" statusCollectionFailed = "StatusCollectionFailed" + + apiEnablementSyncSucceed = "SyncSucceed" + apiEnablementPartialAPIEnablements = "PartialAPIEnablements" + apiEnablementEmptyAPIEnablements = "EmptyAPIEnablements" ) var ( @@ -229,13 +233,22 @@ func (c *ClusterStatusController) setCurrentClusterStatus(clusterClient *util.Cl } currentClusterStatus.KubernetesVersion = clusterVersion + var apiEnablementCondition metav1.Condition // get the list of APIs installed in the member cluster apiEnables, err := getAPIEnablements(clusterClient) if len(apiEnables) == 0 { + apiEnablementCondition = util.NewCondition(clusterv1alpha1.ClusterConditionInvalidAPIEnablements, + apiEnablementEmptyAPIEnablements, "collected empty APIEnablements from the cluster", metav1.ConditionTrue) klog.Errorf("Failed to get any APIs installed in Cluster %s. Error: %v.", cluster.GetName(), err) } else if err != nil { + apiEnablementCondition = util.NewCondition(clusterv1alpha1.ClusterConditionInvalidAPIEnablements, + apiEnablementPartialAPIEnablements, fmt.Sprintf("might collect partial APIEnablements(%d) from the cluster", len(apiEnables)), metav1.ConditionTrue) klog.Warningf("Maybe get partial(%d) APIs installed in Cluster %s. Error: %v.", len(apiEnables), cluster.GetName(), err) + } else { + apiEnablementCondition = util.NewCondition(clusterv1alpha1.ClusterConditionInvalidAPIEnablements, + apiEnablementSyncSucceed, "collected full APIEnablements from the cluster", metav1.ConditionFalse) } + meta.SetStatusCondition(¤tClusterStatus.Conditions, apiEnablementCondition) currentClusterStatus.APIEnablements = apiEnables if c.EnableClusterResourceModeling {