openshift / openshift/machine-config-operator

Fix potential panic in getMachineConfigOperatorPod when no pods are returned

Open
#6,020 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lifecycle/stale
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

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.