-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
chore(source): code cleanup #5189
base: master
Are you sure you want to change the base?
chore(source): code cleanup #5189
Conversation
Signed-off-by: ivan katliarchuk <[email protected]>
/kind cleanup |
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
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.
Would you please rename source/annotations/annottaions.go to source/annotations/annotations.go ?
Signed-off-by: ivan katliarchuk <[email protected]>
@mloiseleur Done |
/lgtm |
Cool. Let me know if needs further split. Most changes - licence and test coverage. |
Signed-off-by: ivan katliarchuk <[email protected]>
…' into feat-code-cleanup-0 * refs/remotes/origin/feat-code-cleanup-0: fix(cloudflare): custom hostnames edge-cases causing duplicates (kubernetes-sigs#5183) feat(banner): standardize user agent and output (kubernetes-sigs#5154) feat: IDNA awareness in the zone finder (kubernetes-sigs#5147) chore(deps): bump the dev-dependencies group across 1 directory with 20 updates chore(deps): bump renovatebot/github-action feat(chart): Update image to v0.16.1 fix: correct route53 iam chore(deps): bump renovatebot/github-action feat(ovh): major rewriting of the provider (kubernetes-sigs#5143) Add Yandex Cloud Webhook chore(openstack designate)!: remove in-tree provider
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
source/annotations/helpers.go
Outdated
|
||
func hasAliasFromAnnotations(annotations map[string]string) bool { | ||
aliasAnnotation, exists := annotations[AliasKey] | ||
return exists && aliasAnnotation == "true" |
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.
In Go we use "ok" as var name in these cases, please change all of them.
exists
-> ok
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.
done
) | ||
|
||
func TestParseAnnotationFilter(t *testing.T) { | ||
tests := []struct { |
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.
Just FYI, so does not need to be changed: you can also omit the "tests" var and start with the for loop and have an inline struct definition. I think it looks like this (out of my head without parser or compiler):
for _, tt := range []struct{
name string
...
}{
name: "myName",
...
}, {
name: "anotherName",
....
}, {
name: "lastName",
....
}} {
t.Run(tt.name, func(t *testing.T) {
// body
})
}
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.
source/istio_virtualservice.go
Outdated
antns "sigs.k8s.io/external-dns/source/annotations" | ||
|
||
"sigs.k8s.io/external-dns/source/utils" | ||
|
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.
I would drop the whitespaces here and let gofmt/goimports group the imports
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.
done
source/kong_tcpingress.go
Outdated
@@ -36,6 +36,8 @@ import ( | |||
"k8s.io/client-go/kubernetes/scheme" | |||
"k8s.io/client-go/tools/cache" | |||
|
|||
antns "sigs.k8s.io/external-dns/source/annotations" | |||
|
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.
drop whitespace
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.
done
source/utils/helpers.go
Outdated
|
||
services, err := svcInformer.Lister().Services(namespace).List(labels.Everything()) | ||
if err != nil { | ||
log.Errorf("not able to list labels for services in namespace %s. %v", namespace, err) |
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.
We could omit the log and log only in the caller or change the error log to a proper style:
"Failed to .." is a good prefix for error logs.
Example:
log.Errorf("Failed to list labels for services in namespace %q: %v", namespace, err)
or return error:
return fmt.Errorf("failed to list labels for services in namespace %q: %w", namespace, err)
I would prefer return the error and drop the log, because of imports.
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.
done
Signed-off-by: ivan katliarchuk <[email protected]>
* master: docs(proposal): externaldns api graduation to beta (kubernetes-sigs#5079) chore(code-cleanup): move logic away from main.go add tests (kubernetes-sigs#5222) chore(deps): bump the dev-dependencies group across 1 directory with 17 updates chore: add se for nlb, alb in thailand region fix(node): logger test fixed (kubernetes-sigs#5232) fix(chart): add missing types for empty values (kubernetes-sigs#5207) docs: Fix typo: grcp → grpc. removing reduntant code renaming variable added new tests to handle edge case detailed documentation with no-expose added warn log edited docs and made new test docs: added documentation in node source fix: fixing ci lint fix: removing fmt.Printf feat: added expose internal ipv6 flag
Signed-off-by: ivan katliarchuk <[email protected]>
rebased with master. just to make sure latest changes do not break anything |
I'd also love to see the name "utils" go away, a relatively known blogpost on the topic: https://dave.cheney.net/2019/01/08/avoid-package-names-like-base-util-or-common |
@Raffo do you mean to move everything back from utils to source.go? |
If the only user is in source package you can put it in source/util.go |
Ok. I give it a try |
Yeah what I really don't like is having a generic package that is called utils. It basically tells nothing about what it is supposed to do and it often becomes a bag with everything inside. I know kubernetes has adopted patterns like util and hack and so on, but those patterns are IMO pretty bad and I don't think we have to copy them only because the kube core contributors 10 years ago went with similar decisions. |
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Signed-off-by: ivan katliarchuk <[email protected]>
Description
No changes to business logic. Slicing this pull request #5186.
Moved few methods to shared/utils folder, added code re-use in some services. Increased code coverage for moved functions.
Target is to support for istio
support v1alpha3 and v1
. draft pull request is here gofogo#10Checklist