Skip to content

Commit

Permalink
terratest roundrobin
Browse files Browse the repository at this point in the history
Signed-off-by: abaguas <[email protected]>
  • Loading branch information
abaguas committed Jun 17, 2024
1 parent 04c9341 commit 1ed9519
Show file tree
Hide file tree
Showing 23 changed files with 353 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ terratest: # Run terratest suite
echo -e "$(RED)Make sure you run the tests against at least two running clusters$(NC)" ;\
exit 1;\
fi
cd terratest/test/ && go mod download && CLUSTERS_NUMBER=$(RUNNING_CLUSTERS) go test -v -timeout 15m -parallel=12 --tags=$(TEST_TAGS)
cd terratest/test/ && go mod download && CLUSTERS_NUMBER=$(RUNNING_CLUSTERS) go test -v -timeout 20m -parallel=12 --tags=$(TEST_TAGS)

.PHONY: website
website:
Expand Down
42 changes: 18 additions & 24 deletions chart/k8gb/crd/k8gb.absa.oss_gslbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,25 +324,25 @@ spec:
description: matchExpressions is a list of label selector
requirements. The requirements are ANDed.
items:
description: A label selector requirement is a selector
that contains values, a key, and an operator that relates
the key and values.
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector
applies to.
type: string
operator:
description: operator represents a key's relationship
to a set of values. Valid operators are In, NotIn,
Exists and DoesNotExist.
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: values is an array of string values. If
the operator is In or NotIn, the values array must
be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced
during a strategic merge patch.
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
Expand All @@ -354,13 +354,13 @@ spec:
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A
single {key,value} in the matchLabels map is equivalent
to an element of matchExpressions, whose key field is "key",
the operator is "In", and the values array contains only
"value". The requirements are ANDed.
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: object
strategy:
description: Gslb Strategy spec
Expand Down Expand Up @@ -408,9 +408,7 @@ spec:
description: LoadBalancer configuration
properties:
exposedIps:
description: ExposedIPs on the local Load Balancer. This information
is extracted automatically from the 'ingress' or 'resourceRef'
configuration (optional)
description: ExposedIPs on the local Load Balancer
items:
type: string
type: array
Expand All @@ -421,14 +419,10 @@ spec:
description: Servers holds the GSLB's servers' configuration
properties:
host:
description: Hostname exposed by the GSLB. This information
is extracted automatically from the 'ingress' or 'resourceRef'
configuration (optional)
description: Hostname exposed by the GSLB
type: string
services:
description: Kubernetes Services backing the load balanced application
under the hostname. This information is extracted automatically
from the 'ingress' or 'resourceRef' configuration (optional)
items:
description: NamespacedName holds a reference to a k8s resource
properties:
Expand Down
2 changes: 1 addition & 1 deletion controllers/gslb_controller_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (r *GslbReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
gslb.Status.Servers = servers
fmt.Printf("got servers: %v\n", servers)

loadBalancerExposedIPs, err := refResolver.GetGslbExposedIPs(gslb, r.Client, r.Config.EdgeDNSServers)
loadBalancerExposedIPs, err := refResolver.GetGslbExposedIPs(r.Client, r.Config.EdgeDNSServers)
if err != nil {
m.IncrementError(gslb)
return result.RequeueError(fmt.Errorf("getting load balancer exposed IPs (%s)", err))
Expand Down
10 changes: 5 additions & 5 deletions controllers/mocks/refresolver_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controllers/providers/dns/infoblox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestInfobloxCreateZoneDelegationForExternalDNSWithSplitBrainEnabled(t *test
a := mocks.NewMockAssistant(ctrl)
cl := mocks.NewMockInfobloxClient(ctrl)
con := mocks.NewMockIBConnector(ctrl)
a.EXPECT().InspectTXTThreshold(gomock.Any(), gomock.Any()).Do(func(fqdn string, arg1 interface{}) {
a.EXPECT().InspectTXTThreshold(gomock.Any(), gomock.Any()).Do(func(fqdn string, _ interface{}) {
require.Equal(t, "test-gslb-heartbeat-us-east-1.example.com", fqdn)
}).Return(nil).Times(1)
con.EXPECT().CreateObject(gomock.Any()).Return(ref, nil).AnyTimes()
Expand Down
4 changes: 2 additions & 2 deletions controllers/refresolver/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
"reflect"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/utils"
netv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -171,7 +171,7 @@ func (irr *IngressReferenceResolver) GetServers() ([]*k8gbv1beta1.Server, error)
}

// GetGslbExposedIPs retrieves the load balancer IP address of the GSLB
func (irr *IngressReferenceResolver) GetGslbExposedIPs(gslb *k8gbv1beta1.Gslb, _ client.Client, edgeDNSServers utils.DNSList) ([]string, error) {
func (irr *IngressReferenceResolver) GetGslbExposedIPs(_ client.Client, edgeDNSServers utils.DNSList) ([]string, error) {
gslbIngressIPs := []string{}

for _, ip := range irr.ingress.Status.LoadBalancer.Ingress {
Expand Down
4 changes: 2 additions & 2 deletions controllers/refresolver/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
"testing"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/utils"
"github.com/stretchr/testify/assert"
netv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestGetGslbExposedIPs(t *testing.T) {
}

// act
IPs, err := resolver.GetGslbExposedIPs(&k8gbv1beta1.Gslb{}, nil, []utils.DNSServer{})
IPs, err := resolver.GetGslbExposedIPs(nil, []utils.DNSServer{})
assert.NoError(t, err)

// assert
Expand Down
4 changes: 2 additions & 2 deletions controllers/refresolver/refresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
"reflect"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/logging"
"github.com/k8gb-io/k8gb/controllers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -54,7 +54,7 @@ type GslbReferenceResolver interface {
// GetServers retrieves the server configuration of the GSLB object
GetServers() ([]*k8gbv1beta1.Server, error)
// GetGslbExposedIPs retrieves the load balancer IP address of the GSLB
GetGslbExposedIPs(*k8gbv1beta1.Gslb, client.Client, utils.DNSList) ([]string, error)
GetGslbExposedIPs(client.Client, utils.DNSList) ([]string, error)
}

// New creates a new GSLBReferenceResolver
Expand Down
13 changes: 13 additions & 0 deletions terratest/examples/failover-playground-ref-gslb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: k8gb.absa.oss/v1beta1
kind: Gslb
metadata:
name: test-gslb
spec:
resourceRef:
ingress:
matchLabels:
app: test-gslb
strategy:
type: failover
dnsTtlSeconds: 5
primaryGeoTag: "eu"
19 changes: 19 additions & 0 deletions terratest/examples/failover-playground-ref-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-gslb
labels:
app: test-gslb
spec:
ingressClassName: nginx
rules:
- host: playground-failover.cloud.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-podinfo # Gslb should reflect Healthy status and create associated DNS records
port:
name: http
13 changes: 13 additions & 0 deletions terratest/examples/failover-ref-gslb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: k8gb.absa.oss/v1beta1
kind: Gslb
metadata:
name: test-gslb
spec:
resourceRef:
ingress:
matchLabels:
app: test-gslb
strategy:
type: failover
dnsTtlSeconds: 5
primaryGeoTag: "eu"
19 changes: 19 additions & 0 deletions terratest/examples/failover-ref-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-gslb
labels:
app: test-gslb
spec:
ingressClassName: nginx
rules:
- host: terratest-failover.cloud.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-podinfo # Gslb should reflect Healthy status and create associated DNS records
port:
name: http
15 changes: 15 additions & 0 deletions terratest/examples/roundrobin-weight1-ref-gslb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: k8gb.absa.oss/v1beta1
kind: Gslb
metadata:
name: test-gslb
spec:
resourceRef:
ingress:
matchLabels:
app: test-gslb
strategy:
type: roundRobin # Use a round robin load balancing strategy, when deciding which downstream clusters to route clients too
dnsTtlSeconds: 5
weight:
eu: 5
us: 5
39 changes: 39 additions & 0 deletions terratest/examples/roundrobin-weight1-ref-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-gslb
labels:
app: test-gslb
spec:
ingressClassName: nginx
rules:
- host: terratest-notfound.cloud.example.com # This is the GSLB enabled host that clients would use
http: # This section mirrors the same structure as that of an Ingress resource and will be used verbatim when creating the corresponding Ingress resource that will match the GSLB host
paths:
- path: /
pathType: Prefix
backend:
service:
name: non-existing-app # Gslb should reflect NotFound status
port:
name: http
- host: terratest-unhealthy.cloud.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: unhealthy-app # Gslb should reflect Unhealthy status
port:
name: http
- host: terratest-roundrobin.cloud.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-podinfo # Gslb should reflect Healthy status and create associated DNS records
port:
name: http
File renamed without changes.
12 changes: 12 additions & 0 deletions terratest/examples/roundrobin2-ref-gslb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: k8gb.absa.oss/v1beta1
kind: Gslb
metadata:
name: roundrobin-test-gslb
spec:
resourceRef:
ingress:
matchLabels:
app: roundrobin-test-gslb
strategy:
type: roundRobin # Use a round robin load balancing strategy, when deciding which downstream clusters to route clients too
dnsTtlSeconds: 5
19 changes: 19 additions & 0 deletions terratest/examples/roundrobin2-ref-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: roundrobin-test-gslb
labels:
app: roundrobin-test-gslb
spec:
ingressClassName: nginx
rules:
- host: roundrobin-test.cloud.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-podinfo # Gslb should reflect Healthy status and create associated DNS records
port:
name: http
Loading

0 comments on commit 1ed9519

Please sign in to comment.