Skip to content

Commit

Permalink
Merge pull request #2219 from FabianKramm/my-changes
Browse files Browse the repository at this point in the history
feat: allow wildcard for dns hostname
  • Loading branch information
FabianKramm authored Oct 10, 2024
2 parents cb310cf + ef3afb6 commit 32c9c7f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/config/coredns_plugin_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ func validateMappings(resolveDNS []vclusterconfig.ResolveDNS) error {
}
}
if mapping.Hostname != "" {
if strings.Count(mapping.Hostname, "*") > 1 {
return fmt.Errorf("error validating networking.resolveDNS[%d].hostname: can only contain a maximum of one wildcard, but got %s", i, mapping.Hostname)
} else if strings.Count(mapping.Hostname, "*") == 1 {
if mapping.Target.Hostname == "" {
return fmt.Errorf("error validating networking.resolveDNS[%d].hostname: when using wildcard hostname, target.hostname is required", i)
} else if strings.Count(mapping.Target.Hostname, "*") != 1 {
return fmt.Errorf("error validating networking.resolveDNS[%d].hostname: when using wildcard hostname, target.hostname needs to contain a single wildcard as well", i)
}

if !strings.HasPrefix(mapping.Hostname, "*") && !strings.HasSuffix(mapping.Hostname, "*") {
return fmt.Errorf("error validating networking.resolveDNS[%d].hostname: when using wildcard hostname, needs to be as a suffix or prefix, but got %s", i, mapping.Hostname)
}
}

options++
}
if mapping.Namespace != "" {
Expand Down Expand Up @@ -50,6 +64,12 @@ func validateTarget(target vclusterconfig.ResolveDNSTarget) error {
options := 0
if target.Hostname != "" {
options++

if strings.Count(target.Hostname, "*") > 1 {
return fmt.Errorf("target can only contain a maximum of one wildcard, but got %s", target.Hostname)
} else if strings.Count(target.Hostname, "*") == 1 && !strings.HasPrefix(target.Hostname, "*") && !strings.HasSuffix(target.Hostname, "*") {
return fmt.Errorf("when using wildcard hostname, needs to be as a suffix or prefix, but got %s", target.Hostname)
}
}
if target.IP != "" {
options++
Expand Down

0 comments on commit 32c9c7f

Please sign in to comment.