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
controller: Make ensure conditions consistent #408
Conversation
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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!
27e0154
to
b7786e1
Compare
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)) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
b7786e1
to
408e341
Compare
/lgtm |
[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 |
e2e-aws-operator failed on |
/retest Please review the full test history for this PR and help us cut down flakes. |
4 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` & `ensureLoadBalancerService` for consistency. Fixes a bug accidentally introducted in openshift#408.
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` & `ensureLoadBalancerService` for consistency. Fixes a bug accidentally introduced in openshift#408.
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` & `ensureLoadBalancerService` for consistency. Fixes a bug accidentally introduced in openshift#408.
Add a `wantFoo` boolean to `ensureWildcardDNSRecord` & `ensureLoadBalancerService` for consistency. Fixes a bug accidentally introduced in openshift#408.
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.