-
Notifications
You must be signed in to change notification settings - Fork 2.8k
perf(endpoint): optimize ProviderSpecific to use map for O(1) access #5814
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
Closed
u-kai
wants to merge
18
commits into
kubernetes-sigs:master
from
u-kai:refactor/provider-specific-map
+1,280
−737
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
39436ea
refactor: decouple CRD types from internal endpoint package
u-kai 85203ba
perf(endpoint): optimize ProviderSpecific to use map for O(1) access
u-kai 5fdeeba
refactor: use maps package for ProviderSpecific operations
u-kai a8f89fd
add omitempty to DNSEndpointSpec.Endpoints
u-kai bbe0387
refactor(endpoint): remove ProviderSpecific String() methad and fix t…
u-kai 010da28
Merge branch 'master' of https://github.com/kubernetes-sigs/external-…
u-kai 1301503
refactor(crd): move endpoint conversion logic to ToInternal method
u-kai aeeff6f
fix(webhook): maintain backward compatibility for records conversion
u-kai 46bc513
fix(webhook): maintain backward compatibility for adjustEndpoints con…
u-kai 3cbefbf
fix(webhook): maintain backward compatibility for ApplyChanges conver…
u-kai 63dd99d
fix(webhook): improve type conversion and maintain backward compatibi…
u-kai 8d70d35
fix lint
u-kai 061b7ca
add endpoint adapter tests
u-kai c054b37
Merge branch 'master' of https://github.com/kubernetes-sigs/external-…
u-kai b2a6334
fix: resolve merge error
u-kai 92d91e0
add provider specific test coverage
u-kai 17052da
fix and rename endpoint adapter
u-kai 440d865
Merge branch 'master' of https://github.com/kubernetes-sigs/external-…
u-kai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,14 +206,21 @@ func (t Targets) IsLess(o Targets) bool { | |
| return false | ||
| } | ||
|
|
||
| // ProviderSpecificProperty holds the name and value of a configuration which is specific to individual DNS providers | ||
| type ProviderSpecificProperty struct { | ||
| Name string `json:"name,omitempty"` | ||
| Value string `json:"value,omitempty"` | ||
| // ProviderSpecific holds configuration which is specific to individual DNS providers | ||
| type ProviderSpecific map[string]string | ||
|
|
||
| func (ps ProviderSpecific) Set(key, value string) { | ||
| ps[key] = value | ||
| } | ||
|
|
||
| // ProviderSpecific holds configuration which is specific to individual DNS providers | ||
| type ProviderSpecific []ProviderSpecificProperty | ||
| func (ps ProviderSpecific) Get(key string) (string, bool) { | ||
| value, ok := ps[key] | ||
| return value, ok | ||
| } | ||
|
|
||
| func (ps ProviderSpecific) Delete(key string) { | ||
| delete(ps, key) | ||
| } | ||
|
|
||
| // EndpointKey is the type of a map key for separating endpoints or targets. | ||
| type EndpointKey struct { | ||
|
|
@@ -224,7 +231,6 @@ type EndpointKey struct { | |
| } | ||
|
|
||
| // Endpoint is a high-level way of a connection between a service and an IP | ||
| // +kubebuilder:object:generate=true | ||
| type Endpoint struct { | ||
| // The hostname of the DNS record | ||
| DNSName string `json:"dnsName,omitempty"` | ||
|
|
@@ -300,37 +306,26 @@ func (e *Endpoint) WithProviderSpecific(key, value string) *Endpoint { | |
|
|
||
| // GetProviderSpecificProperty returns the value of a ProviderSpecificProperty if the property exists. | ||
| func (e *Endpoint) GetProviderSpecificProperty(key string) (string, bool) { | ||
| for _, providerSpecific := range e.ProviderSpecific { | ||
| if providerSpecific.Name == key { | ||
| return providerSpecific.Value, true | ||
| } | ||
| if e.ProviderSpecific == nil { | ||
| return "", false | ||
| } | ||
| return "", false | ||
| return e.ProviderSpecific.Get(key) | ||
| } | ||
|
|
||
| // SetProviderSpecificProperty sets the value of a ProviderSpecificProperty. | ||
| func (e *Endpoint) SetProviderSpecificProperty(key string, value string) { | ||
| for i, providerSpecific := range e.ProviderSpecific { | ||
| if providerSpecific.Name == key { | ||
| e.ProviderSpecific[i] = ProviderSpecificProperty{ | ||
| Name: key, | ||
| Value: value, | ||
| } | ||
| return | ||
| } | ||
| if e.ProviderSpecific == nil { | ||
| e.ProviderSpecific = make(ProviderSpecific) | ||
| } | ||
|
|
||
| e.ProviderSpecific = append(e.ProviderSpecific, ProviderSpecificProperty{Name: key, Value: value}) | ||
| e.ProviderSpecific.Set(key, value) | ||
| } | ||
|
|
||
| // DeleteProviderSpecificProperty deletes any ProviderSpecificProperty of the specified name. | ||
| func (e *Endpoint) DeleteProviderSpecificProperty(key string) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| for i, providerSpecific := range e.ProviderSpecific { | ||
| if providerSpecific.Name == key { | ||
| e.ProviderSpecific = append(e.ProviderSpecific[:i], e.ProviderSpecific[i+1:]...) | ||
| return | ||
| } | ||
| if e.ProviderSpecific == nil { | ||
| return | ||
| } | ||
| e.ProviderSpecific.Delete(key) | ||
| } | ||
|
|
||
| // WithLabel adds or updates a label for the Endpoint. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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.