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

Exoscale provider optimization #4071

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
20 changes: 5 additions & 15 deletions provider/exoscale/exoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
type EgoscaleClientI interface {
ListDNSDomainRecords(context.Context, string, string) ([]egoscale.DNSDomainRecord, error)
ListDNSDomains(context.Context, string) ([]egoscale.DNSDomain, error)
GetDNSDomainRecord(context.Context, string, string, string) (*egoscale.DNSDomainRecord, error)
CreateDNSDomainRecord(context.Context, string, string, *egoscale.DNSDomainRecord) (*egoscale.DNSDomainRecord, error)
DeleteDNSDomainRecord(context.Context, string, string, *egoscale.DNSDomainRecord) error
UpdateDNSDomainRecord(context.Context, string, string, *egoscale.DNSDomainRecord) error
Expand Down Expand Up @@ -160,24 +159,19 @@ func (ep *ExoscaleProvider) ApplyChanges(ctx context.Context, changes *plan.Chan
return err
}

for _, r := range records {
if *r.Name != name {
for _, record := range records {
if *record.Name != name {
continue
}

record, err := ep.client.GetDNSDomainRecord(ctx, ep.apiZone, zoneID, *r.ID)
if err != nil {
return err
}

record.Type = &epoint.RecordType
record.Content = &epoint.Targets[0]
if epoint.RecordTTL != 0 {
ttl := int64(epoint.RecordTTL)
record.TTL = &ttl
}

err = ep.client.UpdateDNSDomainRecord(ctx, ep.apiZone, zoneID, record)
err = ep.client.UpdateDNSDomainRecord(ctx, ep.apiZone, zoneID, &record)
if err != nil {
return err
}
Expand Down Expand Up @@ -240,19 +234,15 @@ func (ep *ExoscaleProvider) Records(ctx context.Context) ([]*endpoint.Endpoint,
return nil, err
}

for _, r := range records {
record, err := ep.client.GetDNSDomainRecord(ctx, ep.apiZone, *domain.ID, *r.ID)
if err != nil {
return nil, err
}
for _, record := range records {
switch *record.Type {
case "A", "CNAME", "TXT":
break
default:
continue
}

e := endpoint.NewEndpointWithTTL((*record.Name)+"."+(*domain.UnicodeName), *record.Type, endpoint.TTL(*r.TTL), *record.Content)
e := endpoint.NewEndpointWithTTL((*record.Name)+"."+(*domain.UnicodeName), *record.Type, endpoint.TTL(*record.TTL), *record.Content)
endpoints = append(endpoints, e)
}
}
Expand Down
12 changes: 0 additions & 12 deletions provider/exoscale/exoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package exoscale

import (
"context"
"errors"
"testing"

egoscale "github.com/exoscale/egoscale/v2"
Expand Down Expand Up @@ -93,17 +92,6 @@ func (ep *ExoscaleClientStub) ListDNSDomainRecords(ctx context.Context, _, domai
return groups[domainID], nil
}

func (ep *ExoscaleClientStub) GetDNSDomainRecord(ctx context.Context, _, domainID, recordID string) (*egoscale.DNSDomainRecord, error) {
group := groups[domainID]
for _, record := range group {
if *record.ID == recordID {
return &record, nil
}
}

return nil, errors.New("not found")
}

func (ep *ExoscaleClientStub) CreateDNSDomainRecord(ctx context.Context, _, domainID string, record *egoscale.DNSDomainRecord) (*egoscale.DNSDomainRecord, error) {
createExoscale = append(createExoscale, createRecordExoscale{domainID: domainID, record: record})
return record, nil
Expand Down
Loading