Skip to content

Commit

Permalink
installconfig/gcp: fix the GetPublicZone api definition to match the …
Browse files Browse the repository at this point in the history
…actual impl
  • Loading branch information
abhinavdahiya committed May 14, 2020
1 parent ed69403 commit 52586ea
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
6 changes: 4 additions & 2 deletions pkg/asset/installconfig/gcp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type API interface {
GetNetwork(ctx context.Context, network, project string) (*compute.Network, error)
GetPublicDomains(ctx context.Context, project string) ([]string, error)
GetPublicDNSZone(ctx context.Context, baseDomain, project string) (*dns.ManagedZone, error)
GetPublicDNSZone(ctx context.Context, project, baseDomain string) (*dns.ManagedZone, error)
GetSubnetworks(ctx context.Context, network, project, region string) ([]*compute.Subnetwork, error)
GetProjects(ctx context.Context) (map[string]string, error)
GetRecordSets(ctx context.Context, project, zone string) ([]*dns.ResourceRecordSet, error)
Expand Down Expand Up @@ -96,7 +96,9 @@ func (c *Client) GetPublicDNSZone(ctx context.Context, project, baseDomain strin
if err != nil {
return nil, err
}

if !strings.HasSuffix(baseDomain, ".") {
baseDomain = fmt.Sprintf("%s.", baseDomain)
}
req := svc.ManagedZones.List(project).DnsName(baseDomain).Context(ctx)
var res *dns.ManagedZone
if err := req.Pages(ctx, func(page *dns.ManagedZonesListResponse) error {
Expand Down
6 changes: 0 additions & 6 deletions pkg/asset/installconfig/gcp/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package gcp

import (
"context"
"fmt"
"sort"
"strings"
"time"

"github.com/pkg/errors"
Expand All @@ -23,10 +21,6 @@ func GetPublicZone(ctx context.Context, project, baseDomain string) (*dns.Manage
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

if !strings.HasSuffix(baseDomain, ".") {
baseDomain = fmt.Sprintf("%s.", baseDomain)
}

dnsZone, err := client.GetPublicDNSZone(ctx, project, baseDomain)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/gcp/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func ValidatePreExitingPublicDNS(client API, ic *types.InstallConfig) error {

record := fmt.Sprintf("api.%s.", strings.TrimSuffix(ic.ClusterDomain(), "."))

zone, err := client.GetPublicDNSZone(context.TODO(), ic.BaseDomain, ic.Platform.GCP.ProjectID)
zone, err := client.GetPublicDNSZone(context.TODO(), ic.Platform.GCP.ProjectID, ic.BaseDomain)
if err != nil {
var gErr *googleapi.Error
if errors.As(err, &gErr) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/gcp/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestValidatePreExitingPublicDNS(t *testing.T) {
defer mockCtrl.Finish()
gcpClient := mock.NewMockAPI(mockCtrl)

gcpClient.EXPECT().GetPublicDNSZone(gomock.Any(), "base-domain", "project-id").Return(&dns.ManagedZone{Name: "zone-name"}, nil).AnyTimes()
gcpClient.EXPECT().GetPublicDNSZone(gomock.Any(), "project-id", "base-domain").Return(&dns.ManagedZone{Name: "zone-name"}, nil).AnyTimes()
gcpClient.EXPECT().GetRecordSets(gomock.Any(), gomock.Eq("project-id"), gomock.Eq("zone-name")).Return(test.records, nil).AnyTimes()

err := ValidatePreExitingPublicDNS(gcpClient, &types.InstallConfig{
Expand Down

0 comments on commit 52586ea

Please sign in to comment.