-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(coredns): rename ownerId and ownedBy to owner #6032
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
Open
farodin91
wants to merge
1
commit into
kubernetes-sigs:master
Choose a base branch
from
farodin91:rename-owner
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−74
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ type coreDNSClient interface { | |
| type coreDNSProvider struct { | ||
| provider.BaseProvider | ||
| dryRun bool | ||
| strictlyOwned bool | ||
| coreDNSPrefix string | ||
| domainFilter *endpoint.DomainFilter | ||
| client coreDNSClient | ||
|
|
@@ -86,13 +87,13 @@ type Service struct { | |
| // Etcd key where we found this service and ignored from json un-/marshaling | ||
| Key string `json:"-"` | ||
|
|
||
| // OwnedBy is used to prevent service to be added by different external-dns (only used by external-dns) | ||
| OwnedBy string `json:"ownedby,omitempty"` | ||
| // Owner is used to prevent service to be added by different external-dns (only used by external-dns) | ||
| Owner string `json:"owner,omitempty"` | ||
| } | ||
|
|
||
| type etcdClient struct { | ||
| client *etcdcv3.Client | ||
| ownerID string | ||
| owner string | ||
| strictlyOwned bool | ||
| } | ||
|
|
||
|
|
@@ -116,7 +117,7 @@ func (c etcdClient) GetServices(ctx context.Context, prefix string) ([]*Service, | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if c.strictlyOwned && svc.OwnedBy != c.ownerID { | ||
| if c.strictlyOwned && svc.Owner != c.owner { | ||
| continue | ||
| } | ||
| b := Service{ | ||
|
|
@@ -149,7 +150,7 @@ func (c etcdClient) SaveService(ctx context.Context, service *Service) error { | |
| defer cancel() | ||
|
|
||
| // check only for empty OwnedBy | ||
| if c.strictlyOwned && service.OwnedBy != c.ownerID { | ||
| if c.strictlyOwned && service.Owner != c.owner { | ||
| r, err := c.client.Get(ctx, service.Key) | ||
| if err != nil { | ||
| return fmt.Errorf("etcd get %q: %w", service.Key, err) | ||
|
|
@@ -160,11 +161,11 @@ func (c etcdClient) SaveService(ctx context.Context, service *Service) error { | |
| if err != nil { | ||
| return fmt.Errorf("failed to unmarshal value for key %q: %w", service.Key, err) | ||
| } | ||
| if svc.OwnedBy != c.ownerID { | ||
| if svc.Owner != c.owner { | ||
| return fmt.Errorf("key %q is not owned by this provider", service.Key) | ||
| } | ||
| } | ||
| service.OwnedBy = c.ownerID | ||
| service.Owner = c.owner | ||
| } | ||
|
|
||
| value, err := json.Marshal(&service) | ||
|
|
@@ -193,7 +194,7 @@ func (c etcdClient) DeleteService(ctx context.Context, key string) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| if svc.OwnedBy != c.ownerID { | ||
| if svc.Owner != c.owner { | ||
| continue | ||
| } | ||
|
|
||
|
|
@@ -248,7 +249,7 @@ func getETCDConfig() (*etcdcv3.Config, error) { | |
| } | ||
|
|
||
| // the newETCDClient is an etcd client constructor | ||
| func newETCDClient(ownerID string, strictlyOwned bool) (coreDNSClient, error) { | ||
| func newETCDClient(owner string, strictlyOwned bool) (coreDNSClient, error) { | ||
| cfg, err := getETCDConfig() | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -257,19 +258,20 @@ func newETCDClient(ownerID string, strictlyOwned bool) (coreDNSClient, error) { | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return etcdClient{c, ownerID, strictlyOwned}, nil | ||
| return etcdClient{c, owner, strictlyOwned}, nil | ||
| } | ||
|
|
||
| // NewCoreDNSProvider is a CoreDNS provider constructor | ||
| func NewCoreDNSProvider(domainFilter *endpoint.DomainFilter, prefix, ownerID string, strictlyOwned, dryRun bool) (provider.Provider, error) { | ||
| client, err := newETCDClient(ownerID, strictlyOwned) | ||
| func NewCoreDNSProvider(domainFilter *endpoint.DomainFilter, prefix, owner string, strictlyOwned, dryRun bool) (provider.Provider, error) { | ||
| client, err := newETCDClient(owner, strictlyOwned) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return coreDNSProvider{ | ||
| client: client, | ||
| dryRun: dryRun, | ||
| strictlyOwned: strictlyOwned, | ||
| coreDNSPrefix: prefix, | ||
| domainFilter: domainFilter, | ||
| }, nil | ||
|
|
@@ -331,6 +333,9 @@ func (p coreDNSProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err | |
| } | ||
| log.Debugf("Creating new ep (%s) with new service host (%s)", ep, service.Host) | ||
| } | ||
| if p.strictlyOwned { | ||
| ep.Labels[endpoint.OwnerLabelKey] = service.Owner | ||
| } | ||
| ep.Labels["originalText"] = service.Text | ||
| ep.Labels[randomPrefixLabel] = prefix | ||
| ep.Labels[service.Host] = prefix | ||
|
|
@@ -342,6 +347,9 @@ func (p coreDNSProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err | |
| endpoint.RecordTypeTXT, | ||
| service.Text, | ||
| ) | ||
| if p.strictlyOwned { | ||
|
Member
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. same, why if is required? |
||
| ep.Labels[endpoint.OwnerLabelKey] = service.Owner | ||
| } | ||
| ep.Labels[randomPrefixLabel] = prefix | ||
| result = append(result, ep) | ||
| } | ||
|
|
||
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.
not too clear why this if is required