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

Create referenced ingress if GSLB is configured with Ingress annotations #1700

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion chart/k8gb/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ spec:
- name: DNS_ZONE
value: {{ .Values.k8gb.dnsZone }}
- name: RECONCILE_REQUEUE_SECONDS
value: {{ quote .Values.k8gb.reconcileRequeueSeconds}}
value: {{ quote .Values.k8gb.reconcileRequeueSeconds }}
- name: ANNOTATION_CREATES_GSLB_WITH_EMBEDDED_INGRESS
value: {{ quote .Values.k8gb.annotationCreatesGSLBWithEmbeddedIngress }}
{{- if .Values.infoblox.enabled }}
- name: INFOBLOX_GRID_HOST
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions chart/k8gb/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@
},
"serviceMonitor": {
"$ref": "#/definitions/k8gbServiceMonitor"
},
"annotationCreatesGSLBWithEmbeddedIngress": {
"type": "boolean"
}
},
"required": [
Expand Down
2 changes: 2 additions & 0 deletions chart/k8gb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ k8gb:
# -- enable ServiceMonitor
serviceMonitor:
enabled: false
# -- whether annotations on ingress create a GSLB with an embedded or a referenced ingress
annotationCreatesGSLBWithEmbeddedIngress: false

externaldns:
# -- `.spec.template.spec.dnsPolicy` for ExternalDNS deployment
Expand Down
2 changes: 2 additions & 0 deletions controllers/depresolver/depresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ type Config struct {
// OtelExporterOtlpEndpoint where the traces should be sent to (in case of otel collector deployed on the same pod as sidecar -> localhost:4318)
// otel collector itself can be configured via a configmap to send it somewhere else
OtelExporterOtlpEndpoint string `env:"OTEL_EXPORTER_OTLP_ENDPOINT, default=localhost:4318"`
// AnnotationCreatesGSLBWithEmbeddedIngress flag (will be deprecated in v1.1)
AnnotationCreatesGSLBWithEmbeddedIngress bool `env:"ANNOTATION_CREATES_GSLB_WITH_EMBEDDED_INGRESS, default=false"`
}

// DependencyResolver resolves configuration for GSLB
Expand Down
27 changes: 14 additions & 13 deletions controllers/depresolver/depresolver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@ const (
InfobloxPortKey = "INFOBLOX_WAPI_PORT"
InfobloxUsernameKey = "INFOBLOX_WAPI_USERNAME"
// #nosec G101; ignore false positive gosec; see: https://securego.io/docs/rules/g101.html
InfobloxPasswordKey = "INFOBLOX_WAPI_PASSWORD"
InfobloxHTTPRequestTimeoutKey = "INFOBLOX_HTTP_REQUEST_TIMEOUT"
InfobloxHTTPPoolConnectionsKey = "INFOBLOX_HTTP_POOL_CONNECTIONS"
K8gbNamespaceKey = "POD_NAMESPACE"
CoreDNSExposedKey = "COREDNS_EXPOSED"
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"
MetricsAddressKey = "METRICS_ADDRESS"
InfobloxPasswordKey = "INFOBLOX_WAPI_PASSWORD"
InfobloxHTTPRequestTimeoutKey = "INFOBLOX_HTTP_REQUEST_TIMEOUT"
InfobloxHTTPPoolConnectionsKey = "INFOBLOX_HTTP_POOL_CONNECTIONS"
K8gbNamespaceKey = "POD_NAMESPACE"
CoreDNSExposedKey = "COREDNS_EXPOSED"
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"
MetricsAddressKey = "METRICS_ADDRESS"
AnnotationCreatesGSLBWithEmbeddedIngress = "ANNOTATION_CREATES_GSLB_WITH_EMBEDDED_INGRESS"
)

// Deprecated environment variables keys
Expand Down
3 changes: 2 additions & 1 deletion controllers/depresolver/depresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ func cleanup() {
ExtDNSEnabledKey, InfobloxGridHostKey, InfobloxVersionKey, InfobloxPortKey, InfobloxUsernameKey,
InfobloxPasswordKey, K8gbNamespaceKey, CoreDNSExposedKey, InfobloxHTTPRequestTimeoutKey,
InfobloxHTTPPoolConnectionsKey, LogLevelKey, LogFormatKey, LogNoColorKey, MetricsAddressKey, SplitBrainCheckKey, TracingEnabled,
TracingSamplingRatio, OtelExporterOtlpEndpoint} {
TracingSamplingRatio, OtelExporterOtlpEndpoint, AnnotationCreatesGSLBWithEmbeddedIngress} {
if os.Unsetenv(s) != nil {
panic(fmt.Errorf("cleanup %s", s))
}
Expand Down Expand Up @@ -1542,6 +1542,7 @@ func configureEnvVar(config Config) {
_ = os.Setenv(TracingEnabled, strconv.FormatBool(config.TracingEnabled))
_ = os.Setenv(TracingSamplingRatio, strconv.FormatFloat(config.TracingSamplingRatio, 'f', 2, 64))
_ = os.Setenv(OtelExporterOtlpEndpoint, config.OtelExporterOtlpEndpoint)
_ = os.Setenv(AnnotationCreatesGSLBWithEmbeddedIngress, strconv.FormatBool(config.AnnotationCreatesGSLBWithEmbeddedIngress))
}

func getTestContext(testData string) (client.Client, *k8gbv1beta1.Gslb) {
Expand Down
40 changes: 32 additions & 8 deletions controllers/gslb_controller_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,38 @@ func (r *GslbReconciler) createGSLBFromIngress(c client.Client, a client.Object,
Msg("Gslb already exists. Skipping Gslb creation...")
return
}
gslb := &k8gbv1beta1.Gslb{
ObjectMeta: metav1.ObjectMeta{
Namespace: a.GetNamespace(),
Name: a.GetName(),
},
Spec: k8gbv1beta1.GslbSpec{
Ingress: k8gbv1beta1.FromV1IngressSpec(ingressToReuse.Spec),
},

if len(ingressToReuse.Labels) == 0 {
log.Warn().
Str("ingress", a.GetName()).
Msg("Deprecated: Ingress does not have labels. From v1.1 every Ingress must have unique labels")
}
var gslb *k8gbv1beta1.Gslb
// TODO replace this config option by an annotation on the ingress; tests that broke should set it
if r.Config.AnnotationCreatesGSLBWithEmbeddedIngress {
gslb = &k8gbv1beta1.Gslb{
ObjectMeta: metav1.ObjectMeta{
Namespace: a.GetNamespace(),
Name: a.GetName(),
},
Spec: k8gbv1beta1.GslbSpec{
Ingress: k8gbv1beta1.FromV1IngressSpec(ingressToReuse.Spec),
},
}
} else {
gslb = &k8gbv1beta1.Gslb{
ObjectMeta: metav1.ObjectMeta{
Namespace: a.GetNamespace(),
Name: a.GetName(),
},
Spec: k8gbv1beta1.GslbSpec{
ResourceRef: k8gbv1beta1.ResourceRef{
Ingress: metav1.LabelSelector{
MatchLabels: ingressToReuse.Labels,
},
},
},
}
}

gslb.Spec.Strategy, err = r.parseStrategy(a.GetAnnotations(), strategy)
Expand Down
2 changes: 2 additions & 0 deletions terratest/examples/broken-ingress-annotation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
annotations:
k8gb.io/strategy: failover
k8gb.io/primary-geotag: eu
labels:
app: notfound-broken
name: broken-test-gslb-annotation-failover
spec:
ingressClassName: nginx
Expand Down
2 changes: 2 additions & 0 deletions terratest/examples/ingress-annotation-failover-simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ metadata:
k8gb.io/strategy: failover
k8gb.io/primary-geotag: "eu"
k8gb.io/dns-ttl-seconds: "5"
labels:
app: ingress-failover-simple
spec:
ingressClassName: nginx
rules:
Expand Down
2 changes: 2 additions & 0 deletions terratest/examples/ingress-annotation-failover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ metadata:
k8gb.io/primary-geotag: "eu"
k8gb.io/dns-ttl-seconds: "5"
k8gb.io/splitbrain-threshold-seconds: "600"
labels:
app: ingress-failover
name: test-gslb-annotation-failover
spec:
ingressClassName: nginx
Expand Down
2 changes: 2 additions & 0 deletions terratest/examples/ingress-annotation-rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
annotations:
k8gb.io/strategy: roundRobin
k8gb.io/dns-ttl-seconds: "5"
labels:
app: ingress-rr
name: test-gslb-annotation
spec:
ingressClassName: nginx
Expand Down
2 changes: 2 additions & 0 deletions terratest/examples/ingress-annotation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
annotations:
k8gb.io/strategy: failover
k8gb.io/primary-geotag: "eu"
labels:
app: test-ingress-annotation-failover
name: test-gslb
spec:
ingressClassName: nginx
Expand Down
8 changes: 0 additions & 8 deletions terratest/test/k8gb_annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ func TestAnnotations(t *testing.T) {
expectedIngress: map[string]string{"k8gb.io/primary-geotag": "eu", "k8gb.io/strategy": "failover"},
expectedGslb: map[string]string{},
},
{
name: "Create From GSLB - patch non k8gb annotation",
host: "test-gslb-annotation.cloud.example.com",
path: "../examples/gslb-annotation.yaml",
patch: map[string]string{"example.io/protocol": "tcp"},
expectedIngress: map[string]string{"k8gb.io/primary-geotag": "eu", "k8gb.io/strategy": "failover", "example.io/protocol": "tcp"},
expectedGslb: map[string]string{"example.io/origin": "gslb"},
},
}

for _, test := range tests {
Expand Down
Loading