Skip to content

Commit

Permalink
fix(azure): make the dns resource group optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Nov 27, 2024
1 parent 6b79b86 commit 48524d7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
44 changes: 44 additions & 0 deletions internal/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,50 @@ func (c *Client) GetStorageAccessKeys(ctx context.Context, resourceGroup, storag
}, nil
}

func (c *Client) ListResourceGroups(ctx context.Context) ([]*armresources.ResourceGroup, error) {
client, err := c.newResourceClientFactory()
if err != nil {
return nil, err
}

pager := client.NewResourceGroupsClient().NewListPager(nil)

var groups []*armresources.ResourceGroup

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return nil, fmt.Errorf("failed to list resource groups: %w", err)
}

groups = append(groups, page.Value...)
}

return groups, nil
}

func (c *Client) TestHostedZoneLivenessWildcard(ctx context.Context, domainName string) (bool, *string, error) {
groups, err := c.ListResourceGroups(ctx)
if err != nil {
return false, nil, err
}

// Search through resource groups and return true for first match
for _, resourceGroup := range groups {
name := resourceGroup.Name
hasDomain, err := c.TestHostedZoneLiveness(ctx, domainName, *name)
if err != nil {
return false, nil, err
}

if hasDomain {
return true, name, err
}
}

return false, nil, nil
}

func (c *Client) TestHostedZoneLiveness(ctx context.Context, domainName, resourceGroup string) (bool, error) {
client, err := c.newDNSClientFactory()
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion internal/controller/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
return fmt.Errorf("domain liveness check failed for AWS: %w", err)
}
case "azure":
domainLiveness, err := clctrl.AzureClient.TestHostedZoneLiveness(context.Background(), clctrl.DomainName, clctrl.AzureDNSZoneResourceGroup)
var domainLiveness bool
ctx := context.Background()

if clctrl.AzureDNSZoneResourceGroup == "" {
domainLiveness, _, err = clctrl.AzureClient.TestHostedZoneLivenessWildcard(ctx, clctrl.DomainName)
} else {
domainLiveness, err = clctrl.AzureClient.TestHostedZoneLiveness(ctx, clctrl.DomainName, clctrl.AzureDNSZoneResourceGroup)
}

if err != nil {
return fmt.Errorf("domain liveness command failed for Azure: %w", err)
}
Expand Down

0 comments on commit 48524d7

Please sign in to comment.