-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Alibaba: fix: destroy the records of the current cluster #5421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
dongchen126:alibabacloud-destroy-records
Dec 10, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1146,19 +1146,14 @@ func (o *ClusterUninstaller) detachPolicy(policyName string, policyType string, | |
|
|
||
| func (o *ClusterUninstaller) deletePrivateZones() (err error) { | ||
| clusterDomain := o.ClusterDomain | ||
| o.Logger.Debug("Start to search private zones") | ||
| zones, err := o.listPrivateZone(clusterDomain) | ||
| zoneID, err := o.getPrivateZoneID() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if len(zones) == 0 { | ||
| if zoneID == "" { | ||
| return nil | ||
| } | ||
| if len(zones) > 1 { | ||
| return errors.Wrap(err, fmt.Sprintf("matched to multiple private zones by clustedomain %q", clusterDomain)) | ||
| } | ||
|
|
||
| zoneID := zones[0].ZoneId | ||
| err = o.bindZoneVpc(zoneID) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -1214,6 +1209,23 @@ func (o *ClusterUninstaller) deletePrivateZones() (err error) { | |
| return nil | ||
| } | ||
|
|
||
| func (o *ClusterUninstaller) getPrivateZoneID() (zoneID string, err error) { | ||
| clusterDomain := o.ClusterDomain | ||
| o.Logger.Debug("Start to search private zones") | ||
| zones, err := o.listPrivateZone(clusterDomain) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if len(zones) == 0 { | ||
| return "", nil | ||
| } | ||
| if len(zones) > 1 { | ||
| return "", errors.Wrap(err, fmt.Sprintf("matched to multiple private zones by clusterdomain %q", clusterDomain)) | ||
| } | ||
|
|
||
| return zones[0].ZoneId, nil | ||
| } | ||
|
|
||
| func (o *ClusterUninstaller) deletePrivateZone(zoneID string) (err error) { | ||
| o.Logger.Debugf("Start to delete private zone %q", zoneID) | ||
| request := pvtz.CreateDeleteZoneRequest() | ||
|
|
@@ -1243,11 +1255,29 @@ func (o *ClusterUninstaller) listPrivateZone(clusterDomain string) ([]pvtz.Zone, | |
| return response.Zones.Zone, nil | ||
| } | ||
|
|
||
| func (o *ClusterUninstaller) listPrivateZoneRecords(zoneID string) ([]pvtz.Record, error) { | ||
| request := pvtz.CreateDescribeZoneRecordsRequest() | ||
| request.Lang = "en" | ||
| request.ZoneId = zoneID | ||
|
|
||
| response, err := o.pvtzClient.DescribeZoneRecords(request) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return response.Records.Record, nil | ||
| } | ||
|
|
||
| func (o *ClusterUninstaller) deleteDNSRecords() (err error) { | ||
| o.Logger.Debug("Start to search DNS records") | ||
|
|
||
| // Get the base domain from the cluster domain. the format of cluster domain is '<cluster name>.<base domain>'. | ||
| baseDomain := strings.Join(strings.Split(o.ClusterDomain, ".")[1:], ".") | ||
| domainParts := strings.Split(o.ClusterDomain, ".") | ||
| if len(domainParts) < 2 { | ||
| return errors.New("could not determine cluster name from cluster domain") | ||
| } | ||
| clusterName := domainParts[0] | ||
| baseDomain := strings.Join(domainParts[1:], ".") | ||
|
|
||
| domains, err := o.listDomain(baseDomain) | ||
| if err != nil { | ||
| return | ||
|
|
@@ -1256,21 +1286,50 @@ func (o *ClusterUninstaller) deleteDNSRecords() (err error) { | |
| return | ||
| } | ||
|
|
||
| records, err := o.listRecord(baseDomain) | ||
| recordSetKey := func(recordType string, rr string) string { | ||
| return fmt.Sprintf("%s %s", recordType, rr) | ||
| } | ||
|
|
||
| // Get the parsing record of privatezone and delete the record in publiczone | ||
| // When the user manually deletes the private zone and records, it may cause the public records to be leaked. | ||
| privateZoneID, err := o.getPrivateZoneID() | ||
| if err != nil { | ||
| return | ||
| } | ||
| if privateZoneID == "" { | ||
| o.Logger.Info("The private zone ID is not obtained, and the DNS public records cannot be deleted") | ||
| return nil | ||
| } | ||
|
|
||
| privateRecords := map[string]bool{} | ||
| records, err := o.listPrivateZoneRecords(privateZoneID) | ||
| if err != nil { | ||
| return | ||
| } | ||
| for _, record := range records { | ||
| key := recordSetKey(record.Type, fmt.Sprintf("%s.%s", record.Rr, clusterName)) | ||
| privateRecords[key] = true | ||
| } | ||
|
|
||
| publicRecords, err := o.listRecord(baseDomain) | ||
| if err != nil { | ||
| return | ||
| } | ||
| if len(records) == 0 { | ||
| if len(publicRecords) == 0 { | ||
| return | ||
| } | ||
|
|
||
| var lastErr error | ||
| o.Logger.Debug("Start to delete DNS records") | ||
| for _, record := range records { | ||
| err = o.deleteRecord(record.RecordId) | ||
| if err != nil { | ||
| err = errors.Wrap(err, fmt.Sprintf("DNS record %q", record.RecordId)) | ||
| o.Logger.Info(err) | ||
| return | ||
| for _, record := range publicRecords { | ||
| key := recordSetKey(record.Type, record.RR) | ||
| if privateRecords[key] { | ||
| err = o.deleteRecord(record.RecordId) | ||
| if err != nil { | ||
| privateRecords[key] = false | ||
| lastErr = errors.Wrap(err, fmt.Sprintf("DNS record %q", record.RecordId)) | ||
| o.Logger.Info(lastErr) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1283,18 +1342,20 @@ func (o *ClusterUninstaller) deleteDNSRecords() (err error) { | |
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| if len(records) == 0 { | ||
| return true, nil | ||
| for _, record := range records { | ||
|
||
| key := recordSetKey(record.Type, record.RR) | ||
| if privateRecords[key] { | ||
| return false, nil | ||
| } | ||
| } | ||
| return false, nil | ||
| return true, nil | ||
| }, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| return lastErr | ||
| } | ||
|
|
||
| func (o *ClusterUninstaller) deleteRecord(recordID string) error { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the alibaba sdk handle paging? Is there a default page size? Or will the sdk return all of the results unless paging is explicitly requested. There could be a lot of records in the base domain zone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default page size is 20, and the SDK will not return all results. If this has caused a problem, I can temporarily increase the page size, such as 50. This is not a good solution, I will create a new PR to add the function of automatically obtaining all paging to
alibabacloud.client.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that the paging issue is limited to just this call. We need to handle the possibility of paging in all of the calls that we make to the SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, yes, let's move that to a separate PR.