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

feat: New validation hook to check if scale target is already managed #4001

Merged
merged 42 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b5bc368
feat: New validation hook to check if scale target is already managed
JorTurFer Dec 30, 2022
659925c
update missing changes
JorTurFer Dec 30, 2022
b3f8312
add prometheus metrics to webhooks
JorTurFer Dec 31, 2022
d6e5cf7
fix test
JorTurFer Dec 31, 2022
061ddf2
fix styles
JorTurFer Jan 1, 2023
3989767
remove unused parameter
JorTurFer Jan 1, 2023
c4a8359
use k8s 1.26 for smoke test
JorTurFer Jan 2, 2023
bfcd999
fix style
JorTurFer Jan 2, 2023
15f2217
add webhook logs to e2e output
JorTurFer Jan 2, 2023
caabea1
apply feedback
JorTurFer Jan 2, 2023
462dd90
use kedautil.GetPodNamespace() in adapter
JorTurFer Jan 2, 2023
0b92987
use gvkr parser for webhooks
JorTurFer Jan 2, 2023
7a56a8d
remove the empty secret as requirement
JorTurFer Jan 3, 2023
8f62b29
update go.sum
JorTurFer Jan 3, 2023
01cbb32
update errors
JorTurFer Jan 3, 2023
ae09572
update pictures
JorTurFer Jan 3, 2023
323bce8
update external name to use admission-webhooks
JorTurFer Jan 3, 2023
7fac0f3
update bin output
JorTurFer Jan 3, 2023
a7d506b
add a core release
JorTurFer Jan 3, 2023
fc4ac7d
split rbac
JorTurFer Jan 3, 2023
6becd32
update changelog
JorTurFer Jan 3, 2023
001fdc5
fix styles
JorTurFer Jan 3, 2023
acddb50
fix typo
JorTurFer Jan 3, 2023
69bae43
update parameter name
JorTurFer Jan 4, 2023
954550f
update docs
JorTurFer Jan 4, 2023
b2482d7
update rbac
JorTurFer Jan 4, 2023
3601109
update contributing
JorTurFer Jan 4, 2023
de9b9fb
add cpu/memory validation
JorTurFer Jan 5, 2023
c4677ca
solve styles
JorTurFer Jan 5, 2023
9476f66
fix errors
JorTurFer Jan 5, 2023
281cdab
update arch picture
JorTurFer Jan 6, 2023
232e18f
use my own fork temporally
JorTurFer Jan 7, 2023
6f7839d
move to the operator the cert generation
JorTurFer Jan 7, 2023
d557d74
fix influx test
JorTurFer Jan 7, 2023
d24c8b8
fix influx test
JorTurFer Jan 7, 2023
f1f3b99
fix matching errors
JorTurFer Jan 7, 2023
925ab2c
undo incorrect change
JorTurFer Jan 8, 2023
2da02f5
remove keda-architecture ppt in favour of keda-docs schematics.pptx
JorTurFer Jan 9, 2023
f19569c
Update Makefile
JorTurFer Jan 9, 2023
04a24f4
apply feedback
JorTurFer Jan 9, 2023
c7eb052
Merge branch 'main' into validation-hook
JorTurFer Jan 9, 2023
d3a3efa
add a deletion note in release yaml
JorTurFer Jan 9, 2023
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
13 changes: 8 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ RUN apt-get update \
# Enable go modules
ENV GO111MODULE=on

ENV OPERATOR_RELEASE_VERSION=v1.0.1
RUN curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_RELEASE_VERSION}/operator-sdk-${OPERATOR_RELEASE_VERSION}-x86_64-linux-gnu \
&& chmod +x operator-sdk-${OPERATOR_RELEASE_VERSION}-x86_64-linux-gnu \
ENV OPERATOR_RELEASE_VERSION=v1.26.0
RUN ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac) \
&& OS=$(uname | awk '{print tolower($0)}') \
&& OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_RELEASE_VERSION} \
&& curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH} \
&& chmod +x operator-sdk_${OS}_${ARCH} \
&& mkdir -p /usr/local/bin/ \
&& cp operator-sdk-${OPERATOR_RELEASE_VERSION}-x86_64-linux-gnu /usr/local/bin/operator-sdk \
&& rm operator-sdk-${OPERATOR_RELEASE_VERSION}-x86_64-linux-gnu
&& cp operator-sdk_${OS}_${ARCH} /usr/local/bin/operator-sdk \
&& rm operator-sdk_${OS}_${ARCH}
12 changes: 12 additions & 0 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,15 @@ jobs:
asset_path: keda-${{ steps.get_version.outputs.VERSION }}.yaml
asset_name: keda-${{ steps.get_version.outputs.VERSION }}.yaml
asset_content_type: application/x-yaml

# Upload core deployment YAML file to GitHub release
- name: Upload Deployment YAML file
id: upload-deployment-yaml
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: https://uploads.github.com/repos/kedacore/keda/releases/${{ steps.get-release-info.outputs.id }}/assets?name=keda-${{ steps.get_version.outputs.VERSION }}-core.yaml
asset_path: keda-${{ steps.get_version.outputs.VERSION }}-core.yaml
asset_name: keda-${{ steps.get_version.outputs.VERSION }}-core.yaml
asset_content_type: application/x-yaml
4 changes: 2 additions & 2 deletions .github/workflows/template-arm64-smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
uses: kedacore/keda/.github/workflows/template-smoke-tests.yml@main
with:
runs-on: ARM64
kubernetesVersion: v1.25
kindImage: kindest/node:v1.25.0@sha256:428aaa17ec82ccde0131cb2d1ca6547d13cf5fdabcc0bbecf749baa935387cbf
kubernetesVersion: v1.26
kindImage: kindest/node:v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352
4 changes: 3 additions & 1 deletion .github/workflows/template-versions-smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ jobs:
strategy:
fail-fast: false
matrix:
kubernetesVersion: [v1.25, v1.24, v1.23]
kubernetesVersion: [v1.26, v1.25, v1.24, v1.23]
include:
- kubernetesVersion: v1.26
kindImage: kindest/node:v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352
- kubernetesVersion: v1.25
kindImage: kindest/node:v1.25.0@sha256:428aaa17ec82ccde0131cb2d1ca6547d13cf5fdabcc0bbecf749baa935387cbf
- kubernetesVersion: v1.24
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ apiserver.local.config/

cover.out

# GO debug binary
# GO debug binaries
cmd/manager/debug.test
__debug_bin

# GO Test result
report.xml
100 changes: 80 additions & 20 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Build & Deploy KEDA](#build--deploy-keda)
- [Building](#building)
- [Quick start with Visual Studio Code Remote - Containers](#quick-start-with-visual-studio-code-remote---containers)
- [Locally directly](#locally-directly)
- [Deploying](#deploying)
- [Custom KEDA locally outside cluster](#custom-keda-locally-outside-cluster)
- [Custom KEDA as an image](#custom-keda-as-an-image)
- [Miscellaneous](#miscellaneous)
- [Setting log levels](#setting-log-levels)
- [KEDA Operator logging](#keda-operator-logging)
- [Metrics Server logging](#metrics-server-logging)
- [Building](#building)
- [Quick start with Visual Studio Code Remote - Containers](#quick-start-with-visual-studio-code-remote---containers)
- [Locally directly](#locally-directly)
- [Deploying](#deploying)
- [Custom KEDA locally outside cluster](#custom-keda-locally-outside-cluster)
- [Custom KEDA as an image](#custom-keda-as-an-image)
- [Debugging with VS Code](#debugging-with-vs-code)
- [Operator](#operator)
- [Metrics server](#metrics-server)
- [Admission Webhooks](#admission-webhooks)
- [Miscellaneous](#miscellaneous)
- [How to use devcontainers and a local Kubernetes cluster](#how-to-use-devcontainers-and-a-local-kubernetes-cluster)
- [Setting log levels](#setting-log-levels)
- [KEDA Operator and Admission webhooks logging](#keda-operator-and-admission-webhooks-logging)
- [Metrics Server logging](#metrics-server-logging)
- [CPU/Memory Profiling](#cpumemory-profiling)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -137,7 +142,7 @@ Follow these instructions if you want to debug the KEDA operator using VS Code.
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/main.go",
"program": "${workspaceFolder}/cmd/operator/main.go",
"env": {
"WATCH_NAMESPACE": "",
"KEDA_CLUSTER_OBJECT_NAMESPACE": "keda"
Expand Down Expand Up @@ -173,7 +178,7 @@ Follow these instructions if you want to debug the KEDA metrics server using VS
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/adapter/main.go",
"program": "${workspaceFolder}/cmd/adapter/main.go",
"env": {
"WATCH_NAMESPACE": "",
"KEDA_CLUSTER_OBJECT_NAMESPACE": "keda"
Expand Down Expand Up @@ -223,6 +228,64 @@ You can query list metrics executing `curl --insecure https://localhost:6443/api

If you prefer to use an authenticated user, you can use a user or service account with access over external metrics API adding their token as authorization header in `curl`, ie: `curl -H "Authorization:Bearer TOKEN" --insecure https://localhost:6443/apis/external.metrics.k8s.io/v1beta1/`

### Admission Webhooks

Follow these instructions if you want to debug the KEDA webhook using VS Code.

1. Create a `launch.json` file inside the `.vscode/` folder in the repo with the following configuration:
```json
{
"configurations": [
{
"name": "Launch webhooks",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/webhooks/main.go",
"env": {
"WATCH_NAMESPACE": "",
"KEDA_CLUSTER_OBJECT_NAMESPACE": "keda"
},
"args": [
"--zap-log-level=debug",
"--zap-encoder=console",
"--zap-time-encoding=rfc3339"
]
},
]
}
```
Refer to [this](https://code.visualstudio.com/docs/editor/debugging) for more information about debugging with VS Code.
2. Expose your local instance to internet. If you can't expose it directly, you can use something like [localtunnel](https://theboroer.github.io/localtunnel-www/) using the command `lt --port 9443 --local-https --allow-invalid-cert` after installing the tool.

3. Update the `admissing_webhooks.yaml` in `config/webhooks`, replacing the section (but not commiting this change)
```yaml
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
service:
name: keda-admission-webhooks
namespace: keda
path: /validate-keda-sh-v1alpha1-scaledobject
```
with the section:
```yaml
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
url: "https://${YOUR_URL}/validate-keda-sh-v1alpha1-scaledobject"
```
**Note:** You could need to define also the key `caBundle` with the CA bundle encoded in base64 if the cluster can get it during the manifest apply (this happens with localtunnel for instance)

4. Deploy CRDs and KEDA into `keda` namespace
```bash
make deploy
```
5. Set breakpoints in the code as required.
6. Select `Run > Start Debugging` or press `F5` to start debugging.

## Miscellaneous

### How to use devcontainers and a local Kubernetes cluster
Expand All @@ -236,24 +299,21 @@ To solve this and be able to work with devcontainers and a local cluster, you sh
You can change default log levels for both KEDA Operator and Metrics Server. KEDA Operator uses
[Operator SDK logging](https://sdk.operatorframework.io/docs/building-operators/golang/references/logging/) mechanism.

### KEDA Operator logging
### KEDA Operator and Admission webhooks logging

To change the logging level, find `--zap-log-level=` argument in Operator Deployment section in `config/manager/manager.yaml` file,
modify its value and redeploy.
To change the logging level, find `--zap-log-level=` argument in Operator Deployment section in `config/manager/manager.yaml` file or in Webhooks Deployment section in `config/webhooks/webhooks.yaml` file, modify its value and redeploy.

Allowed values are `debug`, `info`, `error`, or an integer value greater than `0`, specified as string

Default value: `info`

To change the logging format, find `--zap-encoder=` argument in Operator Deployment section in `config/manager/manager.yaml` file,
modify its value and redeploy.
To change the logging format, find `--zap-encoder=` argument in Operator Deployment section in `config/manager/manager.yaml` file or in Webhooks Deployment section in `config/webhooks/webhooks.yaml` file, modify its value and redeploy.

Allowed values are `json` and `console`

Default value: `console`

To change the logging time encoding, find `--zap-time-encoding=` argument in Operator Deployment section in `config/manager/manager.yaml` file,
modify its value and redeploy.
To change the logging time encoding, find `--zap-time-encoding=` argument in Operator Deployment section in `config/manager/manager.yaml` file or in Webhooks Deployment section in `config/webhooks/webhooks.yaml` file, modify its value and redeploy.

Allowed values are `epoch`, `millis`, `nano`, `iso8601`, `rfc3339` or `rfc3339nano`

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
Here is an overview of all **stable** additions:

- **General**: Introduce new ArangoDB Scaler ([#4000](https://github.com/kedacore/keda/issues/4000))
- **General**: Introduce admission webhooks to automatically validate resource changes to prevent misconfiguration and enforce best practices. ([#3755](https://github.com/kedacore/keda/issues/3755))
JorTurFer marked this conversation as resolved.
Show resolved Hide resolved

Here is an overview of all new **experimental** features:

Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ There are many areas we can use contributions - ranging from code, documentation
- [Making Breaking Changes](#making-breaking-changes)
- [Contributing Scalers](#contributing-scalers)
- [Testing](#testing)
- [Contributing webhooks](#contributing-webhooks)
- [Changelog](#changelog)
- [Including Documentation Changes](#including-documentation-changes)
- [Creating and building a local environment](#creating-and-building-a-local-environment)
Expand Down Expand Up @@ -51,6 +52,10 @@ It is mandatory to provide end-to-end (e2e) tests for new scaler. For more infor
check the [test documentation](./tests/README.md). Those tests are run nightly on our
[CI system](https://github.com/kedacore/keda/actions?query=workflow%3A%22nightly+e2e+test%22).

## Contributing webhooks

Another easy way to contribute is improving the validations to avoid misconfigurations. New rules can be added in the proper type's webhooks file (`apis/keda/v1alpha1/*_webhook.go`).

## Changelog

Every change should be added to our changelog under `Unreleased` which is located in `CHANGELOG.md`. This helps us keep track of all changes in a given release.
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ COPY Makefile Makefile
# Copy the go source
COPY hack/ hack/
COPY version/ version/
COPY main.go main.go
COPY adapter/ adapter/
COPY cmd/ cmd/
COPY apis/ apis/
COPY controllers/ controllers/
COPY pkg/ pkg/
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile.adapter
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ COPY Makefile Makefile
# Copy the go source
COPY hack/ hack/
COPY version/ version/
COPY main.go main.go
COPY adapter/ adapter/
COPY cmd/ cmd/
COPY apis/ apis/
COPY controllers/ controllers/
COPY pkg/ pkg/
Expand Down
37 changes: 37 additions & 0 deletions Dockerfile.webhooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM ghcr.io/kedacore/build-tools:1.18.8 AS builder

ARG BUILD_VERSION=main
ARG GIT_COMMIT=HEAD
ARG GIT_VERSION=main

WORKDIR /workspace

COPY Makefile Makefile

# Copy the go source
COPY hack/ hack/
COPY version/ version/
COPY cmd/ cmd/
COPY apis/ apis/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY vendor/ vendor/
COPY go.mod go.mod
COPY go.sum go.sum

# Build
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
ARG TARGETOS
ARG TARGETARCH
RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH make webhooks

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/bin/keda-admission-webhooks .
# 65532 is numeric for nonroot
USER 65532:65532

ENTRYPOINT ["/keda-admission-webhooks", "--zap-log-level=info", "--zap-encoder=console"]
Loading