Skip to content

Commit

Permalink
Merge pull request #3601 from abhinavdahiya/gcp_pre_api
Browse files Browse the repository at this point in the history
Bug 1815071: check for api dns record before creating cluster
  • Loading branch information
openshift-merge-robot authored May 14, 2020
2 parents b203d35 + 52586ea commit 11bfe33
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 145 deletions.
2 changes: 1 addition & 1 deletion hack/go-genmock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Example: ./hack/go-genmock.sh

if [ "$IS_CONTAINER" != "" ]; then
go generate ./pkg/... "${@}"
go generate ./pkg/asset/installconfig/... "${@}"
else
podman build -t openshift-install-mock ./images/mock
podman run --rm \
Expand Down
111 changes: 0 additions & 111 deletions pkg/asset/installconfig/gcp/.mock/gcpclient_generated.go

This file was deleted.

30 changes: 27 additions & 3 deletions pkg/asset/installconfig/gcp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import (
"google.golang.org/api/option"
)

//go:generate mockgen -source=./client.go -destination=.mock/gcpclient_generated.go -package=mock
//go:generate mockgen -source=./client.go -destination=./mock/gcpclient_generated.go -package=mock

// API represents the calls made to the API.
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)
}

// Client makes calls to the GCP API.
Expand Down Expand Up @@ -95,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 All @@ -114,6 +117,27 @@ func (c *Client) GetPublicDNSZone(ctx context.Context, project, baseDomain strin
return res, nil
}

// GetRecordSets returns all the records for a DNS zone.
func (c *Client) GetRecordSets(ctx context.Context, project, zone string) ([]*dns.ResourceRecordSet, error) {
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Minute)
defer cancel()

svc, err := c.getDNSService(ctx)
if err != nil {
return nil, err
}

req := svc.ResourceRecordSets.List(project, zone).Context(ctx)
var rrSets []*dns.ResourceRecordSet
if err := req.Pages(ctx, func(page *dns.ResourceRecordSetsListResponse) error {
rrSets = append(rrSets, page.Rrsets...)
return nil
}); err != nil {
return nil, err
}
return rrSets, nil
}

// GetSubnetworks uses the GCP Compute Service API to retrieve all subnetworks in a given network.
func (c *Client) GetSubnetworks(ctx context.Context, network, project, region string) ([]*compute.Subnetwork, error) {
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
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
61 changes: 38 additions & 23 deletions pkg/asset/installconfig/gcp/mock/gcpclient_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 11bfe33

Please sign in to comment.