Skip to content

Commit

Permalink
Skip health check for deployments whose replicas is 0
Browse files Browse the repository at this point in the history
Signed-off-by: zhujian <[email protected]>
  • Loading branch information
zhujian7 committed Oct 19, 2023
1 parent 4c1ce8e commit ed466a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 41 deletions.
4 changes: 4 additions & 0 deletions pkg/addonmanager/controllers/agentdeploy/healthcheck_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func (s *healthCheckSyncer) analyzeDeploymentWorkProber(
deployments := utils.FilterDeployments(manifests)
for _, deployment := range deployments {
manifestConfig := utils.DeploymentWellKnowManifestConfig(deployment.Namespace, deployment.Name)
// only probe the deployment with non-zero replicas
if deployment.Spec.Replicas != nil && *deployment.Spec.Replicas == 0 {
continue
}
probeFields = append(probeFields, agent.ProbeField{
ResourceIdentifier: manifestConfig.ResourceIdentifier,
ProbeRules: manifestConfig.FeedbackRules,
Expand Down
30 changes: 11 additions & 19 deletions pkg/utils/probe_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,22 @@ func DeploymentAvailabilityHealthCheck(identifier workapiv1.ResourceIdentifier,
return fmt.Errorf("unsupported resource group %s", identifier.Group)
}

var readyReplicas, replicas int64 = -1, -1
if len(result.Values) == 0 {
return fmt.Errorf("no values are probed for deployment %s/%s", identifier.Namespace, identifier.Name)
}
for _, value := range result.Values {
if value.Name == "Replicas" {
replicas = *value.Value.Integer
}
if value.Name == "ReadyReplicas" {
readyReplicas = *value.Value.Integer
if value.Name != "ReadyReplicas" {
continue
}
}

if readyReplicas == -1 || replicas == -1 {
return fmt.Errorf("readyReplicas or replicas is not probed for deployment %s/%s",
identifier.Namespace, identifier.Name)
}

if replicas == 0 {
return nil
}
if *value.Value.Integer >= 1 {
return nil
}

if readyReplicas >= 1 {
return nil
return fmt.Errorf("readyReplica is %d for deployment %s/%s",
*value.Value.Integer, identifier.Namespace, identifier.Name)
}

return fmt.Errorf("readyReplica is %d for deployment %s/%s", readyReplicas, identifier.Namespace, identifier.Name)
return fmt.Errorf("readyReplica is not probed")
}

func FilterDeployments(objects []runtime.Object) []*appsv1.Deployment {
Expand Down
24 changes: 2 additions & 22 deletions pkg/utils/probe_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestDeploymentProbe(t *testing.T) {
{
name: "no result",
result: workapiv1.StatusFeedbackResult{},
expectedErr: "readyReplicas or replicas is not probed for deployment testns/test",
expectedErr: "no values are probed for deployment testns/test",
},
{
name: "no matched value",
Expand All @@ -44,7 +44,7 @@ func TestDeploymentProbe(t *testing.T) {
},
},
},
expectedErr: "readyReplicas or replicas is not probed for deployment testns/test",
expectedErr: "readyReplica is not probed",
},
{
name: "check failed with 0 ready replica",
Expand Down Expand Up @@ -86,26 +86,6 @@ func TestDeploymentProbe(t *testing.T) {
},
expectedErr: "",
},
{
name: "check passed when replica is 0",
result: workapiv1.StatusFeedbackResult{
Values: []workapiv1.FeedbackValue{
{
Name: "Replicas",
Value: workapiv1.FieldValue{
Integer: boolPtr(0),
},
},
{
Name: "ReadyReplicas",
Value: workapiv1.FieldValue{
Integer: boolPtr(0),
},
},
},
},
expectedErr: "",
},
}

for _, c := range cases {
Expand Down

0 comments on commit ed466a3

Please sign in to comment.