Skip to content

Fix potential panic in getMachineConfigOperatorPod when no pods are returned #6020

Description

@coderabbitai

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions