-
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. |
source/annotations/annotations.go
Outdated
const ( | ||
// CloudflareProxiedKey The annotation used for determining if traffic will go through Cloudflare | ||
CloudflareProxiedKey = cloudflare.CloudflareProxiedKey | ||
CloudflareCustomHostnameKey = cloudflare.CloudflareCustomHostnameKey |
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.
Shouldn't cloudflare use the annotations package const?
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.
Changed. Cloudflare annotations defined in annotations package
source/annotations/helpers.go
Outdated
"sigs.k8s.io/external-dns/endpoint" | ||
) | ||
|
||
func getAliasFromAnnotations(annotations map[string]string) bool { |
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.
Get suggests that you get the alias from it, I would say has...
would be more appropriate
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.
Changed
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.
Original code
Line 185 in 277e8ca
func getAliasFromAnnotations(annotations map[string]string) bool { |
} | ||
ttlValue, err := parseTTL(ttlAnnotation) | ||
if err != nil { | ||
log.Warnf("%s: \"%v\" is not a valid TTL value: %v", resource, ttlAnnotation, 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.
IMO it's clearly an error. Warning should have only use of communication deprecations, in my opinion.
Maybe we should decide how we use warnings, because I think during the last couple of months there's a little abuse of warnings.
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.
Link to original code
Lines 91 to 106 in 277e8ca
func getTTLFromAnnotations(annotations map[string]string, resource string) endpoint.TTL { | |
ttlNotConfigured := endpoint.TTL(0) | |
ttlAnnotation, exists := annotations[ttlAnnotationKey] | |
if !exists { | |
return ttlNotConfigured | |
} | |
ttlValue, err := parseTTL(ttlAnnotation) | |
if err != nil { | |
log.Warnf("%s: \"%v\" is not a valid TTL value: %v", resource, ttlAnnotation, err) | |
return ttlNotConfigured | |
} | |
if ttlValue < ttlMinimum || ttlValue > ttlMaximum { | |
log.Warnf("TTL value %q must be between [%d, %d]", ttlValue, ttlMinimum, ttlMaximum) | |
return ttlNotConfigured | |
} | |
return endpoint.TTL(ttlValue) |
And pull commit where change was introduced 17e9637#diff-cf68f602fa7c20e5341f3b83054df68ade1586a144b1eae5347e0ac47096d3aa
The Warning makes to an extend.
- When parseTTL failes, there is a Warning that user should change TTL configuration
- Code uses default values, external-dns works.
- User could fix annotation or configuration when have time, and Warning will disapear
If it's an error;
- the code most likely should throw an error instead of setting up a default
- If there is a mistake in configuration, the external-dns is going to crash or behave differently
I need to capture all cases and provide an update for annotations proposal #5080
It was like that and I would rather keep it as is. In my opinion, I better capture this in annotation graduation proposal. Kind of all annotations should have validations, and validation should either be Error or Warning as example.
// | ||
// Note: for durations like "1.5s" the fraction is omitted (resulting in 1 second | ||
// for the example). | ||
func parseTTL(s string) (ttlSeconds int64, err error) { |
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 define return variables in the signature if you don't use the feature?
Please drop them it's most off the time a code smell.
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.
Will do. I was just moved things around, it was like that.
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.
current master
Line 115 in 277e8ca
func parseTTL(s string) (ttlSeconds int64, err error) { |
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 actually think the error is used on the client.
If an error, provide default
ttlValue, err := parseTTL(ttlAnnotation)
if err != nil {
return ttlNotConfigured
}
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.
Pls suggest what to do. Another option is parseTTLOrDefault
@@ -35,7 +35,10 @@ import ( | |||
"k8s.io/client-go/kubernetes" | |||
"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.
Why rename? It reads simpler if you don't alias the package import here.
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.
Removed antns
. The main reason was - annotations
is quite a common package name in most of the projects.
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.
Example method attributes
Line 247 in 277e8ca
func getTargetsFromTargetAnnotation(annotations map[string]string) endpoint.Targets { |
input
"k8s.io/apimachinery/pkg/labels" | ||
kubeinformers "k8s.io/client-go/informers" | ||
coreinformers "k8s.io/client-go/informers/core/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"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 the whitespace here
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/source.go
Outdated
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
|
||
"sigs.k8s.io/external-dns/endpoint" | ||
|
||
antns "sigs.k8s.io/external-dns/source/annotations" | ||
"sigs.k8s.io/external-dns/source/cloudflare" |
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 should not import cloudflare.
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.
Removed import
source/source.go
Outdated
CloudflareProxiedKey = "external-dns.alpha.kubernetes.io/cloudflare-proxied" | ||
CloudflareCustomHostnameKey = "external-dns.alpha.kubernetes.io/cloudflare-custom-hostname" | ||
// CloudflareProxiedKey The annotation used for determining if traffic will go through Cloudflare | ||
CloudflareProxiedKey = cloudflare.CloudflareProxiedKey |
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 redefining if we can just use the annotations package?
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.
Fixed
[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 |
I think it's a great idea! |
Signed-off-by: ivan katliarchuk <[email protected]>
Probably worth to share once again the motivation of why some of the functions moved to utils. I have a follow-up pull request to address several Istio bugs and add support for v1alpha, v1beta, and v1 versions. While all code could reside in the is not going to be exact folder structure, just an example at the moment |
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