Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #414 from cgag/fix-trailing-dots
Browse files Browse the repository at this point in the history
kube-aws: don't append trailing dot to externalDNSName
  • Loading branch information
colhom committed Apr 15, 2016
2 parents 42fb1bd + 5fec18f commit df7272a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion multi-node/aws/pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (c *Cluster) validateDNSConfig(r53 r53Service) error {

if len(recordSetsResp.ResourceRecordSets) > 0 {
for _, recordSet := range recordSetsResp.ResourceRecordSets {
if *recordSet.Name == c.ExternalDNSName {
if *recordSet.Name == config.WithTrailingDot(c.ExternalDNSName) {
return fmt.Errorf(
"RecordSet for \"%s\" already exists in Hosted Zone \"%s.\"",
c.ExternalDNSName,
Expand Down
2 changes: 1 addition & 1 deletion multi-node/aws/pkg/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ type dummyR53Service struct {
func (r53 dummyR53Service) ListHostedZonesByName(input *route53.ListHostedZonesByNameInput) (*route53.ListHostedZonesByNameOutput, error) {
output := &route53.ListHostedZonesByNameOutput{}
for _, zone := range r53.HostedZones {
if zone.DNS == *input.DNSName {
if zone.DNS == config.WithTrailingDot(*input.DNSName) {
output.HostedZones = append(output.HostedZones, &route53.HostedZone{
Name: aws.String(zone.DNS),
Id: aws.String(zone.Id),
Expand Down
13 changes: 5 additions & 8 deletions multi-node/aws/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ func ClusterFromBytes(data []byte) (*Cluster, error) {
return nil, fmt.Errorf("failed to parse cluster: %v", err)
}

// HostedZone needs to end with a '.'
c.HostedZone = withTrailingDot(c.HostedZone)

// ExternalDNSName doesn't require '.' to be created,
// but adding it here makes validations easier
c.ExternalDNSName = withTrailingDot(c.ExternalDNSName)
// HostedZone needs to end with a '.', amazon will not append it for you.
// as it will with RecordSets
c.HostedZone = WithTrailingDot(c.HostedZone)

if err := c.valid(); err != nil {
return nil, fmt.Errorf("invalid cluster: %v", err)
Expand Down Expand Up @@ -511,7 +508,7 @@ func cidrOverlap(a, b *net.IPNet) bool {
return a.Contains(b.IP) || b.Contains(a.IP)
}

func withTrailingDot(s string) string {
func WithTrailingDot(s string) string {
if s == "" {
return s
}
Expand All @@ -523,7 +520,7 @@ func withTrailingDot(s string) string {
}

func isSubdomain(sub, parent string) bool {
sub, parent = withTrailingDot(sub), withTrailingDot(parent)
sub, parent = WithTrailingDot(sub), WithTrailingDot(parent)
subParts, parentParts := strings.Split(sub, "."), strings.Split(parent, ".")

if len(parentParts) > len(subParts) {
Expand Down

0 comments on commit df7272a

Please sign in to comment.