Skip to content

Commit 82c8aed

Browse files
author
Eduardo Oliveira de Carvalho
committed
Make cleanup idempotent with creation.
Testes were failing because records were being created with quotes and then retrieved for deletion without quotes. The solution was to quote the string on creation and on retrieval for deletion.
1 parent 692a93a commit 82c8aed

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ func (c *designateDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) erro
6363
var opts recordsets.CreateOpts
6464
opts.Name = ch.ResolvedFQDN
6565
opts.Type = "TXT"
66-
if strings.HasPrefix(ch.Key, "\"") {
67-
opts.Records = []string{ch.Key}
68-
} else {
69-
opts.Records = []string{strconv.Quote(ch.Key)}
70-
}
66+
opts.Records = []string{quoteRecord(ch.Key)}
7167

7268
_, err = recordsets.Create(c.client, allZones[0].ID, opts).Extract()
7369
if err != nil {
@@ -101,10 +97,11 @@ func (c *designateDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) erro
10197
recordListOpts := recordsets.ListOpts{
10298
Name: ch.ResolvedFQDN,
10399
Type: "TXT",
104-
Data: ch.Key,
100+
Data: quoteRecord(ch.Key),
105101
}
106102

107103
allRecordPages, err := recordsets.ListByZone(c.client, allZones[0].ID, recordListOpts).AllPages()
104+
108105
if err != nil {
109106
return err
110107
}
@@ -220,3 +217,11 @@ func createDesignateServiceClient() (*gophercloud.ServiceClient, error) {
220217
log.Infof("Found OpenStack Designate service at %s", client.Endpoint)
221218
return client, nil
222219
}
220+
221+
func quoteRecord(r string) string {
222+
if strings.HasPrefix(r, "\"") && strings.HasSuffix(r, "\"") {
223+
return r
224+
} else {
225+
return strconv.Quote(r)
226+
}
227+
}

0 commit comments

Comments
 (0)