openshift / openshift/machine-config-operator

Fix potential panic in getMachineConfigOperatorPod when no pods are returned

Open Beginner friendly
#6,019 4 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

Start in test/extended-priv/util.go at getMachineConfigOperatorPod and inspect how its callers handle the returned error. Verify the helper handles both GetAllPodsWithLabel errors and an empty pod list without indexing pods[0], while still returning the pod name when one is found.

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
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.