Skip to content

Commit 5f66369

Browse files
author
Jeff McCormick
authored
add logic to have the scorecard created pod wait till all the contain… (#1921)
* add logic to have the scorecard created pod wait till all the containers are in a Running status * Update internal/pkg/scorecard/plugins/resource_handler.go Co-Authored-By: Joe Lanford <[email protected]> * refactored the getPodFromDeployment() function a bit to be easier to read
1 parent a4b4945 commit 5f66369

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

internal/pkg/scorecard/plugins/resource_handler.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,33 @@ func getPodFromDeployment(depName, namespace string) (pod *v1.Pod, err error) {
177177
if err != nil {
178178
return false, fmt.Errorf("failed to get list of pods in deployment: %v", err)
179179
}
180-
// Make sure the pods exist. There should only be 1 pod per deployment.
181-
if len(pods.Items) == 1 {
182-
// If the pod has a deletion timestamp, it is the old pod; wait for
183-
// pod with no deletion timestamp
184-
if pods.Items[0].GetDeletionTimestamp() == nil {
185-
pod = &pods.Items[0]
186-
return true, nil
187-
}
188-
} else {
180+
181+
// Make sure the pod exist.
182+
if len(pods.Items) == 0 {
183+
return false, nil
184+
}
185+
186+
// There should only be 1 pod per deployment.
187+
if len(pods.Items) > 1 {
189188
log.Debug("Operator deployment has more than 1 pod")
189+
return false, nil
190190
}
191-
return false, nil
191+
192+
// If the pod has a deletion timestamp, it is the old pod; wait for
193+
// pod with no deletion timestamp
194+
if pods.Items[0].GetDeletionTimestamp() != nil {
195+
return false, nil
196+
}
197+
198+
// Make sure all containers are Running
199+
for _, containerStatus := range pods.Items[0].Status.ContainerStatuses {
200+
if containerStatus.State.Running == nil {
201+
return false, nil
202+
}
203+
}
204+
205+
pod = &pods.Items[0]
206+
return true, nil
192207
})
193208
if err != nil {
194209
return nil, fmt.Errorf("failed to get proxyPod: %s", err)

0 commit comments

Comments
 (0)