Skip to content

Commit

Permalink
fix: Ensure that cluster_state_synced metric gets set if function exi…
Browse files Browse the repository at this point in the history
…ts early (#1011)
  • Loading branch information
jonathan-innis authored Feb 15, 2024
1 parent 0a5e3ce commit 0c41181
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/controllers/state/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func NewCluster(clk clock.Clock, client client.Client, cp cloudprovider.CloudPro
// utilizing the cluster state as our source of truth
//
//nolint:gocyclo
func (c *Cluster) Synced(ctx context.Context) bool {
func (c *Cluster) Synced(ctx context.Context) (synced bool) {
// Set the metric to whatever the result of the Synced() call is
defer func() {
clusterStateSynced.Set(lo.Ternary[float64](synced, 1, 0))
}()
nodeClaimList := &v1beta1.NodeClaimList{}
if err := c.kubeClient.List(ctx, nodeClaimList); err != nil {
logging.FromContext(ctx).Errorf("checking cluster state sync, %v", err)
Expand Down Expand Up @@ -123,9 +127,7 @@ func (c *Cluster) Synced(ctx context.Context) bool {
// This doesn't ensure that the two states are exactly aligned (we could still not be tracking a node
// that exists in the cluster state but not in the apiserver) but it ensures that we have a state
// representation for every node/nodeClaim that exists on the apiserver
synced := stateNodeClaimNames.IsSuperset(nodeClaimNames) && stateNodeNames.IsSuperset(nodeNames)
clusterStateSynced.Set(lo.Ternary[float64](synced, 1, 0))
return synced
return stateNodeClaimNames.IsSuperset(nodeClaimNames) && stateNodeNames.IsSuperset(nodeNames)
}

// ForPodsWithAntiAffinity calls the supplied function once for each pod with required anti affinity terms that is
Expand Down

0 comments on commit 0c41181

Please sign in to comment.