Skip to content

Commit 46c2e11

Browse files
authored
Implementation for HAProxy backend (#13)
* Initial scaffold for HAProxy backend * Replace HAProxy API module * Change to my own haproxy client module. Add test * Implement HAProxy monitor and pool management * Update HAProxy test * Use validateCerts field. Fix some tests. * Set default values and validation for validatecerts and debug on haproxy * Improve makefile * Use LBMethod on HAProxy * Add HAProxy loading and validation to CRD * Clean tests * Make IP field minlength=1 since in HAproxy one can use * * Open and close provider connection when finalizing to delete resources * Implement HAProxy actions. Add tests. * Add HAProxy docs, config and docker-compose * Additional tests for HAProxy * Disable some tests that fail due our mock server * Re-enable secret test. No need to order HAProxy tests
1 parent ba91903 commit 46c2e11

25 files changed

+1415
-32
lines changed

Diff for: Makefile

+12-8
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ catalog-push: catalog-build ## Push a catalog image.
239239
$(MAKE) docker-push IMG=$(CATALOG_IMG)
240240

241241
.PHONY: olm-validate
242-
olm-validate: bundle-push ## Validates the bundle image.
242+
olm-validate: bundle-push catalog-push ## Validates the bundle image.
243243
operator-sdk bundle validate $(BUNDLE_IMG)
244244

245245
.PHONY: olm-run
@@ -250,23 +250,27 @@ else
250250
$(shell kind create cluster --name test-operator)
251251
endif
252252
kubectl config use-context kind-test-operator
253-
operator-sdk olm install --timeout=5m || true
253+
operator-sdk olm install --version=0.21.2 --timeout=5m || true
254254
operator-sdk run bundle $(BUNDLE_IMG) --timeout=5m
255-
kubectl create secret generic dummy-creds --from-literal=username=nsroot --from-literal=password=nsroot
255+
kubectl create secret generic dummy-creds --from-literal=username=admin --from-literal=password=admin
256256
kubectl apply -f config/samples/lb_v1_externalloadbalancer-dummy.yaml
257+
sleep 3
257258
kubectl get elb externalloadbalancer-master-dummy-test
258259
operator-sdk cleanup lbconfig-operator
259-
kubectl delete secret generic dummy-creds
260+
kubectl delete secret dummy-creds
260261
@echo "===================="
261262
@echo "Don't forget to teardown the KIND cluster with 'kind delete cluster --name test-operator'"
262263
@echo "===================="
263264

264265
.PHONY: scorecard-run
265266
scorecard-run: ## Runs the scorecard validation (depends on a KIND cluster)
266267
operator-sdk run bundle $(BUNDLE_IMG) --timeout=5m || true
267-
kubectl create namespace lbconfig-operator-system || true
268-
kubectl create secret generic -n lbconfig-operator-system dummy-creds --from-literal=username=admin --from-literal=password=admin || true
269-
operator-sdk scorecard ./bundle --wait-time 5m --service-account=lbconfig-operator-controller-manager --namespace=lbconfig-operator-system
268+
kubectl create secret generic dummy-creds --from-literal=username=admin --from-literal=password=admin || true
269+
operator-sdk scorecard ./bundle --wait-time 5m --service-account=lbconfig-operator-controller-manager
270+
271+
.PHONY: testenv-teardown
272+
testenv-teardown:
273+
kind delete cluster --name test-operator
270274

271275
.PHONY: dist
272-
dist: docker-cross deployment-manifests bundle-push catalog-push ## Build manifests and container image, pushing it to the registry
276+
dist: docker-cross bundle olm-validate ## Build manifests and container image, pushing it to the registry

Diff for: apis/externalloadbalancer/v1/externalloadbalancer_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type ExternalLoadBalancerSpec struct {
6161
// Vip is the Virtual IP configured in this LoadBalancer instance
6262
// +operator-sdk:csv:customresourcedefinitions:type=spec
6363
// +kubebuilder:validation:Required
64-
// +kubebuilder:validation:MinLength=7
64+
// +kubebuilder:validation:MinLength=1
6565
// +kubebuilder:validation:MaxLength=15
6666
Vip string `json:"vip"`
6767

@@ -127,7 +127,7 @@ type Provider struct {
127127
// Vendor is the backend provider vendor
128128
// +operator-sdk:csv:customresourcedefinitions:type=spec
129129
// +kubebuilder:validation:Required
130-
// +kubebuilder:validation:Enum=F5_BigIP;Citrix_ADC;Dummy
130+
// +kubebuilder:validation:Enum=Dummy;F5_BigIP;Citrix_ADC;HAProxy
131131
Vendor string `json:"vendor"`
132132

133133
// Host is the Load Balancer API IP or Hostname in URL format. Eg. `http://10.25.10.10`.

Diff for: bundle/manifests/lb.lbconfig.carlosedp.com_externalloadbalancers.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ spec:
160160
vendor:
161161
description: Vendor is the backend provider vendor
162162
enum:
163+
- Dummy
163164
- F5_BigIP
164165
- Citrix_ADC
165-
- Dummy
166+
- HAProxy
166167
type: string
167168
required:
168169
- creds
@@ -181,7 +182,7 @@ spec:
181182
description: Vip is the Virtual IP configured in this LoadBalancer
182183
instance
183184
maxLength: 15
184-
minLength: 7
185+
minLength: 1
185186
type: string
186187
required:
187188
- monitor
@@ -349,9 +350,10 @@ spec:
349350
vendor:
350351
description: Vendor is the backend provider vendor
351352
enum:
353+
- Dummy
352354
- F5_BigIP
353355
- Citrix_ADC
354-
- Dummy
356+
- HAProxy
355357
type: string
356358
required:
357359
- creds

Diff for: config/crd/bases/lb.lbconfig.carlosedp.com_externalloadbalancers.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ spec:
161161
vendor:
162162
description: Vendor is the backend provider vendor
163163
enum:
164+
- Dummy
164165
- F5_BigIP
165166
- Citrix_ADC
166-
- Dummy
167+
- HAProxy
167168
type: string
168169
required:
169170
- creds
@@ -182,7 +183,7 @@ spec:
182183
description: Vip is the Virtual IP configured in this LoadBalancer
183184
instance
184185
maxLength: 15
185-
minLength: 7
186+
minLength: 1
186187
type: string
187188
required:
188189
- monitor
@@ -350,9 +351,10 @@ spec:
350351
vendor:
351352
description: Vendor is the backend provider vendor
352353
enum:
354+
- Dummy
353355
- F5_BigIP
354356
- Citrix_ADC
355-
- Dummy
357+
- HAProxy
356358
type: string
357359
required:
358360
- creds
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: lb.lbconfig.carlosedp.com/v1
2+
kind: ExternalLoadBalancer
3+
metadata:
4+
name: externalloadbalancer-infra-haproxy-sample
5+
namespace: lbconfig-operator-system
6+
spec:
7+
vip: "192.168.1.42"
8+
nodelabels:
9+
node-role.kubernetes.io/control-plane: ""
10+
ports:
11+
- 80
12+
- 443
13+
monitor:
14+
path: "/healthz"
15+
port: 1936
16+
monitortype: http
17+
provider:
18+
vendor: HAProxy
19+
host: "http://127.0.0.1"
20+
port: 5555
21+
creds: haproxy-creds
22+
validatecerts: no
23+
debug: true
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: lb.lbconfig.carlosedp.com/v1
2+
kind: ExternalLoadBalancer
3+
metadata:
4+
name: externalloadbalancer-master-haproxy-sample
5+
namespace: lbconfig-operator-system
6+
spec:
7+
vip: "*"
8+
nodelabels:
9+
node-role.kubernetes.io/control-plane: ""
10+
ports:
11+
- 6443
12+
monitor:
13+
path: "/healthz"
14+
port: 6443
15+
monitortype: "https"
16+
provider:
17+
vendor: HAProxy
18+
host: "http://127.0.0.1"
19+
port: 5555
20+
creds: haproxy-creds
21+
validatecerts: no
22+
debug: true

Diff for: controllers/backend/backend_loader/backend_loader.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ import (
44
// Load backend modules to register them in the manager
55
_ "github.com/carlosedp/lbconfig-operator/controllers/backend/dummy"
66
_ "github.com/carlosedp/lbconfig-operator/controllers/backend/f5"
7+
_ "github.com/carlosedp/lbconfig-operator/controllers/backend/haproxy"
78
_ "github.com/carlosedp/lbconfig-operator/controllers/backend/netscaler"
89
)

0 commit comments

Comments
 (0)