Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controller: Make ensure conditions consistent #408

Merged
merged 1 commit into from Jun 11, 2020

Conversation

sgreene570
Copy link
Contributor

Switches all ensure functions in pkg/operator/controller/ingress
to use a have boolean rather than manually checking if
!= nil for consistency.

Also makes sure that failed update branches in each ensure<thing> function return the current object, if available, as mentioned in openshift/cluster-dns-operator#176.

@@ -607,7 +607,7 @@ func (r *reconciler) ensureIngressController(ci *operatorv1.IngressController, d
errs = append(errs, err)
}

deployment, err := r.ensureRouterDeployment(ci, infraConfig, ingressConfig, apiConfig, networkConfig)
_, deployment, err := r.ensureRouterDeployment(ci, infraConfig, ingressConfig, apiConfig, networkConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change highlights some questionable logic—it should be verifying that ensureRouterDeployment did indeed return a deployment. Granted, it is unlikely that the deployment would not exist at this point if err is nil (looking at ensureRouterDeployment, the only way both deployment and err could be nil would be if the API let us get or create the deployment in one API call, and then it reported not-found in the following get request), but we shouldn't and needn't assume that it does. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I'm understanding correctly, the way to rectify this problem would be to check that ensureRouterDeployment returns true for it's first return value (rather than ditch the value with _)? Would changing line 611 to if (err != nil || !haveDeployment) { be sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, well line 612 formats an error message with err, which could be null if haveDeployment were false. So it would probably be best to just add another if statement, but I digress.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd add an else if !haveDeployment clause that appended an appropriate error message to errs and returned (to avoid dereferencing a nil deployment further down).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a second instance of this in this PR, which I have also corrected, so thanks!

@sgreene570 sgreene570 force-pushed the boolean-rework branch 3 times, most recently from 27e0154 to b7786e1 Compare June 10, 2020 20:28
errs = append(errs, fmt.Errorf("failed to ensure wildcard dnsrecord for %s: %v", ci.Name, err))
} else if !haveWC {
errs = append(errs, fmt.Errorf("failed to get wildcard dnsrecord for %s", ci.Name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is trickier because the ingresscontroller should always have a deployment, but sometimes it shouldn't have a load-balancer service. In particular, if the ingresscontroller's endpoint publishing strategy type is not "LoadBalancerService", then lbService should be nil here, and given a nil lbService, ensureWildcardDNSRecord should return false, nil, nil. (Further down, we assign record to wildcardRecord and pass the latter to syncIngressControllerStatus, which knows what to do with a nil value.)

I'd suggest that ensureLoadBalancerService should return a Boolean value, and as long as ensureLoadBalancerService returns a nil error value, we should call ensureWildcardDNSRecord and pass it the Boolean value from ensureLoadBalancerService.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my mistake! Your suggestion definitely seems reasonable. I believe I was able to amend this PR properly, but let me know if I missed something again. Thanks! 😃

Switches all ensure<thing> functions in pkg/operator/controller/ingress
to use a have<thing> boolean rather than manually checking if
<thing> != nil for consistency.
@Miciah
Copy link
Contributor

Miciah commented Jun 10, 2020

/lgtm
Thanks!

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Miciah, sgreene570

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 10, 2020
@Miciah
Copy link
Contributor

Miciah commented Jun 11, 2020

e2e-aws-operator failed on TestRouteAdmissionPolicy; the failure is probably not caused by the changes in this PR (see #400).

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

4 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 9edc269 into openshift:master Jun 11, 2020
sgreene570 added a commit to sgreene570/cluster-ingress-operator that referenced this pull request Jun 15, 2020
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` &
`ensureLoadBalancerService` for consistency. Fixes a bug
accidentally introducted in openshift#408.
sgreene570 added a commit to sgreene570/cluster-ingress-operator that referenced this pull request Jun 15, 2020
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` &
`ensureLoadBalancerService` for consistency. Fixes a bug
accidentally introduced in openshift#408.
sgreene570 added a commit to sgreene570/cluster-ingress-operator that referenced this pull request Jun 18, 2020
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` &
`ensureLoadBalancerService` for consistency. Fixes a bug
accidentally introduced in openshift#408.
sgreene570 added a commit to sgreene570/cluster-ingress-operator that referenced this pull request Sep 11, 2020
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` &
`ensureLoadBalancerService` for consistency. Fixes a bug
accidentally introduced in openshift#408.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants