openshift / openshift/machine-config-operator
Fix potential panic in getMachineConfigOperatorPod when no pods are returned
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 269
- Forks
- 529
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 83
Description
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
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
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open test/extended-priv/util.go and inspect getMachineConfigOperatorPod, starting with its GetAllPodsWithLabel call and the pods[0] access. Verify the error and empty-result paths, then confirm the helper returns an error instead of panicking when no pod is found; the related PR and review thread show that this work is already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100