Skip to content

Commit

Permalink
remove TXT record from assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
kuritka committed Feb 11, 2025
1 parent ca8416f commit c80fbae
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 90 deletions.
2 changes: 0 additions & 2 deletions controllers/depresolver/depresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ type Config struct {
MetricsAddress string `env:"METRICS_ADDRESS, default=0.0.0.0:8080"`
// extDNSEnabled hidden. EdgeDNSType defines all enabled Enabled types
extDNSEnabled bool `env:"EXTDNS_ENABLED, default=false"`
// SplitBrainCheck flag decides whether split brain TXT records will be stored in edge DNS
SplitBrainCheck bool `env:"SPLIT_BRAIN_CHECK, default=false"`
// TracingEnabled flag decides whether to use a real otlp tracer or a noop one
TracingEnabled bool `env:"TRACING_ENABLED, default=false"`
// TracingSamplingRatio how many traces should be kept and sent (1.0 - all, 0.0 - none)
Expand Down
38 changes: 0 additions & 38 deletions controllers/gslb_controller_reconciliation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
"go.uber.org/mock/gomock"
corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -593,35 +592,6 @@ func TestCanGetExternalTargetsFromK8gbInAnotherLocation(t *testing.T) {
}).RequireNoError(t)
}

func TestCanCheckExternalGslbTXTRecordForValidityAndFailIfItIsExpired(t *testing.T) {
// arrange
utils.NewFakeDNS(fakeDNSSettings).
AddTXTRecord("test-gslb-heartbeat-eu.example.com.", oldEdgeTimestamp("10m")).
Start().
RunTestFunc(func() {
settings := provideSettings(t, predefinedConfig)
// act
got := settings.assistant.InspectTXTThreshold("test-gslb-heartbeat-eu.example.com", time.Minute*5)
want := errors.NewResourceExpired("Split brain TXT record expired the time threshold: (5m0s)")
// assert
assert.Equal(t, want, got, "got:\n %s from TXT split brain check,\n\n want error:\n %v", got, want)
}).RequireNoError(t)
}

func TestCanCheckExternalGslbTXTRecordForValidityAndPAssIfItISNotExpired(t *testing.T) {
// arrange
utils.NewFakeDNS(fakeDNSSettings).
AddTXTRecord("test-gslb-heartbeat-za.example.com.", oldEdgeTimestamp("3m")).
Start().
RunTestFunc(func() {
settings := provideSettings(t, predefinedConfig)
// act
err2 := settings.assistant.InspectTXTThreshold("test-gslb-heartbeat-za.example.com", time.Minute*5)
// assert
assert.NoError(t, err2, "got:\n %s from TXT split brain check,\n\n want error:\n %v", err2, nil)
}).RequireNoError(t)
}

func TestReturnsOwnRecordsUsingFailoverStrategyWhenPrimary(t *testing.T) {
serviceName := defaultPodinfoServiceName
want := []*externaldns.Endpoint{
Expand Down Expand Up @@ -1495,14 +1465,6 @@ func provideSettings(t *testing.T, expected depresolver.Config) (settings testSe
return settings
}

func oldEdgeTimestamp(threshold string) string {
now := time.Now()
duration, _ := time.ParseDuration(threshold)
before := now.Add(-duration)
edgeTimestamp := fmt.Sprint(before.UTC().Format("2006-01-02T15:04:05"))
return edgeTimestamp
}

func TestMain(m *testing.M) {
var exitCode int
defer func() {
Expand Down
5 changes: 0 additions & 5 deletions controllers/providers/assistant/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
*/

import (
"time"

corev1 "k8s.io/api/core/v1"
externaldns "sigs.k8s.io/external-dns/endpoint"
)
Expand All @@ -36,7 +34,4 @@ type Assistant interface {
SaveDNSEndpoint(namespace string, i *externaldns.DNSEndpoint) error
// RemoveEndpoint removes endpoint
RemoveEndpoint(endpointName string) error
// InspectTXTThreshold inspects fqdn TXT record from edgeDNSServer. If record doesn't exists or timestamp is greater than
// splitBrainThreshold the error is returned. In case fakeDNSEnabled is true, 127.0.0.1:7753 is used as edgeDNSServer
InspectTXTThreshold(fqdn string, splitBrainThreshold time.Duration) error
}
45 changes: 0 additions & 45 deletions controllers/providers/assistant/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"context"
coreerrors "errors"
"fmt"
"strings"
"time"

"github.com/k8gb-io/k8gb/controllers/utils"

Expand Down Expand Up @@ -210,49 +208,6 @@ func (r *Gslb) RemoveEndpoint(endpointName string) error {
return err
}

// InspectTXTThreshold inspects fqdn TXT record from edgeDNSServer. If record doesn't exists or timestamp is greater than
// splitBrainThreshold the error is returned.
func (r *Gslb) InspectTXTThreshold(fqdn string, splitBrainThreshold time.Duration) error {
m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(fqdn), dns.TypeTXT)
txt, err := utils.Exchange(m, r.edgeDNSServers)
if err != nil {
log.Info().
Interface("edgeDNSServers", r.edgeDNSServers).
Err(err).
Msg("Contacting EdgeDNS server for TXT split brain record")
return err
}
if len(txt.Answer) > 0 {
if t, ok := txt.Answer[0].(*dns.TXT); ok {
timestamp := strings.Split(t.String(), "\t")[4]
timestamp = strings.Trim(timestamp, "\"") // Otherwise time.Parse() will miserably fail
timeFromTXT, err := time.Parse("2006-01-02T15:04:05", timestamp)
if err != nil {
log.Err(err).
Str("rawRecord", t.String()).
Str("rawTimestamp", timestamp).
Msg("Split brain TXT: can't parse timestamp")
return err
}
now := time.Now().UTC()
diff := now.Sub(timeFromTXT)
log.Debug().
Str("rawRecord", t.String()).
Str("rawTimestamp", timestamp).
Time("parsed", timeFromTXT).
Str("diff", diff.String()).
Msg("Split brain TXT")

if diff > splitBrainThreshold {
return errors.NewResourceExpired(fmt.Sprintf("Split brain TXT record expired the time threshold: (%s)", splitBrainThreshold))
}
return nil
}
}
return errors.NewResourceExpired(fmt.Sprintf("Can't find split brain TXT record at EdgeDNS servers(%+v) and record %s ", r.edgeDNSServers, fqdn))
}

func getARecords(msg *dns.Msg) []string {
var ARecords []string
for _, nsA := range msg.Answer {
Expand Down

0 comments on commit c80fbae

Please sign in to comment.