-
Notifications
You must be signed in to change notification settings - Fork 51
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
pkg/components: Refactor to reduce duplicate code #1845
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
var rules []rbacv1.PolicyRule | ||
|
||
rules = append(rules, | ||
newPolicyRule([]string{""}, []string{"events"}, []string{"update"}), |
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.
wdyt about this ?
easier to read imo please
newPolicyRule(
[]string{""},
[]string{"events"},
[]string{"update"}
),
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.
ouch sonar is not happy from that
i guess we dont have a choice
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.
tried: duplicity went up 18%
perhaps we could use new line only on lines that are too long?
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.
either that, or just revert to the initial please (better imo)
whatever you prefer
thanks
beside cosmetics there are no changes right ? |
It's only a refactor. No logic changed. |
pkg/components/components.go
Outdated
var rules []rbacv1.PolicyRule | ||
|
||
rules = append(rules, | ||
newPolicyRule([]string{"apps"}, []string{"daemonsets"}, []string{"get", "create", "update", "delete"}), | ||
newPolicyRule([]string{""}, []string{"configmaps"}, []string{"get", "create", "update"}), | ||
newPolicyRule([]string{"apps"}, []string{"deployments"}, []string{"delete"}), | ||
newPolicyRule([]string{""}, []string{"namespaces"}, []string{"update", "get", "patch"}), | ||
newPolicyRule([]string{""}, []string{"serviceaccounts"}, []string{"get", "create", "update", "delete"}), | ||
newPolicyRule([]string{"monitoring.coreos.com"}, []string{"prometheusrules", "servicemonitors"}, []string{"get", "create", "update", "delete"}), | ||
newPolicyRule([]string{"rbac.authorization.k8s.io"}, []string{"roles", "rolebindings"}, []string{"get", "create", "update", "delete"}), | ||
newPolicyRule([]string{"policy"}, []string{"poddisruptionbudgets"}, []string{"get", "delete"}), | ||
newPolicyRule([]string{""}, []string{"configmaps"}, []string{"patch"}), | ||
newPolicyRule([]string{"coordination.k8s.io"}, []string{"leases"}, []string{"get", "list", "watch", "create", "update", "patch", "delete"}), | ||
newPolicyRule([]string{"cert-manager.io"}, []string{"certificates", "issuers"}, []string{"get", "create", "update", "delete"}), | ||
) |
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.
why using append
? append
is pricey. I think you can initialize the slice with the required data; e.g.
var rules []rbacv1.PolicyRule | |
rules = append(rules, | |
newPolicyRule([]string{"apps"}, []string{"daemonsets"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{""}, []string{"configmaps"}, []string{"get", "create", "update"}), | |
newPolicyRule([]string{"apps"}, []string{"deployments"}, []string{"delete"}), | |
newPolicyRule([]string{""}, []string{"namespaces"}, []string{"update", "get", "patch"}), | |
newPolicyRule([]string{""}, []string{"serviceaccounts"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{"monitoring.coreos.com"}, []string{"prometheusrules", "servicemonitors"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{"rbac.authorization.k8s.io"}, []string{"roles", "rolebindings"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{"policy"}, []string{"poddisruptionbudgets"}, []string{"get", "delete"}), | |
newPolicyRule([]string{""}, []string{"configmaps"}, []string{"patch"}), | |
newPolicyRule([]string{"coordination.k8s.io"}, []string{"leases"}, []string{"get", "list", "watch", "create", "update", "patch", "delete"}), | |
newPolicyRule([]string{"cert-manager.io"}, []string{"certificates", "issuers"}, []string{"get", "create", "update", "delete"}), | |
) | |
rules := []rbacv1.PolicyRule{ | |
newPolicyRule([]string{"apps"}, []string{"daemonsets"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{""}, []string{"configmaps"}, []string{"get", "create", "update"}), | |
newPolicyRule([]string{"apps"}, []string{"deployments"}, []string{"delete"}), | |
newPolicyRule([]string{""}, []string{"namespaces"}, []string{"update", "get", "patch"}), | |
newPolicyRule([]string{""}, []string{"serviceaccounts"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{"monitoring.coreos.com"}, []string{"prometheusrules", "servicemonitors"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{"rbac.authorization.k8s.io"}, []string{"roles", "rolebindings"}, []string{"get", "create", "update", "delete"}), | |
newPolicyRule([]string{"policy"}, []string{"poddisruptionbudgets"}, []string{"get", "delete"}), | |
newPolicyRule([]string{""}, []string{"configmaps"}, []string{"patch"}), | |
newPolicyRule([]string{"coordination.k8s.io"}, []string{"leases"}, []string{"get", "list", "watch", "create", "update", "patch", "delete"}), | |
newPolicyRule([]string{"cert-manager.io"}, []string{"certificates", "issuers"}, []string{"get", "create", "update", "delete"}), | |
} |
pkg/components/components.go
Outdated
} | ||
return role | ||
} | ||
|
||
func GetClusterRole(allowMultus bool) *rbacv1.ClusterRole { | ||
var rules []rbacv1.PolicyRule |
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.
same
pkg/components/components.go
Outdated
var rules []rbacv1.PolicyRule | ||
|
||
rules = append(rules, |
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.
same
5d31b26
to
6896c42
Compare
6896c42
to
968a49b
Compare
/hold |
if any are left out, tests should find it, or we are missing tests, or those arent needed anymore |
you didnt rebase correctly, please check it Those need to be included please: |
thanks! |
968a49b
to
cc6fe21
Compare
Quality Gate passedIssues Measures |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with /lifecycle stale |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with /lifecycle rotten |
This is done in order to eliminate sonarCloud issue. Signed-off-by: Ram Lavi <[email protected]>
cc6fe21
to
519dec3
Compare
Quality Gate passedIssues Measures |
Change: Rebase |
nice catch! - fixed. PTAL |
/hold cancel |
/remove-lifecycle rotten |
@RamLavi: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What this PR does / why we need it:
currently sonarCloud reports a lot of code is duplicate on pkg/components (37.6%).
Refactoring the code to reduce duplicate to 0% and make thing more clear (all policies are visible in one screen, no endless scrolling).
Special notes for your reviewer:
Release note: