diff --git a/pkg/asset/installconfig/gcp/client.go b/pkg/asset/installconfig/gcp/client.go index 937c1632297..61d7cd02b75 100644 --- a/pkg/asset/installconfig/gcp/client.go +++ b/pkg/asset/installconfig/gcp/client.go @@ -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) @@ -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 { diff --git a/pkg/asset/installconfig/gcp/dns.go b/pkg/asset/installconfig/gcp/dns.go index 590c86ab9c3..06f44602931 100644 --- a/pkg/asset/installconfig/gcp/dns.go +++ b/pkg/asset/installconfig/gcp/dns.go @@ -2,9 +2,7 @@ package gcp import ( "context" - "fmt" "sort" - "strings" "time" "github.com/pkg/errors" @@ -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 diff --git a/pkg/asset/installconfig/gcp/validation.go b/pkg/asset/installconfig/gcp/validation.go index 163fb895ab9..f441f14ddcc 100644 --- a/pkg/asset/installconfig/gcp/validation.go +++ b/pkg/asset/installconfig/gcp/validation.go @@ -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) { diff --git a/pkg/asset/installconfig/gcp/validation_test.go b/pkg/asset/installconfig/gcp/validation_test.go index ecc81e07338..f390d81679c 100644 --- a/pkg/asset/installconfig/gcp/validation_test.go +++ b/pkg/asset/installconfig/gcp/validation_test.go @@ -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{