Skip to content

Commit

Permalink
checkPodsScheduledForDeployment: Add nil check
Browse files Browse the repository at this point in the history
checkPodsScheduledForDeployment takes a pointer to a deployment, which
should never be nil, so return an error indicating that there is a bug
if the deployment is somehow nil.

* pkg/operator/controller/ingress/status.go
(checkPodsScheduledForDeployment): Check whether deployment is nil and
return an error if it is.
* pkg/operator/controller/ingress/status_test.go
(Test_checkPodsScheduledForDeployment): Add a "nil deployment" test case.
  • Loading branch information
Miciah committed Dec 8, 2022
1 parent dbb5ac8 commit 67b0e92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/operator/controller/ingress/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func computeAllowedSourceRanges(service *corev1.Service) []operatorv1.CIDR {
// PodsScheduled=True. This function returns an error value indicating the
// result of that check.
func checkPodsScheduledForDeployment(deployment *appsv1.Deployment, pods []corev1.Pod) error {
if deployment == nil {
return errors.New("System error detected: deployment was nil. Please report this issue to Red Hat: https://issues.redhat.com/secure/CreateIssueDetails!init.jspa?pid=12332330&issuetype=1&components=12367900&priority=10300&customfield_12316142=26752")
}
selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector)
if err != nil || selector.Empty() {
return errors.New("Deployment has an invalid label selector.")
Expand Down
6 changes: 6 additions & 0 deletions pkg/operator/controller/ingress/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ func Test_checkPodsScheduledForDeployment(t *testing.T) {
pods []corev1.Pod
expectError bool
}{
{
name: "nil deployment",
deployment: nil,
pods: []corev1.Pod{scheduledPod},
expectError: true,
},
{
name: "no pods",
deployment: deployment,
Expand Down

0 comments on commit 67b0e92

Please sign in to comment.