Skip to content
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

try to zone one by one #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
kubebuilder/
.idea/
32 changes: 21 additions & 11 deletions alidns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,32 @@ func newClient(region string, cred auth.Credential) (*Client, error) {
return &Client{dnsc: client}, nil
}

func (c *Client) getHostedZone(zone string) (string, error) {
func (c *Client) getHostedZoneByFqdn(fqdn string) (string, error) {
request := alidns.CreateDescribeDomainsRequest()
request.KeyWord = util.UnFqdn(zone)
request.SearchMode = "EXACT"

response, err := c.dnsc.DescribeDomains(request)
if err != nil {
return "", err
}
// in case fqdn is zone
domain := "." + util.UnFqdn(fqdn)
for i := len(domain) - 2; i >= 0; i-- {
if domain[i] != '.' {
continue
}
request.KeyWord = domain[i+1:]
request.SearchMode = "EXACT"

response, err := c.dnsc.DescribeDomains(request)
if err != nil {
return "", err
}

zones := response.Domains.Domain
if len(zones) == 0 {
continue
}

zones := response.Domains.Domain
if len(zones) == 0 {
return "", fmt.Errorf("zone %s does not exist", zone)
return zones[0].DomainName, nil
}

return zones[0].DomainName, nil
return "", fmt.Errorf("cloud not find zone for: %s", fqdn)
}

func (c *Client) addTxtRecord(zone, rr, value string) error {
Expand Down
8 changes: 4 additions & 4 deletions alidns/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (s *Solver) Present(ch *v1alpha1.ChallengeRequest) error {
return err
}

zoneName, err := client.getHostedZone(ch.ResolvedZone)
zoneName, err := client.getHostedZoneByFqdn(ch.ResolvedFQDN)
if err != nil {
klog.Errorf("Get hosted zone %v error: %v", ch.ResolvedZone, err)
klog.Errorf("Get hosted fqdn %v error: %v", ch.ResolvedFQDN, err)
return err
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func (s *Solver) getCredential(cfg *Config, ns string) (*credentials.AccessKeyCr
}

func (s *Solver) getSecretData(selector cmmetav1.SecretKeySelector, ns string) ([]byte, error) {
secret, err := s.client.CoreV1().Secrets(ns).Get(context.TODO(),selector.Name, metav1.GetOptions{})
secret, err := s.client.CoreV1().Secrets(ns).Get(context.TODO(), selector.Name, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "failed to load secret %q", ns+"/"+selector.Name)
}
Expand All @@ -130,7 +130,7 @@ func (s *Solver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
return err
}

zoneName, err := client.getHostedZone(ch.ResolvedZone)
zoneName, err := client.getHostedZoneByFqdn(ch.ResolvedFQDN)
if err != nil {
klog.Errorf("Get hosted zone %v error: %v", ch.ResolvedZone, err)
return err
Expand Down