Skip to content

Commit fb17e77

Browse files
authored
HTTPSO-based Routing Table (#669)
1 parent f06f975 commit fb17e77

File tree

135 files changed

+5634
-4992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+5634
-4992
lines changed

.devcontainer/Dockerfile

-8
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ RUN apt-get update \
5454
github.com/derekparker/delve/cmd/dlv 2>&1 \
5555
&& go install honnef.co/go/tools/cmd/staticcheck@latest \
5656
&& go install golang.org/x/tools/gopls@latest \
57-
# Protocol Buffer Compiler
58-
&& PROTOC_VERSION=21.9 \
59-
&& if [ $(dpkg --print-architecture) = "amd64" ]; then PROTOC_ARCH="x86_64"; else PROTOC_ARCH="aarch_64" ; fi \
60-
&& curl -LO "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-$PROTOC_ARCH.zip" \
61-
&& unzip "protoc-${PROTOC_VERSION}-linux-$PROTOC_ARCH.zip" -d $HOME/.local \
62-
&& mv $HOME/.local/bin/protoc /usr/local/bin/protoc \
63-
&& mv $HOME/.local/include/ /usr/local/bin/include/ \
64-
&& protoc --version \
6557
# Install golangci-lint
6658
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0 \
6759
#

.dockerignore

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
/target
1+
*.md
2+
*.yaml
3+
*.yml
4+
.*
5+
/LICENSE
26
/bin
3-
.git
4-
.gitignore
57
/charts
6-
/.vscode
7-
/bin
88
/cli
9-
/examples
9+
/config
1010
/docs
11-
/.envrc
12-
/.github
13-
/README.md
14-
/RELEASE_PROCESS.md
15-
CONTRIBUTING.md
11+
/examples
12+
/target
13+
/tests
1614
Dockerfile

.github/workflows/tests.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- name: Manifests
5454
run: make verify-manifests
5555

56+
- name: Mockgen
57+
run: make verify-mockgen
58+
5659
- name: Build
5760
run: ARCH=${{ matrix.name }} make build
5861

@@ -71,5 +74,5 @@ jobs:
7174
with:
7275
go-version: 1.19
7376
- name: Get golangci
74-
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
77+
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2
7578
- uses: pre-commit/[email protected]

.golangci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ issues:
5252
- gomnd
5353
- dupl
5454
- unparam
55+
# Exclude gci check for //+kubebuilder:scaffold:imports comments. Waiting to
56+
# resolve https://github.com/kedacore/keda/issues/4379
57+
- path: operator/controllers/http/suite_test.go
58+
linters:
59+
- gci
60+
- path: operator/main.go
61+
linters:
62+
- gci
5563
linters-settings:
5664
funlen:
5765
lines: 80

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This changelog keeps track of work items that have been completed and are ready
2626
- **General**: Automatically tag Docker image with commit SHA ([#567](https://github.com/kedacore/http-add-on/issues/567))
2727
- **RBAC**: Introduce fine-grained permissions per component and reduce required permissions ([#612](https://github.com/kedacore/http-add-on/issues/612))
2828
- **Operator**: Migrate project to Kubebuilder v3 ([#625](https://github.com/kedacore/http-add-on/issues/625))
29+
- **Routing**: New routing table implementation that relies on the live state of HTTPScaledObjects on the K8s Cluster instead of a ConfigMap that is updated periodically ([#605](https://github.com/kedacore/http-add-on/issues/605))
2930

3031
### Fixes
3132

Makefile

+22-15
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ GIT_COMMIT_SHORT ?= $(shell git rev-parse --short HEAD)
3434

3535
# Build targets
3636

37-
build-operator: proto-gen
38-
${GO_BUILD_VARS} go build -ldflags $(GO_LDFLAGS) -a -o bin/operator ./operator
37+
build-operator:
38+
${GO_BUILD_VARS} go build -ldflags $(GO_LDFLAGS) -trimpath -a -o bin/operator ./operator
3939

40-
build-interceptor: proto-gen
41-
${GO_BUILD_VARS} go build -ldflags $(GO_LDFLAGS) -a -o bin/interceptor ./interceptor
40+
build-interceptor:
41+
${GO_BUILD_VARS} go build -ldflags $(GO_LDFLAGS) -trimpath -a -o bin/interceptor ./interceptor
4242

43-
build-scaler: proto-gen
44-
${GO_BUILD_VARS} go build -ldflags $(GO_LDFLAGS) -a -o bin/scaler ./scaler
43+
build-scaler:
44+
${GO_BUILD_VARS} go build -ldflags $(GO_LDFLAGS) -trimpath -a -o bin/scaler ./scaler
4545

4646
build: build-operator build-interceptor build-scaler
4747

@@ -85,9 +85,9 @@ publish-multiarch: publish-operator-multiarch publish-interceptor-multiarch publ
8585

8686
# Development
8787

88-
generate: codegen manifests ## Generate code and manifests.
88+
generate: codegen manifests mockgen ## Generate code, manifests, and mocks.
8989

90-
verify: verify-codegen verify-manifests ## Verify code and manifests.
90+
verify: verify-codegen verify-manifests verify-mockgen ## Verify code, manifests, and mocks.
9191

9292
codegen: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
9393
$(CONTROLLER_GEN) object:headerFile='hack/boilerplate.go.txt' paths='./...'
@@ -104,18 +104,24 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
104104
verify-manifests: ## Verify manifests are up to date.
105105
./hack/verify-manifests.sh
106106

107+
mockgen: ## Generate mock implementations of Go interfaces.
108+
./hack/update-mockgen.sh
109+
110+
verify-mockgen: ## Verify mocks are up to date.
111+
./hack/verify-mockgen.sh
112+
107113
fmt: ## Run go fmt against code.
108114
go fmt ./...
109115

110116
vet: ## Run go vet against code.
111117
go vet ./...
112118

119+
lint: ## Run golangci-lint against code.
120+
golangci-lint run
121+
113122
pre-commit: ## Run static-checks.
114123
pre-commit run --all-files
115124

116-
proto-gen: protoc-gen-go ## Scaler protobuffers
117-
protoc --proto_path=proto scaler.proto --go_out=proto --go-grpc_out=proto
118-
119125
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
120126
controller-gen: ## Download controller-gen locally if necessary.
121127
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-tools/cmd/[email protected]
@@ -124,10 +130,6 @@ KUSTOMIZE = $(shell pwd)/bin/kustomize
124130
kustomize: ## Download kustomize locally if necessary.
125131
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/kustomize/kustomize/[email protected]
126132

127-
protoc-gen-go: ## Download protoc-gen-go
128-
go install google.golang.org/protobuf/cmd/[email protected]
129-
go install google.golang.org/grpc/cmd/[email protected]
130-
131133
deploy: manifests kustomize ## Deploy to the K8s cluster specified in ~/.kube/config.
132134
cd config/interceptor && \
133135
$(KUSTOMIZE) edit set image ghcr.io/kedacore/http-add-on-interceptor=${IMAGE_INTERCEPTOR_VERSIONED_TAG}
@@ -142,3 +144,8 @@ deploy: manifests kustomize ## Deploy to the K8s cluster specified in ~/.kube/co
142144

143145
undeploy:
144146
$(KUSTOMIZE) build config/default | kubectl delete -f -
147+
148+
kind-load:
149+
kind load docker-image ghcr.io/kedacore/http-add-on-operator:${VERSION}
150+
kind load docker-image ghcr.io/kedacore/http-add-on-interceptor:${VERSION}
151+
kind load docker-image ghcr.io/kedacore/http-add-on-scaler:${VERSION}

config/crd/bases/http.keda.sh_httpscaledobjects.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ spec:
8888
type: object
8989
scaleTargetRef:
9090
description: The name of the deployment to route HTTP requests to
91-
(and to autoscale). Either this or Image must be set
91+
(and to autoscale).
9292
properties:
9393
deployment:
9494
description: The name of the deployment to scale according to

config/interceptor/admin.service.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# TODO(pedrotorres): remove after implementing new routing table
21
apiVersion: v1
32
kind: Service
43
metadata:

config/interceptor/deployment.yaml

+13-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,18 @@ spec:
5353
- name: KEDA_HTTP_EXPECT_CONTINUE_TIMEOUT
5454
value: "1s"
5555
ports:
56-
# TODO(pedrotorres): remove after implementing new routing table
5756
- name: admin
5857
containerPort: 9090
5958
- name: proxy
6059
containerPort: 8080
60+
livenessProbe:
61+
httpGet:
62+
path: /livez
63+
port: proxy
64+
readinessProbe:
65+
httpGet:
66+
path: /readyz
67+
port: proxy
6168
# TODO(pedrotorres): set better default values avoiding overcommitment
6269
resources:
6370
requests:
@@ -69,11 +76,12 @@ spec:
6976
securityContext:
7077
allowPrivilegeEscalation: false
7178
readOnlyRootFilesystem: true
72-
runAsNonRoot: true
7379
capabilities:
7480
drop:
75-
- ALL
76-
seccompProfile:
77-
type: RuntimeDefault
81+
- ALL
82+
securityContext:
83+
runAsNonRoot: true
84+
seccompProfile:
85+
type: RuntimeDefault
7886
serviceAccountName: interceptor
7987
terminationGracePeriodSeconds: 10

config/interceptor/role.yaml

+2-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ rules:
1212
- get
1313
- list
1414
- watch
15-
---
16-
apiVersion: rbac.authorization.k8s.io/v1
17-
kind: Role
18-
metadata:
19-
name: interceptor
20-
namespace: keda
21-
rules:
2215
- apiGroups:
23-
- ""
16+
- http.keda.sh
2417
resources:
25-
- configmaps
18+
- httpscaledobjects
2619
verbs:
2720
- get
2821
- list

config/interceptor/role_binding.yaml

-12
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,3 @@ roleRef:
1010
subjects:
1111
- kind: ServiceAccount
1212
name: interceptor
13-
---
14-
apiVersion: rbac.authorization.k8s.io/v1
15-
kind: RoleBinding
16-
metadata:
17-
name: interceptor
18-
roleRef:
19-
apiGroup: rbac.authorization.k8s.io
20-
kind: Role
21-
name: interceptor
22-
subjects:
23-
- kind: ServiceAccount
24-
name: interceptor

config/operator/deployment.yaml

+17-13
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,28 @@ spec:
2727
# TODO(pedrotorres): remove after implementing new routing table
2828
- --admin-port=9090
2929
env:
30-
# TODO(pedrotorres): remove after implementing new routing table
31-
- name: KEDAHTTP_INTERCEPTOR_SERVICE
32-
value: "keda-http-add-on-interceptor-admin"
3330
- name: KEDAHTTP_OPERATOR_EXTERNAL_SCALER_SERVICE
3431
value: "keda-http-add-on-external-scaler"
3532
- name: KEDAHTTP_OPERATOR_EXTERNAL_SCALER_PORT
3633
value: "9090"
37-
- name: KEDAHTTP_INTERCEPTOR_ADMIN_PORT
38-
value: "9090"
39-
- name: KEDAHTTP_INTERCEPTOR_PROXY_PORT
40-
value: "8080"
4134
- name: KEDA_HTTP_OPERATOR_NAMESPACE
4235
value: "keda"
4336
- name: KEDA_HTTP_OPERATOR_WATCH_NAMESPACE
4437
value: ""
4538
# TODO(pedrotorres): remove after implementing new routing table
4639
ports:
47-
- name: admin
48-
containerPort: 9090
40+
- name: metrics
41+
containerPort: 8080
42+
- name: probes
43+
containerPort: 8081
44+
livenessProbe:
45+
httpGet:
46+
path: /healthz
47+
port: probes
48+
readinessProbe:
49+
httpGet:
50+
path: /readyz
51+
port: probes
4952
# TODO(pedrotorres): set better default values avoiding overcommitment
5053
resources:
5154
requests:
@@ -57,11 +60,12 @@ spec:
5760
securityContext:
5861
allowPrivilegeEscalation: false
5962
readOnlyRootFilesystem: true
60-
runAsNonRoot: true
6163
capabilities:
6264
drop:
63-
- ALL
64-
seccompProfile:
65-
type: RuntimeDefault
65+
- ALL
66+
securityContext:
67+
runAsNonRoot: true
68+
seccompProfile:
69+
type: RuntimeDefault
6670
serviceAccountName: operator
6771
terminationGracePeriodSeconds: 10

config/scaler/deployment.yaml

+12-8
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ spec:
2323
- name: scaler
2424
image: ghcr.io/kedacore/http-add-on-scaler
2525
env:
26-
# TODO(pedrotorres): remove after implementing new routing table
2726
- name: KEDA_HTTP_SCALER_TARGET_ADMIN_DEPLOYMENT
2827
value: "keda-http-add-on-interceptor"
2928
- name: KEDA_HTTP_SCALER_PORT
3029
value: "9090"
31-
- name: KEDA_HTTP_HEALTH_PORT
32-
value: "9091"
3330
- name: KEDA_HTTP_SCALER_TARGET_ADMIN_NAMESPACE
3431
value: "keda"
3532
# TODO(pedrotorres): remove after implementing new routing table
@@ -43,8 +40,14 @@ spec:
4340
ports:
4441
- name: grpc
4542
containerPort: 9090
46-
- name: health
47-
containerPort: 9091
43+
livenessProbe:
44+
grpc:
45+
port: 9090
46+
service: liveness
47+
readinessProbe:
48+
grpc:
49+
port: 9090
50+
service: readiness
4851
# TODO(pedrotorres): set better default values avoiding overcommitment
4952
resources:
5053
requests:
@@ -56,11 +59,12 @@ spec:
5659
securityContext:
5760
allowPrivilegeEscalation: false
5861
readOnlyRootFilesystem: true
59-
runAsNonRoot: true
6062
capabilities:
6163
drop:
6264
- ALL
63-
seccompProfile:
64-
type: RuntimeDefault
65+
securityContext:
66+
runAsNonRoot: true
67+
seccompProfile:
68+
type: RuntimeDefault
6569
serviceAccountName: scaler
6670
terminationGracePeriodSeconds: 10

config/scaler/role.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ rules:
2020
- get
2121
- list
2222
- watch
23+
- apiGroups:
24+
- http.keda.sh
25+
resources:
26+
- httpscaledobjects
27+
verbs:
28+
- get
29+
- list
30+
- watch
2331
---
2432
apiVersion: rbac.authorization.k8s.io/v1
2533
kind: Role

config/scaler/service.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,3 @@ spec:
88
protocol: TCP
99
port: 9090
1010
targetPort: grpc
11-
- name: health
12-
protocol: TCP
13-
port: 9091
14-
targetPort: health

0 commit comments

Comments
 (0)