-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(zonefinder): transform zone name to unicode as well #5980
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
| "golang.org/x/sync/errgroup" | ||
|
|
||
| "sigs.k8s.io/external-dns/endpoint" | ||
| "sigs.k8s.io/external-dns/internal/idna" | ||
| "sigs.k8s.io/external-dns/pkg/apis/externaldns" | ||
| "sigs.k8s.io/external-dns/plan" | ||
| "sigs.k8s.io/external-dns/provider" | ||
|
|
@@ -156,43 +157,55 @@ func (p *OVHProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) | |
| return endpoints, nil | ||
| } | ||
|
|
||
| func planChangesByZoneName(zones []string, changes *plan.Changes) map[string]*plan.Changes { | ||
| func planChangesByZoneName(zones []string, changes *plan.Changes) (map[string]*plan.Changes, error) { | ||
| zoneNameIDMapper := provider.ZoneIDName{} | ||
| for _, zone := range zones { | ||
| zoneNameIDMapper.Add(zone, zone) | ||
| } | ||
|
|
||
| output := map[string]*plan.Changes{} | ||
| for _, endpt := range changes.Delete { | ||
| _, zoneName := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| zoneName, _ := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| if zoneName == "" { | ||
| return nil, provider.NewSoftError(fmt.Errorf("record %q have not found matching DNS zone in OVH provider", endpt.DNSName)) | ||
| } | ||
| if _, ok := output[zoneName]; !ok { | ||
| output[zoneName] = &plan.Changes{} | ||
| } | ||
| output[zoneName].Delete = append(output[zoneName].Delete, endpt) | ||
| } | ||
| for _, endpt := range changes.Create { | ||
| _, zoneName := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| zoneName, _ := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| if zoneName == "" { | ||
| return nil, provider.NewSoftError(fmt.Errorf("record %q have not found matching DNS zone in OVH provider", endpt.DNSName)) | ||
|
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 |
||
| } | ||
| if _, ok := output[zoneName]; !ok { | ||
| output[zoneName] = &plan.Changes{} | ||
| } | ||
| output[zoneName].Create = append(output[zoneName].Create, endpt) | ||
| } | ||
| for _, endpt := range changes.UpdateOld { | ||
| _, zoneName := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| zoneName, _ := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| if zoneName == "" { | ||
| return nil, provider.NewSoftError(fmt.Errorf("record %q have not found matching DNS zone in OVH provider", endpt.DNSName)) | ||
|
Contributor
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 NewSoftErrorf |
||
| } | ||
| if _, ok := output[zoneName]; !ok { | ||
| output[zoneName] = &plan.Changes{} | ||
| } | ||
| output[zoneName].UpdateOld = append(output[zoneName].UpdateOld, endpt) | ||
| } | ||
| for _, endpt := range changes.UpdateNew { | ||
| _, zoneName := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| zoneName, _ := zoneNameIDMapper.FindZone(endpt.DNSName) | ||
| if zoneName == "" { | ||
| return nil, provider.NewSoftError(fmt.Errorf("record %q have not found matching DNS zone in OVH provider", endpt.DNSName)) | ||
|
Contributor
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 NewSoftErrorf |
||
| } | ||
| if _, ok := output[zoneName]; !ok { | ||
| output[zoneName] = &plan.Changes{} | ||
| } | ||
| output[zoneName].UpdateNew = append(output[zoneName].UpdateNew, endpt) | ||
| } | ||
|
|
||
| return output | ||
| return output, nil | ||
| } | ||
|
|
||
| func (p *OVHProvider) computeSingleZoneChanges(_ context.Context, zoneName string, existingRecords []ovhRecord, changes *plan.Changes) ([]ovhChange, error) { | ||
|
|
@@ -264,7 +277,10 @@ func (p *OVHProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) e | |
| } | ||
| } | ||
|
|
||
| changesByZoneName := planChangesByZoneName(zones, changes) | ||
| changesByZoneName, err := planChangesByZoneName(zones, changes) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| eg, ctx := errgroup.WithContext(ctx) | ||
|
|
||
| for zoneName, changes := range changesByZoneName { | ||
|
|
@@ -553,6 +569,13 @@ func (p *OVHProvider) newOvhChangeCreateDelete(action int, endpoints []*endpoint | |
| } | ||
|
|
||
| func convertDNSNameIntoSubDomain(DNSName string, zoneName string) string { // nolint: gocritic // captLocal | ||
| if name, err := idna.Profile.ToUnicode(DNSName); err == nil { | ||
|
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. why not to first and only then execute idna normalisation? I have tried func convertDNSNameIntoSubDomain(DNSName string, zoneName string) string { // nolint: gocritic // captLocal
if DNSName == zoneName {
return ""
}
if name, err := idna.Profile.ToUnicode(DNSName); err == nil {
DNSName = name
}
if name, err := idna.Profile.ToUnicode(zoneName); err == nil {
zoneName = name
}
return strings.TrimSuffix(DNSName, "."+zoneName)
}All tests still green, either required a test that will fail or we could do the fastest check first. |
||
| DNSName = name | ||
| } | ||
| if name, err := idna.Profile.ToUnicode(zoneName); err == nil { | ||
| zoneName = name | ||
| } | ||
|
|
||
| if DNSName == zoneName { | ||
| return "" | ||
| } | ||
|
|
||
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.