Skip to content

Commit

Permalink
entry metric + improve handling for non-matchind provider includes
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Apr 3, 2019
1 parent 7115732 commit c8e6d88
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 81 deletions.
8 changes: 7 additions & 1 deletion pkg/controller/provider/alicloud/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func NewHandler(logger logger.LogContext, config *provider.DNSHandlerConfig, met
return this, nil
}

func (h *Handler) ProviderType() string {
return TYPE_CODE
}

func (this *Handler) GetZones() (provider.DNSHostedZones, error) {
raw := []alidns.Domain{}
{
Expand Down Expand Up @@ -86,7 +90,9 @@ func (this *Handler) GetZones() (provider.DNSHostedZones, error) {
if err != nil {
return nil, err
}
hostedZone := provider.NewDNSHostedZone(z.DomainId, z.DomainName, z.DomainName, forwarded)
hostedZone := provider.NewDNSHostedZone(
this.ProviderType(), z.DomainId,
z.DomainName, z.DomainName, forwarded)
zones = append(zones, hostedZone)
}
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/provider/aws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func NewHandler(logger logger.LogContext, config *provider.DNSHandlerConfig, met
return this, nil
}

func (h *Handler) ProviderType() string {
return TYPE_CODE
}

func (this *Handler) GetZones() (provider.DNSHostedZones, error) {
rt := provider.M_LISTZONES
raw := []*route53.HostedZone{}
Expand Down Expand Up @@ -101,7 +105,7 @@ func (this *Handler) GetZones() (provider.DNSHostedZones, error) {
}
this.handleRecordSets(id, aggr)

hostedZone := provider.NewDNSHostedZone(
hostedZone := provider.NewDNSHostedZone(this.ProviderType(),
id, dns.NormalizeHostname(domain), aws.StringValue(z.Id), forwarded)
zones = append(zones, hostedZone)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/provider/azure/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func NewHandler(logger logger.LogContext, config *provider.DNSHandlerConfig, met

var re = regexp.MustCompile("/resourceGroups/([^/]+)/")

func (h *Handler) ProviderType() string {
return TYPE_CODE
}

func (h *Handler) GetZones() (provider.DNSHostedZones, error) {
zones := provider.DNSHostedZones{}

Expand All @@ -115,6 +119,7 @@ func (h *Handler) GetZones() (provider.DNSHostedZones, error) {

// ResourceGroup needed for requests to Azure. Remember by adding to Id. Split by calling splitZoneid().
hostedZone := provider.NewDNSHostedZone(
h.ProviderType(),
resourceGroup+"/"+*item.Name,
dns.NormalizeHostname(*item.Name),
"",
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/provider/google/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func NewHandler(logger logger.LogContext, config *provider.DNSHandlerConfig, met
return this, nil
}

func (h *Handler) ProviderType() string {
return TYPE_CODE
}

func (this *Handler) GetZones() (provider.DNSHostedZones, error) {
rt := provider.M_LISTZONES
raw := []*googledns.ManagedZone{}
Expand Down Expand Up @@ -108,7 +112,7 @@ func (this *Handler) GetZones() (provider.DNSHostedZones, error) {
}
}
this.handleRecordSets(z.Name, f)
hostedZone := provider.NewDNSHostedZone(
hostedZone := provider.NewDNSHostedZone(this.ProviderType(),
z.Name, dns.NormalizeHostname(z.DnsName), "", forwarded)
zones = append(zones, hostedZone)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/provider/openstack/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ func readAuthConfig(config *provider.DNSHandlerConfig) (*authConfig, error) {
return &authConfig, nil
}

func (h *Handler) ProviderType() string {
return TYPE_CODE
}

func (h *Handler) GetZones() (provider.DNSHostedZones, error) {
hostedZones := provider.DNSHostedZones{}

zoneHandler := func(zone *zones.Zone) error {
forwarded := h.collectForwardedSubzones(zone)

hostedZone := provider.NewDNSHostedZone(
h.ProviderType(),
zone.ID,
dns.NormalizeHostname(zone.Name),
"",
Expand Down
11 changes: 9 additions & 2 deletions pkg/dns/provider/changemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ func (this *ChangeGroup) cleanup(logger logger.LogContext, model *ChangeModel) b
if !ok {
if s.IsOwnedBy(model.owners) {
if e := model.IsStale(s.Name); e != nil {
model.Infof("found stale set '%s' -> preserve unchanged", s.Name)
e.UpdateStatus(logger, v1alpha1.STATE_STALE, "errornous entry presevered in provider", nil)
status := e.object.Status()
msg := MSG_PRESERVED
if status.State == v1alpha1.STATE_ERROR || status.State == v1alpha1.STATE_INVALID {
msg = msg + ": " + utils.StringValue(status.Message)
model.Infof("found stale set '%s': %s -> preserve unchanged", utils.StringValue(status.Message), s.Name)
} else {
model.Infof("found stale set '%s' -> preserve unchanged", s.Name)
}
e.UpdateStatus(logger, v1alpha1.STATE_STALE, msg, nil)
} else {
model.Infof("found unapplied managed set '%s'", s.Name)
for ty := range s.Sets {
Expand Down
17 changes: 11 additions & 6 deletions pkg/dns/provider/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ func NewDNSZoneState(sets dns.DNSSets) DNSZoneState {
////////////////////////////////////////////////////////////////////////////////

type DefaultDNSHostedZone struct {
id string // identifying id for provider api
domain string // base domain for zone
forwarded []string // forwarded sub domains
key string // internal key used by provider (not used by this lib)
providerType string // provider type
id string // identifying id for provider api
domain string // base domain for zone
forwarded []string // forwarded sub domains
key string // internal key used by provider (not used by this lib)
}

func (this *DefaultDNSHostedZone) Key() string {
Expand All @@ -52,6 +53,10 @@ func (this *DefaultDNSHostedZone) Key() string {
return this.id
}

func (this *DefaultDNSHostedZone) ProviderType() string {
return this.providerType
}

func (this *DefaultDNSHostedZone) Id() string {
return this.id
}
Expand All @@ -64,6 +69,6 @@ func (this *DefaultDNSHostedZone) ForwardedDomains() []string {
return this.forwarded
}

func NewDNSHostedZone(id, domain, key string, forwarded []string) DNSHostedZone {
return &DefaultDNSHostedZone{id: id, key: key, domain: domain, forwarded: forwarded}
func NewDNSHostedZone(ptype string, id, domain, key string, forwarded []string) DNSHostedZone {
return &DefaultDNSHostedZone{providerType: ptype, id: id, key: key, domain: domain, forwarded: forwarded}
}
17 changes: 13 additions & 4 deletions pkg/dns/provider/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
corev1 "k8s.io/api/core/v1"
)

const MSG_PRESERVED = "errornous entry preserved in provider"

type Entry struct {
lock sync.Mutex
object *dnsutils.DNSEntryObject
Expand Down Expand Up @@ -240,8 +242,7 @@ func (this *Entry) Update(logger logger.LogContext, state *state, op string, own
}

if utils.StringValue(status.ProviderType) != resp {
err = state.RemoveFinalizer(object)
return reconcile.RepeatOnError(logger, err)
return reconcile.RepeatOnError(logger, state.RemoveFinalizer(object))
}

logger.Infof("%s ENTRY", op)
Expand Down Expand Up @@ -327,8 +328,16 @@ func (this *Entry) Update(logger logger.LogContext, state *state, op string, own
}
mod.AssureStringPtrValue(&status.Zone, zoneid)
if err != nil {
mod.AssureStringValue(&status.State, api.STATE_ERROR)
mod.AssureStringPtrValue(&status.Message, err.Error())
if status.State != api.STATE_STALE {
mod.AssureStringValue(&status.State, api.STATE_ERROR)
mod.AssureStringPtrValue(&status.Message, err.Error())
} else {
if strings.HasPrefix(*status.Message, MSG_PRESERVED) {
mod.AssureStringPtrValue(&status.Message, MSG_PRESERVED+": "+err.Error())
} else {
mod.AssureStringPtrValue(&status.Message, err.Error())
}
}
} else {
if zoneid == "" {
mod.AssureStringValue(&status.State, api.STATE_ERROR)
Expand Down
2 changes: 2 additions & 0 deletions pkg/dns/provider/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func NewConfigForController(c controller.Interface, factory DNSHandlerFactory) C
}

type DNSHostedZone interface {
ProviderType() string
Key() string
Id() string
Domain() string
Expand Down Expand Up @@ -106,6 +107,7 @@ type Metrics interface {
}

type DNSHandler interface {
ProviderType() string
GetZones() (DNSHostedZones, error)
GetZoneState(DNSHostedZone) (DNSZoneState, error)
ExecuteRequests(logger logger.LogContext, zone DNSHostedZone, state DNSZoneState, reqs []*ChangeRequest) error
Expand Down
31 changes: 18 additions & 13 deletions pkg/dns/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ func newProvider() *dnsProvider {
///////////////////////////////////////////////////////////////////////////////

type DNSAccount struct {
lock sync.Mutex
handler DNSHandler
config utils.Properties
providerType string
lock sync.Mutex
handler DNSHandler
config utils.Properties

hash string
clients resources.ObjectNameSet
Expand All @@ -83,11 +82,11 @@ var _ DNSHandler = &DNSAccount{}
var _ Metrics = &DNSAccount{}

func (this *DNSAccount) AddRequests(requestType string, n int) {
metrics.AddRequests(this.providerType, this.hash, requestType, n)
metrics.AddRequests(this.handler.ProviderType(), this.hash, requestType, n)
}

func (this *DNSAccount) Type() string {
return this.providerType
func (this *DNSAccount) ProviderType() string {
return this.handler.ProviderType()
}

func (this *DNSAccount) Hash() string {
Expand Down Expand Up @@ -142,7 +141,7 @@ func (this *AccountCache) Get(logger logger.LogContext, provider *dnsutils.DNSPr
Config: provider.Spec().ProviderConfig,
DryRun: state.GetConfig().Dryrun,
}
a = &DNSAccount{providerType: provider.Spec().Type, ttl: this.ttl, config: props, hash: h, clients: resources.ObjectNameSet{}}
a = &DNSAccount{ttl: this.ttl, config: props, hash: h, clients: resources.ObjectNameSet{}}
a.handler, err = state.GetHandlerFactory().Create(logger, &cfg, a)
if err != nil {
return nil, err
Expand All @@ -169,7 +168,7 @@ func (this *AccountCache) Release(logger logger.LogContext, a *DNSAccount, name
if len(a.clients) == 0 {
logger.Infof("releasing account for %s (%s)", name, a.Hash())
delete(this.cache, a.hash)
metrics.DeleteAccount(a.Type(), a.Hash())
metrics.DeleteAccount(a.ProviderType(), a.Hash())
} else {
logger.Infof("keeping account for %s (%s): %d client(s)", name, a.Hash(), len(a.clients))
}
Expand Down Expand Up @@ -205,6 +204,7 @@ type dnsProviderVersion struct {

object *dnsutils.DNSProviderObject
account *DNSAccount
valid bool

secret resources.ObjectName
def_include utils.StringSet
Expand All @@ -216,6 +216,10 @@ type dnsProviderVersion struct {
excluded utils.StringSet
}

func (this *dnsProviderVersion) IsValid() bool {
return this.valid
}

func (this *dnsProviderVersion) equivalentTo(v *dnsProviderVersion) bool {
if this.account != v.account {
return false
Expand Down Expand Up @@ -282,7 +286,7 @@ func updateDNSProvider(logger logger.LogContext, state *state, provider *dnsutil

this.account, err = state.GetDNSAccount(logger, provider, props)
if err != nil {
return nil, reconcile.Delay(logger, err)
return this, reconcile.Delay(logger, err)
}

dspec := provider.DNSProvider().Spec.Domains
Expand All @@ -296,7 +300,7 @@ func updateDNSProvider(logger logger.LogContext, state *state, provider *dnsutil

this.zones, err = this.account.GetZones()
if err != nil {
return nil, this.failed(logger, false, fmt.Errorf("cannot get zones: %s", err), true)
return this, this.failed(logger, false, fmt.Errorf("cannot get zones: %s", err), true)
}

included, err := filterByZones(this.def_include, this.zones)
Expand All @@ -310,14 +314,14 @@ func updateDNSProvider(logger logger.LogContext, state *state, provider *dnsutil

if len(this.def_include) == 0 {
if len(this.zones) == 0 {
return nil, this.failed(logger, false, fmt.Errorf("no hosted zones found"), false)
return this, this.failed(logger, false, fmt.Errorf("no hosted zones found"), false)
}
for _, z := range this.zones {
included.Add(z.Domain())
}
} else {
if len(included) == 0 {
return nil, this.failed(logger, false, fmt.Errorf("no domain matching hosting zones"), false)
return this, this.failed(logger, false, fmt.Errorf("no domain matching hosting zones"), false)

}
}
Expand All @@ -341,6 +345,7 @@ func updateDNSProvider(logger logger.LogContext, state *state, provider *dnsutil
this.included = included
this.excluded = excluded

this.valid = true
return this, this.succeeded(logger, this.object.SetDomains(included, excluded))
}

Expand Down
Loading

0 comments on commit c8e6d88

Please sign in to comment.