Skip to content
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

improve error message for 'no domain matching zones' #158

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pkg/dns/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ func updateDNSProvider(logger logger.LogContext, state *state, provider *dnsutil
return this, this.failed(logger, false, pkgerrors.Wrap(err, "cannot get hosted zones"), true)
}
if len(zones) == 0 {
return this, this.failedButRecheck(logger, fmt.Errorf("no hosted zones available in account"))
empty := utils.StringSet{}
mod := this.object.SetSelection(empty, empty, &this.object.Status().Domains)
mod = this.object.SetSelection(empty, empty, &this.object.Status().Zones) || mod
return this, this.failedButRecheck(logger, fmt.Errorf("no hosted zones available in account"), mod)
}

results := selection.CalcZoneAndDomainSelection(provider.DNSProvider().Spec, toLightZones(zones))
Expand All @@ -402,8 +405,10 @@ func updateDNSProvider(logger logger.LogContext, state *state, provider *dnsutil
for _, warning := range results.Warnings {
this.object.Eventf(corev1.EventTypeWarning, "reconcile", "%s", warning)
}
mod := this.object.SetSelection(this.included, this.excluded, &this.object.Status().Domains)
mod = this.object.SetSelection(this.included_zones, this.excluded_zones, &this.object.Status().Zones) || mod
if results.Error != "" {
return this, this.failedButRecheck(logger, fmt.Errorf(results.Error))
return this, this.failedButRecheck(logger, fmt.Errorf(results.Error), mod)
}

if last == nil || !this.included.Equals(last.included) || !this.excluded.Equals(last.excluded) {
Expand All @@ -425,8 +430,6 @@ func updateDNSProvider(logger logger.LogContext, state *state, provider *dnsutil
}

this.valid = true
mod := this.object.SetSelection(this.included, this.excluded, &this.object.Status().Domains)
mod = this.object.SetSelection(this.included_zones, this.excluded_zones, &this.object.Status().Zones) || mod
return this, this.succeeded(logger, mod)
}

Expand Down Expand Up @@ -528,8 +531,8 @@ func maxDuration(x, y time.Duration) time.Duration {
return x
}

func (this *dnsProviderVersion) failedButRecheck(logger logger.LogContext, err error) reconcile.Status {
uerr := this.setError(false, err)
func (this *dnsProviderVersion) failedButRecheck(logger logger.LogContext, err error, modified bool) reconcile.Status {
uerr := this.setError(modified, err)
if uerr != nil {
logger.Error(err)
if errors.IsConflict(uerr) {
Expand Down
8 changes: 7 additions & 1 deletion pkg/dns/provider/selection/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package selection

import (
"fmt"
"strings"

"github.com/gardener/controller-manager-library/pkg/utils"

Expand Down Expand Up @@ -121,8 +122,13 @@ func CalcZoneAndDomainSelection(spec v1alpha1.DNSProviderSpec, zones []LightDNSH
if len(this.DomainSel.Include) == 0 {
this.ZoneSel.Exclude.AddSet(this.ZoneSel.Include)
this.ZoneSel.Include = utils.NewStringSet()
zoneDomains := []string{}
for _, z := range this.Zones {
zoneDomains = append(zoneDomains, z.Domain())
}
this.Zones = nil
this.Error = "no domain matching hosting zones"
this.Error = fmt.Sprintf("no domain matching hosting zones. Need to be a (sub)domain of [%s]",
strings.Join(zoneDomains, ", "))
return this
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dns/provider/selection/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ var _ = Describe("Selection", func() {
Include: utils.NewStringSet(),
Exclude: utils.NewStringSet(),
},
Error: "no domain matching hosting zones",
Error: "no domain matching hosting zones. Need to be a (sub)domain of [a.b, c.a.b, o.p]",
Warnings: []string{
"domain \"y.z\" not in hosted domains",
},
Expand Down