From ba001b4c200a0c3cd0c09bd5d00caef5e80d40ce Mon Sep 17 00:00:00 2001 From: ston1th Date: Tue, 28 Sep 2021 22:33:43 +0200 Subject: [PATCH] minor changes --- Makefile | 13 +++++-------- pkg/api/v1/schema/schema.go | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index e603d46..466131d 100644 --- a/Makefile +++ b/Makefile @@ -12,16 +12,16 @@ all: $(PROGRAM) setup: $(CC) get -u github.com/client9/misspell -release: clean generate gofmt codeqa +release: clean gofmt codeqa $(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS) $(CMD) release-vendor: clean generate gofmt codeqa $(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS) $(CMD) -vendor: clean generate gofmt +vendor: clean gofmt $(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS) $(CMD) -$(PROGRAM): clean generate gofmt +$(PROGRAM): clean gofmt $(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS) $(CMD) clean: @@ -29,9 +29,6 @@ clean: codeqa: misspell golint test -generate: - $(CC) generate - gofmt: gofmt -w pkg/ cmd/ @@ -39,7 +36,7 @@ golint: $(GOPATH)/bin/golint . misspell: - $(GOPATH)/bin/misspell pkg/* cmd/* Makefile README.md vipman.yaml + $(GOPATH)/bin/misspell pkg/* cmd/* Makefile README.md haproxy-lb.yaml test: ifeq ($(shell go env GOARCH), $(shell go env GOHOSTARCH)) @@ -52,4 +49,4 @@ else $(info skipping tests of other platforms) endif -.PHONY: setup release release-vendor vendor build clean codeqa generate gofmt golint misspell test +.PHONY: setup release release-vendor vendor build clean codeqa gofmt golint misspell test diff --git a/pkg/api/v1/schema/schema.go b/pkg/api/v1/schema/schema.go index 6990495..7b40c58 100644 --- a/pkg/api/v1/schema/schema.go +++ b/pkg/api/v1/schema/schema.go @@ -14,6 +14,13 @@ healthCheckNodePort const Version = "v1" +type ProxyProtocol string + +const ( + ProxyProtocolV1 ProxyProtocol = "v1" + ProxyProtocolV2 = "v2" +) + type LoadBalancer struct { Name string `json:"name,omitempty"` IP string `json:"ip,omitempty"` @@ -29,11 +36,11 @@ func NewLoadBalancerFromBytes(b []byte) (lb *LoadBalancer, err error) { } type Options struct { - Frontend []string `json:"frontend,omitempty"` - Backend []string `json:"backend,omitempty"` - ProxyProtocol string `json:"proxyProtocol,omitempty"` - CheckProxyProtocol bool `json:"checkProxyProtocol,omitempty"` - DefaultServer string `json:"defaultServer,omitempty` + Frontend []string `json:"frontend,omitempty"` + Backend []string `json:"backend,omitempty"` + ProxyProtocol ProxyProtocol `json:"proxyProtocol,omitempty"` + CheckProxyProtocol bool `json:"checkProxyProtocol,omitempty"` + DefaultServer string `json:"defaultServer,omitempty` } type Port struct { @@ -144,6 +151,11 @@ func (lb LoadBalancer) ValidateServer() error { if lb.CIDR == "" { return errors.New("LoadBalancer.CIDR can not be empty") } + switch lb.Options.ProxyProtocol { + case "", ProxyProtocolV1, ProxyProtocolV2: + default: + return errors.New(`LoadBalancer.Options.ProxyProtocol invalid value. (allowed: "", "v1", "v2")`) + } err := lb.ValidateClient() if err != nil { return err