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

Remove SplitBrain implementation #1829

Merged
merged 1 commit into from
Feb 12, 2025
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
2 changes: 1 addition & 1 deletion api/v1beta1/gslb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Strategy struct {
PrimaryGeoTag string `json:"primaryGeoTag,omitempty"`
// Defines DNS record TTL in seconds
DNSTtlSeconds int `json:"dnsTtlSeconds,omitempty"`
// Split brain TXT record expiration in seconds
// Split brain TXT record expiration in seconds. The field is deprecated and not used.
SplitBrainThresholdSeconds int `json:"splitBrainThresholdSeconds,omitempty"`
}

Expand Down
1 change: 0 additions & 1 deletion chart/k8gb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ For Kubernetes `< 1.19` use this chart and k8gb in version `0.8.8` or lower.
| k8gb.securityContext.runAsNonRoot | bool | `true` | For more options consult https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#securitycontext-v1-core |
| k8gb.securityContext.runAsUser | int | `1000` | |
| k8gb.serviceMonitor | object | `{"enabled":false}` | enable ServiceMonitor |
| k8gb.splitBrainCheck | bool | `false` | Enable SplitBrain check (Infoblox only) |
| k8gb.validatingAdmissionPolicy | object | `{"enabled":false}` | enable validating admission policies |
| ns1.enabled | bool | `false` | Enable NS1 provider |
| ns1.ignoreSSL | bool | `false` | optional custom NS1 API endpoint for on-prem setups endpoint: https://api.nsone.net/v1/ |
Expand Down
3 changes: 2 additions & 1 deletion chart/k8gb/crd/k8gb.absa.oss_gslbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ spec:
description: Primary Geo Tag. Valid for failover strategy only
type: string
splitBrainThresholdSeconds:
description: Split brain TXT record expiration in seconds
description: Split brain TXT record expiration in seconds. The
field is deprecated and not used.
type: integer
type:
description: Load balancing strategy type:(roundRobin|failover)
Expand Down
2 changes: 0 additions & 2 deletions chart/k8gb/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ spec:
value: {{ quote .Values.k8gb.log.level }}
- name: NO_COLOR
value: "true"
- name: SPLIT_BRAIN_CHECK
value: {{ quote .Values.k8gb.splitBrainCheck }}
- name: METRICS_ADDRESS
value: {{ .Values.k8gb.metricsAddress }}
{{- if .Values.tracing.enabled }}
Expand Down
2 changes: 0 additions & 2 deletions chart/k8gb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ k8gb:
format: simple # log format (simple,json)
# -- log level (panic,fatal,error,warn,info,debug,trace)
level: info # log level (panic,fatal,error,warn,info,debug,trace)
# -- Enable SplitBrain check (Infoblox only)
splitBrainCheck: false
# -- Metrics server address
metricsAddress: "0.0.0.0:8080"
securityContext:
Expand Down
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
24 changes: 0 additions & 24 deletions controllers/depresolver/depresolver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const (
LogLevelKey = "LOG_LEVEL"
LogFormatKey = "LOG_FORMAT"
LogNoColorKey = "NO_COLOR"
SplitBrainCheckKey = "SPLIT_BRAIN_CHECK"
TracingEnabled = "TRACING_ENABLED"
OtelExporterOtlpEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
TracingSamplingRatio = "TRACING_SAMPLING_RATIO"
Expand Down Expand Up @@ -383,18 +382,6 @@ func (c *Config) GetClusterNSName() string {
return getNsName(c.ClusterGeoTag, c.DNSZone, c.EdgeDNSZone, c.EdgeDNSServers[0].Host)
}

func (c *Config) GetExternalClusterHeartbeatFQDNs(gslbName string) (m map[string]string) {
m = make(map[string]string, len(c.ExtClustersGeoTags))
for _, tag := range c.ExtClustersGeoTags {
m[tag] = getHeartbeatFQDN(gslbName, tag, c.EdgeDNSZone)
}
return
}

func (c *Config) GetClusterHeartbeatFQDN(gslbName string) string {
return getHeartbeatFQDN(gslbName, c.ClusterGeoTag, c.EdgeDNSZone)
}

// getNsName returns NS for geo tag.
// The values is combination of DNSZone, EdgeDNSZone and (Ext)ClusterGeoTag, see:
// DNS_ZONE k8gb-test.gslb.cloud.example.com
Expand All @@ -412,14 +399,3 @@ func getNsName(tag, dnsZone, edgeDNSZone, edgeDNSServer string) string {
domainX := strings.ReplaceAll(d, ".", "-")
return fmt.Sprintf("%s-%s-%s.%s", prefix, tag, domainX, edgeDNSZone)
}

// getHeartbeatFQDN returns heartbeat for geo tag.
// The values is combination of EdgeDNSZone and (Ext)ClusterGeoTag, and GSLB name see:
// EDGE_DNS_ZONE: cloud.example.com
// CLUSTER_GEOTAG: us
// gslb.Name: test-gslb-1
// will generate "test-gslb-1-heartbeat-us.cloud.example.com"
// The function is private and expects only valid inputs.
func getHeartbeatFQDN(name, geoTag, edgeDNSZone string) string {
return fmt.Sprintf("%s-heartbeat-%s.%s", name, geoTag, edgeDNSZone)
}
10 changes: 1 addition & 9 deletions controllers/depresolver/depresolver_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import (
)

var predefinedStrategy = k8gbv1beta1.Strategy{
DNSTtlSeconds: 30,
SplitBrainThresholdSeconds: 300,
DNSTtlSeconds: 30,
}

// ResolveGslbSpec fills Gslb by spec values. It executes always, when gslb is initialised.
Expand All @@ -44,9 +43,6 @@ func (dr *DependencyResolver) ResolveGslbSpec(ctx context.Context, gslb *k8gbv1b
if gslb.Spec.Strategy.DNSTtlSeconds == 0 {
gslb.Spec.Strategy.DNSTtlSeconds = predefinedStrategy.DNSTtlSeconds
}
if gslb.Spec.Strategy.SplitBrainThresholdSeconds == 0 {
gslb.Spec.Strategy.SplitBrainThresholdSeconds = predefinedStrategy.SplitBrainThresholdSeconds
}
dr.errorSpec = dr.validateSpec(gslb.Spec.Strategy)
if dr.errorSpec == nil {
dr.errorSpec = client.Update(ctx, gslb)
Expand All @@ -61,10 +57,6 @@ func (dr *DependencyResolver) validateSpec(strategy k8gbv1beta1.Strategy) (err e
if err != nil {
return
}
err = field("SplitBrainThresholdSeconds", strategy.SplitBrainThresholdSeconds).isHigherOrEqualToZero().err
if err != nil {
return
}
err = field("Type", strategy.Type).isOneOf(RoundRobinStrategy, GeoStrategy, FailoverStrategy).err
if err != nil {
return
Expand Down
88 changes: 1 addition & 87 deletions controllers/depresolver/depresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ var predefinedConfig = Config{
EdgeDNSZone: "example.com",
DNSZone: defaultEdgeDNSZone,
K8gbNamespace: "k8gb",
SplitBrainCheck: true,
MetricsAddress: "0.0.0.0:8080",
Infoblox: Infoblox{
"Infoblox.host.com",
Expand All @@ -97,7 +96,6 @@ func TestResolveSpecWithFilledFields(t *testing.T) {
// assert
assert.NoError(t, err)
assert.Equal(t, 35, gslb.Spec.Strategy.DNSTtlSeconds)
assert.Equal(t, 305, gslb.Spec.Strategy.SplitBrainThresholdSeconds)
assert.False(t, len(gslb.Spec.Strategy.Weight) == 0)
assert.Equal(t, 15, gslb.Spec.Strategy.Weight["za"])
assert.Equal(t, 25, gslb.Spec.Strategy.Weight["eu"])
Expand All @@ -114,22 +112,9 @@ func TestResolveSpecWithoutFields(t *testing.T) {
// assert
assert.NoError(t, err)
assert.Equal(t, predefinedStrategy.DNSTtlSeconds, gslb.Spec.Strategy.DNSTtlSeconds)
assert.Equal(t, predefinedStrategy.SplitBrainThresholdSeconds, gslb.Spec.Strategy.SplitBrainThresholdSeconds)
assert.True(t, len(gslb.Spec.Strategy.Weight) == 0)
}

func TestResolveSpecWithZeroSplitBrain(t *testing.T) {
// arrange
cl, gslb := getTestContext("./testdata/filled_omitempty_with_zero_splitbrain.yaml")
resolver := NewDependencyResolver()
// act
err := resolver.ResolveGslbSpec(context.TODO(), gslb, cl)
// assert
assert.NoError(t, err)
assert.Equal(t, 35, gslb.Spec.Strategy.DNSTtlSeconds)
assert.Equal(t, predefinedStrategy.SplitBrainThresholdSeconds, gslb.Spec.Strategy.SplitBrainThresholdSeconds)
}

func TestResolveSpecWithEmptyFields(t *testing.T) {
// arrange
cl, gslb := getTestContext("./testdata/invalid_omitempty_empty.yaml")
Expand All @@ -139,17 +124,6 @@ func TestResolveSpecWithEmptyFields(t *testing.T) {
// assert
assert.NoError(t, err)
assert.Equal(t, predefinedStrategy.DNSTtlSeconds, gslb.Spec.Strategy.DNSTtlSeconds)
assert.Equal(t, predefinedStrategy.SplitBrainThresholdSeconds, gslb.Spec.Strategy.SplitBrainThresholdSeconds)
}

func TestResolveSpecWithNegativeFields(t *testing.T) {
// arrange
cl, gslb := getTestContext("./testdata/invalid_omitempty_negative.yaml")
resolver := NewDependencyResolver()
// act
err := resolver.ResolveGslbSpec(context.TODO(), gslb, cl)
// assert
assert.Error(t, err)
}

func TestResolveSpecWithType(t *testing.T) {
Expand Down Expand Up @@ -227,13 +201,11 @@ func TestSpecRunWhenChanged(t *testing.T) {
resolver := NewDependencyResolver()
// act
err1 := resolver.ResolveGslbSpec(ctx, gslb, cl)
gslb.Spec.Strategy.SplitBrainThresholdSeconds = 0
err2 := resolver.ResolveGslbSpec(ctx, gslb, cl)
// assert
assert.NoError(t, err1)
// err2 would not be empty
assert.NoError(t, err2)
assert.Equal(t, predefinedStrategy.SplitBrainThresholdSeconds, gslb.Spec.Strategy.SplitBrainThresholdSeconds)
assert.Equal(t, 35, gslb.Spec.Strategy.DNSTtlSeconds)
}

Expand Down Expand Up @@ -1184,63 +1156,6 @@ func TestResolveLoggerOutputWithInvalidValue(t *testing.T) {
assert.Equal(t, NoFormat, config.Log.Format)
}

func TestResolveConfigSplitBrainCheckEnabled(t *testing.T) {
// arrange
defer cleanup()
expected := predefinedConfig
expected.SplitBrainCheck = true
// act,assert
arrangeVariablesAndAssert(t, expected, assert.NoError)
}

func TestHeartBeatWithMultipleExtClusterGeoTag(t *testing.T) {
const geoTag = "test-gslb-1"
// arrange
defer cleanup()
customConfig := predefinedConfig
customConfig.DNSZone = defaultDNSZone
customConfig.EdgeDNSZone = defaultEdgeDNSZone
customConfig.ClusterGeoTag = defaultClusterGeoTagUs1
customConfig.ExtClustersGeoTags = []string{defaultClusterGeoTagUs2, defaultClusterGeoTagEu}
configureEnvVar(customConfig)
resolver := NewDependencyResolver()

// act
config, err := resolver.ResolveOperatorConfig()

// assert
assert.NoError(t, err)
assert.Len(t, config.GetExternalClusterHeartbeatFQDNs(geoTag), 2)
assert.Equal(t, "test-gslb-1-heartbeat-us-west-1.cloud.example.com", config.GetClusterHeartbeatFQDN(geoTag))

for k, v := range map[string]string{defaultClusterGeoTagUs2: "test-gslb-1-heartbeat-us-east-1.cloud.example.com",
defaultClusterGeoTagEu: "test-gslb-1-heartbeat-eu-central-1.cloud.example.com"} {
assert.Equal(t, config.GetExternalClusterHeartbeatFQDNs(geoTag)[k], v)
}
}

func TestHeartBeatWithOneExtClusterGeoTag(t *testing.T) {
const geoTag = "test-gslb-1"
// arrange
defer cleanup()
customConfig := predefinedConfig
customConfig.DNSZone = defaultDNSZone
customConfig.EdgeDNSZone = defaultEdgeDNSZone
customConfig.ClusterGeoTag = defaultClusterGeoTagUs1
customConfig.ExtClustersGeoTags = []string{defaultClusterGeoTagUs2}
configureEnvVar(customConfig)
resolver := NewDependencyResolver()

// act
config, err := resolver.ResolveOperatorConfig()

// assert
assert.NoError(t, err)
assert.Len(t, config.GetExternalClusterHeartbeatFQDNs(geoTag), 1)
assert.Equal(t, "test-gslb-1-heartbeat-us-west-1.cloud.example.com", config.GetClusterHeartbeatFQDN(geoTag))
assert.Equal(t, config.GetExternalClusterHeartbeatFQDNs(geoTag)[defaultClusterGeoTagUs2], "test-gslb-1-heartbeat-us-east-1.cloud.example.com")
}

func TestNsServerNamesWithMultipleExtClusterGeoTag(t *testing.T) {
// arrange
defer cleanup()
Expand Down Expand Up @@ -1526,7 +1441,7 @@ func cleanup() {
for _, s := range []string{ReconcileRequeueSecondsKey, NSRecordTTLKey, ClusterGeoTagKey, ExtClustersGeoTagsKey, EdgeDNSZoneKey, DNSZoneKey,
EdgeDNSServersKey, ExtDNSEnabledKey, InfobloxGridHostKey, InfobloxVersionKey, InfobloxPortKey, InfobloxUsernameKey,
InfobloxPasswordKey, K8gbNamespaceKey, CoreDNSExposedKey, InfobloxHTTPRequestTimeoutKey,
InfobloxHTTPPoolConnectionsKey, LogLevelKey, LogFormatKey, LogNoColorKey, MetricsAddressKey, SplitBrainCheckKey, TracingEnabled,
InfobloxHTTPPoolConnectionsKey, LogLevelKey, LogFormatKey, LogNoColorKey, MetricsAddressKey, TracingEnabled,
TracingSamplingRatio, OtelExporterOtlpEndpoint} {
if os.Unsetenv(s) != nil {
panic(fmt.Errorf("cleanup %s", s))
Expand Down Expand Up @@ -1558,7 +1473,6 @@ func configureEnvVar(config Config) {
_ = os.Setenv(LogFormatKey, config.Log.Format.String())
_ = os.Setenv(LogNoColorKey, strconv.FormatBool(config.Log.NoColor))
_ = os.Setenv(MetricsAddressKey, config.MetricsAddress)
_ = os.Setenv(SplitBrainCheckKey, strconv.FormatBool(config.SplitBrainCheck))
_ = os.Setenv(TracingEnabled, strconv.FormatBool(config.TracingEnabled))
_ = os.Setenv(TracingSamplingRatio, strconv.FormatFloat(config.TracingSamplingRatio, 'f', 2, 64))
_ = os.Setenv(OtelExporterOtlpEndpoint, config.OtelExporterOtlpEndpoint)
Expand Down
1 change: 0 additions & 1 deletion controllers/depresolver/testdata/filled_omitempty.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ spec:
name: http
strategy:
type: roundRobin # Use a round robin load balancing strategy, when deciding which downstream clusters to route clients too
splitBrainThresholdSeconds: 305
dnsTtlSeconds: 35
weight:
us: 60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ spec:
name: http
strategy:
type: roundRobin # Use a round robin load balancing strategy, when deciding which downstream clusters to route clients too
splitBrainThresholdSeconds: 0
dnsTtlSeconds: 35

Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ spec:
name: http
strategy:
type: roundRobin # Use a round robin load balancing strategy, when deciding which downstream clusters to route clients too
splitBrainThresholdSeconds:
weight:

This file was deleted.

11 changes: 5 additions & 6 deletions controllers/gslb_controller_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ type GslbReconciler struct {
}

const (
gslbFinalizer = "k8gb.absa.oss/finalizer"
primaryGeoTagAnnotation = "k8gb.io/primary-geotag"
strategyAnnotation = "k8gb.io/strategy"
dnsTTLSecondsAnnotation = "k8gb.io/dns-ttl-seconds"
splitBrainThresholdSecondsAnnotation = "k8gb.io/splitbrain-threshold-seconds"
gslbFinalizer = "k8gb.absa.oss/finalizer"
primaryGeoTagAnnotation = "k8gb.io/primary-geotag"
strategyAnnotation = "k8gb.io/strategy"
dnsTTLSecondsAnnotation = "k8gb.io/dns-ttl-seconds"
)

var k8gbAnnotations = []string{strategyAnnotation, primaryGeoTagAnnotation, dnsTTLSecondsAnnotation, splitBrainThresholdSecondsAnnotation}
var k8gbAnnotations = []string{strategyAnnotation, primaryGeoTagAnnotation, dnsTTLSecondsAnnotation}

var log = logging.Logger()

Expand Down
Loading
Loading