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: Rework boolean logic for consistency #176

Conversation

sgreene570
Copy link
Contributor

Switches all ensureDNS<thing> functions in pkg/operator/controller
to use a have<thing> boolean rather than manually checking if
<thing> != nil.

@Miciah mentioned that this is the pattern the cluster-ingress-operator tries to follow, so the cluster-dns-operator should do the same.

Copy link
Contributor

@Miciah Miciah left a comment

Choose a reason for hiding this comment

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

Great cleanup, thanks! I made a couple suggestions in the comments.

}
desired, err := desiredDNSConfigMap(dns, clusterDomain)
if err != nil {
return nil, fmt.Errorf("failed to build configmap: %v", err)
return haveCM, nil, fmt.Errorf("failed to build configmap: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would think this should return return haveCM, current, fmt.Errorf(...).

That said, I grepped for return true, nil, in cluster-ingress-operator and found several matches. However, it makes sense that if we return true (indicating that the resource exists), we should return a non-nil pointer value; would you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would agree. Will update this, good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps some of the return true, nil, ... lines in the cluster-ingress-operator could be cleaned up as well. I'm working a PR for the cluster-ingress-operator similar to this one, so I'll keep that in mind.

pkg/operator/controller/controller_dns_configmap.go Outdated Show resolved Hide resolved
pkg/operator/controller/controller_dns_daemonset.go Outdated Show resolved Hide resolved
pkg/operator/controller/controller_dns_daemonset.go Outdated Show resolved Hide resolved
pkg/operator/controller/controller_dns_service.go Outdated Show resolved Hide resolved
pkg/operator/controller/controller_service_monitor.go Outdated Show resolved Hide resolved
}
logrus.Infof("created dns cluster role: %s/%s", desired.Namespace, desired.Name)
case desired != nil && current != nil:
case haveCR:
if err := r.updateDNSClusterRole(current, desired); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sidenote: A future cleanup could add a Boolean return value to the update methods that don't have one to indicate whether an update was performed. If no update was performed, the caller can return true, current, nil instead of falling through to return r.currentFoo (which incurs an unnecessary API call).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I suspect there are quite a few places that have these extra API calls, not just in the cluster-dns-operator but also in the cluster-ingress-operator, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably, yeah. This is an opportunity to make all of this logic more consistent, correct, and efficient across both operators.

pkg/operator/controller/controller_cluster_role.go Outdated Show resolved Hide resolved
pkg/operator/controller/controller_cluster_role.go Outdated Show resolved Hide resolved
Switches all `ensureDNS<thing>` functions in `pkg/operator/controller`
to use a `have<thing>` boolean rather than manually checking if
`<thing> != nil`.
@sgreene570 sgreene570 force-pushed the boolean-logic-rework-ensure branch from ff375d4 to cded466 Compare June 9, 2020 16:54
@Miciah
Copy link
Contributor

Miciah commented Jun 9, 2020

Thanks!
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 9, 2020
@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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 9, 2020
@openshift-bot
Copy link
Contributor

/retest

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

2 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.

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