Skip to content
Closed
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
Expand Up @@ -25,6 +25,7 @@ Dockerfile.cross
*.swp
*.swo
*~
examples/*

# Helm chart packages
*operator*.tgz*
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ build: manifests generate fmt vet ## Build manager binary.
RUN_METRICS_ADDR=":8080"
RUN_HEALTH_ADDR=":8081"
RUN_DELEGATION_ROLE="primary"
DEFAULT_RUN_FLAGS ?= --zap-devel --provider inmemory,aws,google,azure,coredns,endpoint --delegation-role=${RUN_DELEGATION_ROLE} --metrics-bind-address=${RUN_METRICS_ADDR} --health-probe-bind-address=${RUN_HEALTH_ADDR}
DEFAULT_RUN_FLAGS ?= --zap-devel --provider inmemory,aws,google,azure,coredns,endpoint --delegation-role=${RUN_DELEGATION_ROLE} --metrics-bind-address=${RUN_METRICS_ADDR} --health-probe-bind-address=${RUN_HEALTH_ADDR} --min-requeue-time=1s --valid-for=5s --max-requeue-time=30s
RUN_FLAGS ?= $(DEFAULT_RUN_FLAGS)

.PHONY: run
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ const ConditionReasonUnhealthy ConditionReason = "HealthChecksFailed"

const ConditionTypeReadyForDelegation ConditionType = "ReadyForDelegation"
const ConditionReasonFinalizersSet ConditionReason = "FinalizersSet"

const ConditionTypeActive ConditionType = "Active"
const ConditionReasonNotInActiveGroup = "NotMemberOfActiveGroup"
const ConditionReasonInActiveGroup = "MemberOfActiveGroup"
const ConditionReasonNoActiveGroups = "NoActiveGroupsSet"
11 changes: 11 additions & 0 deletions api/v1alpha1/dnsrecord_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
externaldns "sigs.k8s.io/external-dns/endpoint"

"github.com/kuadrant/dns-operator/internal/common/hash"
"github.com/kuadrant/dns-operator/types"
)

type Protocol string
Expand Down Expand Up @@ -176,6 +177,12 @@ type DNSRecordStatus struct {
// A CRD can't reference a type within itself so the `apiextensionsv1.JSON` type is used.
// Use GetRemoteRecordStatuses to get the converted type.
RemoteRecordStatuses map[string]apiextensionsv1.JSON `json:"remoteRecordStatuses,omitempty"`

// Group displays the group which the dns-operator belongs to, if set.
Group types.Group `json:"group,omitempty"`

// ActiveGroups displays the last read list of active groups
ActiveGroups string `json:"activeGroups,omitempty"`
}

// GetRemoteRecordStatuses returns any remote record statuses in the current status.
Expand Down Expand Up @@ -336,6 +343,10 @@ func (s *DNSRecord) IsDeleting() bool {
return s.DeletionTimestamp != nil && !s.DeletionTimestamp.IsZero()
}

func (s *DNSRecord) IsActive() bool {
return true
}

// ProviderAccessor impl

var _ ProviderAccessor = &DNSRecord{}
Expand Down
4 changes: 4 additions & 0 deletions bundle/manifests/kuadrant.io_dnsrecords.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ spec:
type: array
type: object
type: array
group:
description: Group displays the group which the dns-operator belongs
to, if set.
type: string
healthCheck:
properties:
conditions:
Expand Down
4 changes: 4 additions & 0 deletions charts/dns-operator/templates/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ spec:
type: array
type: object
type: array
group:
description: Group displays the group which the dns-operator belongs
to, if set.
type: string
healthCheck:
properties:
conditions:
Expand Down
6 changes: 4 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ func main() {
Scheme: mgr.GetScheme(),
ProviderFactory: providerFactory,
DelegationRole: delegationRole,
Group: &group,
Group: group,
TXTResolver: &controller.DefaultTXTResolver{},
},
Client: mgr.GetClient(),
}
Expand All @@ -263,7 +264,8 @@ func main() {
Scheme: mgr.GetScheme(),
ProviderFactory: providerFactory,
DelegationRole: delegationRole,
Group: &group,
Group: group,
TXTResolver: &controller.DefaultTXTResolver{},
},
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/plugin/common/pretty.go → cmd/plugin/common/output.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"fmt"
"os"
"strings"

Expand All @@ -9,6 +10,10 @@ import (
externaldns "sigs.k8s.io/external-dns/endpoint"
)

var (
Verbose bool
)

func RenderEndpoints(endpoints []*externaldns.Endpoint) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
Expand All @@ -34,3 +39,13 @@ func RenderEndpoints(endpoints []*externaldns.Endpoint) {
}
t.Render()
}

func PrintOutput(text string, debugLevelMessage bool) {
if Verbose || !debugLevelMessage {
fmt.Println(text)
}
}

func PrintError(err error, wrap string) {
fmt.Printf("%s: %s\n", wrap, err)
}
33 changes: 17 additions & 16 deletions cmd/plugin/failover/add-active-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func init() {
}

func addActiveGroup(_ *cobra.Command, args []string) error {
log := logf.Log.WithName("add-active-group")
log := logf.Log.WithName("add-active-group").WithSink(logf.NullLogSink{})

groupName := args[0]

Expand All @@ -57,42 +57,43 @@ func addActiveGroup(_ *cobra.Command, args []string) error {
// setup context
d := time.Now().Add(time.Minute * 5)
ctx, cancel := context.WithDeadline(context.Background(), d)
ctx = logf.IntoContext(ctx, log)
defer cancel()

// get all the zones
endpointProvider, err := common.GetProviderForConfig(ctx, resourceRef, provider.Config{
DomainFilter: externaldnsendpoint.NewRegexDomainFilter(domainRegexp, nil),
})
if err != nil {
log.Error(err, "failed to create provider for secret")
common.PrintError(err, "failed to create provider for secret")
return err
}

// note down zones we want to work with
allZones, err := endpointProvider.DNSZones(ctx)
if err != nil {
log.Error(err, "failed to get DNS zones")
common.PrintError(err, "failed to get DNS zones")
return err
}

var selectedZones []provider.DNSZone

if len(allZones) == 0 {
log.Info(fmt.Sprintf("No DNS zones found for domain %s", domain))
log.V(1).Info(fmt.Sprintf("Regexp string: %s", domainRegexp.String()))
common.PrintOutput(fmt.Sprintf("No DNS zones found for domain %s", domain), false)
common.PrintOutput(fmt.Sprintf("Regexp string: %s", domainRegexp.String()), true)
return nil
} else if len(allZones) == 1 {
selectedZones = allZones
} else {
log.Info(fmt.Sprintf("Multiple DNS zones (%d) found for domain %s", len(allZones), domain))
common.PrintOutput(fmt.Sprintf("Multiple DNS zones (%d) found for domain %s", len(allZones), domain), false)
for _, zone := range allZones {
if !assumeYes {
log.Info(fmt.Sprintf("Add group to zone %s (ID: %s)? [Y/N]", zone.DNSName, zone.ID))
common.PrintOutput(fmt.Sprintf("Add group to zone %s (ID: %s)? [Y/N]", zone.DNSName, zone.ID), false)
}

if assumeYes || inputYes(log) {
if assumeYes {
log.V(1).Info(fmt.Sprintf("Selected zone %s (ID: %s)", domain, zone.ID))
common.PrintOutput(fmt.Sprintf("Selected zone %s (ID: %s)", domain, zone.ID), true)
}
selectedZones = append(selectedZones, zone)
}
Expand All @@ -111,13 +112,13 @@ func addActiveGroup(_ *cobra.Command, args []string) error {
},
})
if err != nil {
log.Error(err, fmt.Sprintf("failed to create provider for zone %s (ID: %s)", zone.DNSName, zone.ID))
common.PrintError(err, fmt.Sprintf("failed to create provider for zone %s (ID: %s)", zone.DNSName, zone.ID))
continue
}

endpoints, err = providerForZone.Records(ctx)
if err != nil {
log.Error(err, "failed tp get endpoints")
common.PrintError(err, "failed tp get endpoints")
continue
}

Expand All @@ -132,14 +133,14 @@ func addActiveGroup(_ *cobra.Command, args []string) error {
}
}
if groupTXTRecord != nil && strings.Contains(groupTXTRecord.Targets[0], groupName) {
log.Info("Found existing TXT record for domain that already contains group name.", "zone DNS Name", zone.DNSName, "record", groupName)
log.Info("Nothing to do")
log.V(1).Info(fmt.Sprintf("existing record name: %s, targets: %s", groupRecordName, groupTXTRecord.Targets))
common.PrintOutput(fmt.Sprintf("Found existing TXT record for domain that already contains group name. Zone DNS Name: %s. Record: %s", zone.DNSName, groupName), false)
common.PrintOutput("Nothing to do", false)
common.PrintOutput(fmt.Sprintf("existing record name: %s, targets: %s", groupRecordName, groupTXTRecord.Targets), true)
continue

}

log.Info(fmt.Sprintf("Setting group %s as active group", groupName))
common.PrintOutput(fmt.Sprintf("Setting group %s as active group", groupName), false)

// write txt record
changes := &plan.Changes{}
Expand All @@ -154,11 +155,11 @@ func addActiveGroup(_ *cobra.Command, args []string) error {
// apply changes via provider bypassing registry - we don't want ownership TXT records for this
err = providerForZone.ApplyChanges(ctx, changes)
if err != nil {
log.Error(err, "failed to apply changes")
common.PrintError(err, "failed to apply changes")
continue
}

log.Info(fmt.Sprintf("added group \"%s\" to active groups of \"%s\" zone", args[0], zone.DNSName))
common.PrintOutput(fmt.Sprintf("added group \"%s\" to active groups of \"%s\" zone", args[0], zone.DNSName), false)
}
return nil
}
21 changes: 11 additions & 10 deletions cmd/plugin/failover/get-active-groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {
}

func getActiveGroups(_ *cobra.Command, _ []string) error {
log := logf.Log.WithName("get-active-groups")
log := logf.Log.WithName("get-active-groups").WithSink(logf.NullLogSink{})

// create regexp to filter zones
domainRegexp, err := GetDomainRegexp(domain)
Expand All @@ -39,32 +39,33 @@ func getActiveGroups(_ *cobra.Command, _ []string) error {

resourceRef, err = common.ParseProviderRef(providerRef)
if err != nil {
log.Error(err, "failed to parse provider ref")
common.PrintError(err, "failed to parse provider ref")
return err
}

// get provider secret
d := time.Now().Add(time.Minute * 5)
ctx, cancel := context.WithDeadline(context.Background(), d)
ctx = logf.IntoContext(ctx, log)
defer cancel()

// get all the zones
endpointProvider, err := common.GetProviderForConfig(ctx, resourceRef, provider.Config{
DomainFilter: externaldnsendpoint.NewRegexDomainFilter(domainRegexp, nil),
})
if err != nil {
log.Error(err, "failed to create provider for secret")
common.PrintError(err, "failed to create provider for secret")
return err
}

allZones, err := endpointProvider.DNSZones(ctx)
if err != nil {
log.Error(err, "failed to get DNS zones")
common.PrintError(err, "failed to get DNS zones")
return err
}

if len(allZones) == 0 {
log.Info(fmt.Sprintf("No DNS zones found for domain %s", domain))
common.PrintOutput(fmt.Sprintf("No DNS zones found for domain %s", domain), false)
return nil
}

Expand All @@ -87,13 +88,13 @@ func getActiveGroups(_ *cobra.Command, _ []string) error {
},
})
if err != nil {
log.Error(err, fmt.Sprintf("failed to create provider for zone %s (ID: %s)", zone.DNSName, zone.ID))
common.PrintError(err, fmt.Sprintf("failed to create provider for zone %s (ID: %s)", zone.DNSName, zone.ID))
continue
}

endpoints, err := providerForZone.Records(ctx)
if err != nil {
log.Error(err, "failed tp get endpoints")
common.PrintError(err, "failed tp get endpoints")
continue
}

Expand Down Expand Up @@ -121,14 +122,14 @@ func getActiveGroups(_ *cobra.Command, _ []string) error {
}

if len(allActiveGroups) == 0 {
log.Info(fmt.Sprintf("No active groups found for domain %s", domain))
common.PrintOutput(fmt.Sprintf("No active groups found for domain %s", domain), false)
return nil
}

for zone, groups := range allActiveGroups {
log.Info(fmt.Sprintf("Zone %s (ID %s):", zone.name, zone.id))
common.PrintOutput(fmt.Sprintf("Zone %s (ID %s):", zone.name, zone.id), false)
for _, group := range groups {
log.Info(fmt.Sprintf("\t%s", group))
common.PrintOutput(fmt.Sprintf("\t%s", group), false)
}
}

Expand Down
Loading
Loading