Skip to content

Commit

Permalink
add new cluster condition: InvalidAPIEnablements
Browse files Browse the repository at this point in the history
Signed-off-by: whitewindmills <[email protected]>
  • Loading branch information
whitewindmills committed Aug 19, 2024
1 parent c757122 commit 1a949d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/cluster/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/controllers/status/cluster_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const (
clusterNotReachableReason = "ClusterNotReachable"
clusterNotReachableMsg = "cluster is not reachable"
statusCollectionFailed = "StatusCollectionFailed"

apiEnablementSyncSucceed = "SyncSucceed"
apiEnablementPartialAPIEnablements = "PartialAPIEnablements"
apiEnablementEmptyAPIEnablements = "EmptyAPIEnablements"
)

var (
Expand Down Expand Up @@ -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(&currentClusterStatus.Conditions, apiEnablementCondition)
currentClusterStatus.APIEnablements = apiEnables

if c.EnableClusterResourceModeling {
Expand Down

0 comments on commit 1a949d8

Please sign in to comment.