Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/destroy/ibmcloud/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func (o *ClusterUninstaller) deleteDNSRecord(item cloudResource) error {
// destroyDNSRecords removes all DNS record resources that have a name containing
// the cluster's infra ID.
func (o *ClusterUninstaller) destroyDNSRecords() error {
// If CIS CRN is not set, skip DNS records cleanup
if len(o.CISInstanceCRN) == 0 {
o.Logger.Info("Skipping deletion of DNS Records, no CIS CRN found")
return nil
}

found, err := o.listDNSRecords()
if err != nil {
return err
Expand Down
82 changes: 42 additions & 40 deletions pkg/destroy/ibmcloud/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,51 +216,53 @@ func (o *ClusterUninstaller) loadSDKServices() error {
}
o.iamPolicyManagementSvc.Service.SetUserAgent(userAgentString)

// ZonesV1
zAuthenticator, err := icibmcloud.NewIamAuthenticator(apiKey)
if err != nil {
return err
}
o.zonesSvc, err = zonesv1.NewZonesV1(&zonesv1.ZonesV1Options{
Authenticator: zAuthenticator,
Crn: core.StringPtr(o.CISInstanceCRN),
})
if err != nil {
return err
}
o.zonesSvc.Service.SetUserAgent(userAgentString)
if len(o.CISInstanceCRN) > 0 {
// ZonesV1
zAuthenticator, err := icibmcloud.NewIamAuthenticator(apiKey)
if err != nil {
return err
}
o.zonesSvc, err = zonesv1.NewZonesV1(&zonesv1.ZonesV1Options{
Authenticator: zAuthenticator,
Crn: core.StringPtr(o.CISInstanceCRN),
})
if err != nil {
return err
}
o.zonesSvc.Service.SetUserAgent(userAgentString)

// Get the Zone ID
options := o.zonesSvc.NewListZonesOptions()
resources, _, err := o.zonesSvc.ListZonesWithContext(o.Context, options)
if err != nil {
return err
}
// Get the Zone ID
options := o.zonesSvc.NewListZonesOptions()
resources, _, err := o.zonesSvc.ListZonesWithContext(o.Context, options)
if err != nil {
return err
}

zoneID := ""
for _, zone := range resources.Result {
if strings.Contains(o.BaseDomain, *zone.Name) {
zoneID = *zone.ID
zoneID := ""
for _, zone := range resources.Result {
if strings.Contains(o.BaseDomain, *zone.Name) {
zoneID = *zone.ID
}
}
if zoneID == "" || err != nil {
return errors.Errorf("Could not determine DNS zone ID from base domain %q", o.BaseDomain)
}
}
if zoneID == "" || err != nil {
return errors.Errorf("Could not determine DNS zone ID from base domain %q", o.BaseDomain)
}

// DnsRecordsV1
dnsAuthenticator, err := icibmcloud.NewIamAuthenticator(apiKey)
if err != nil {
return err
}
o.dnsRecordsSvc, err = dnsrecordsv1.NewDnsRecordsV1(&dnsrecordsv1.DnsRecordsV1Options{
Authenticator: dnsAuthenticator,
Crn: core.StringPtr(o.CISInstanceCRN),
ZoneIdentifier: core.StringPtr(zoneID),
})
if err != nil {
return err
// DnsRecordsV1
dnsAuthenticator, err := icibmcloud.NewIamAuthenticator(apiKey)
if err != nil {
return err
}
o.dnsRecordsSvc, err = dnsrecordsv1.NewDnsRecordsV1(&dnsrecordsv1.DnsRecordsV1Options{
Authenticator: dnsAuthenticator,
Crn: core.StringPtr(o.CISInstanceCRN),
ZoneIdentifier: core.StringPtr(zoneID),
})
if err != nil {
return err
}
o.dnsRecordsSvc.Service.SetUserAgent(userAgentString)
}
o.dnsRecordsSvc.Service.SetUserAgent(userAgentString)

// VpcV1
vpcAuthenticator, err := icibmcloud.NewIamAuthenticator(apiKey)
Expand Down