Fix potential panic in getMachineConfigOperatorPod when no pods are returned
## Summary
In `test/extended-priv/util.go`, the helper function `getMachineConfigOperatorPod` indexes `pods[0]` before checking whether `exutil.GetAllPodsWithLabel` succeeded or returned any pods. This can cause a runtime panic if the label query errors or returns an empty list.
## Related
- PR: https://github.com/openshift/machine-config-operator/pull/5875
- Review comment: https://github.com/openshift/machine-config-operator/pull/5875#discussion_r3128857555
- Jira: https://redhat.atlassian.net/browse/MCO-2243
- Requested by: @ptalgulk01
## Proposed Fix
```go
func getMachineConfigOperatorPod(oc *exutil.CLI) (string, error) {
pods, err := exutil.GetAllPodsWithLabel(oc.AsAdmin(), MachineConfigNamespace, "k8s-app=machine-config-operator")
if err != nil {
return "", err
}
if len(pods) == 0 {
return "", fmt.Errorf("no machine-config-operator pod found in namespace %s", MachineConfigNamespace)
}
logger.Infof("machine-config-operator pod name is %s", pods[0])
return pods[0], nil
}
```
5 条评论