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: add support to validating webhooks #352

Merged
merged 4 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
fail-fast: false
matrix:
enableAzureWorkloadIdentity: [false, true]
kubernetesVersion: [v1.25, v1.24, v1.23]
kubernetesVersion: [v1.26, v1.25, v1.24, v1.23]
include:
# Azure Workload Identity
- enableAzureWorkloadIdentity: true
Expand All @@ -48,6 +48,8 @@ jobs:
clientId: ""
# Images are defined on every Kind release
# See https://github.com/kubernetes-sigs/kind/releases
- 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 Expand Up @@ -87,6 +89,8 @@ jobs:
tag: main
metricsApiServer:
tag: main
webhooks:
tag: main
podIdentity:
azureWorkload:
enabled: ${{ matrix.enableAzureWorkloadIdentity }}
Expand All @@ -97,11 +101,19 @@ jobs:
maxUnavailable: 1
metricServer:
maxUnavailable: 1
webhooks:
maxUnavailable: 1
prometheus:
operator:
enabled: true
podMonitor:
enabled: true
webhooks:
enabled: true
serviceMonitor:
enabled: true
webhooks:
failurePolicy: Fail
EOF

- name: Install deps
Expand Down
158 changes: 104 additions & 54 deletions keda/README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions keda/templates/10-keda-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ rules:
- '*/scale'
verbs:
- '*'
{{- if .Values.certificates.autoGenerated }}
- apiGroups:
- admissionregistration.k8s.io
resources:
- validatingwebhookconfigurations
verbs:
- get
- list
- patch
- update
- watch
{{- end }}
- apiGroups:
- apps
resources:
Expand Down
26 changes: 26 additions & 0 deletions keda/templates/12-keda-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if .Values.certificates.autoGenerated }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
annotations:
{{- toYaml .Values.additionalAnnotations | nindent 4 }}
labels:
app.kubernetes.io/name: {{ .Values.operator.name }}
{{- include "keda.labels" . | indent 4 }}
creationTimestamp: null
name: {{ .Values.operator.name }}
namespace: {{ .Release.Namespace }}
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
{{- end -}}
20 changes: 20 additions & 0 deletions keda/templates/13-keda-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if .Values.certificates.autoGenerated }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
annotations:
{{- toYaml .Values.additionalAnnotations | nindent 4 }}
labels:
app.kubernetes.io/name: {{ .Values.operator.name }}
{{- include "keda.labels" . | indent 4 }}
name: {{ .Values.operator.name }}
namespace: {{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ .Values.operator.name }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccount.name }}
namespace: {{ .Release.Namespace }}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ spec:
- "--zap-log-level={{ .Values.logging.operator.level }}"
- "--zap-encoder={{ .Values.logging.operator.format }}"
- "--zap-time-encoding={{ .Values.logging.operator.timeEncoding }}"
- "--cert-dir={{ .Values.certificates.mountPath }}"
- "--enable-cert-rotation={{ .Values.certificates.autoGenerated }}"
- "--cert-secret-name={{ .Values.certificates.secretName }}"
- "--operator-service-name={{ .Values.operator.name }}"
- "--metrics-server-service-name={{ .Values.operator.name }}-metrics-apiserver"
- "--webhooks-service-name={{ .Values.webhooks.name }}"
{{- if .Values.prometheus.operator.enabled }}
- --metrics-bind-address=:{{ .Values.prometheus.operator.port }}
{{- end }}
Expand Down Expand Up @@ -119,7 +125,10 @@ spec:
{{- if .Values.env }}
{{- toYaml .Values.env | nindent 12 -}}
{{- end }}
volumeMounts:
volumeMounts:
- mountPath: {{ .Values.certificates.mountPath }}
name: certificates
readOnly: true
{{- if .Values.grpcTLSCertsSecret }}
- name: grpc-certs
mountPath: /grpccerts
Expand All @@ -130,14 +139,19 @@ spec:
{{- end }}
{{- if .Values.volumes.keda.extraVolumeMounts }}
{{- toYaml .Values.volumes.keda.extraVolumeMounts | nindent 12 }}
{{- end }}
{{- end }}
resources:
{{- if .Values.resources.operator }}
{{- toYaml .Values.resources.operator | nindent 12 }}
{{- else }}
{{- toYaml .Values.resources | nindent 12 }}
{{- end }}
volumes:
- name: certificates
secret:
defaultMode: 420
secretName: {{ .Values.certificates.secretName }}
optional: {{ .Values.certificates.autoGenerated }}
{{- if .Values.grpcTLSCertsSecret }}
- name: grpc-certs
secret:
Expand Down
7 changes: 7 additions & 0 deletions keda/templates/22-metrics-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ spec:
protocol: TCP
{{- end }}
volumeMounts:
- mountPath: {{ .Values.certificates.mountPath }}
name: certificates
readOnly: true
{{- if .Values.grpcTLSCertsSecret }}
- name: grpc-certs
mountPath: /grpccerts
Expand All @@ -146,6 +149,10 @@ spec:
{{- toYaml .Values.resources | nindent 12 }}
{{- end }}
volumes:
- name: certificates
secret:
defaultMode: 420
secretName: {{ .Values.certificates.secretName }}
{{- if .Values.grpcTLSCertsSecret }}
- name: grpc-certs
secret:
Expand Down
144 changes: 144 additions & 0 deletions keda/templates/30-webhooks-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.webhooks.name }}
namespace: {{ .Release.Namespace }}
annotations:
{{- toYaml .Values.additionalAnnotations | nindent 4 }}
labels:
app: {{ .Values.webhooks.name }}
name: {{ .Values.webhooks.name }}
app.kubernetes.io/name: {{ .Values.webhooks.name }}
{{- include "keda.labels" . | indent 4 }}
spec:
replicas: {{ .Values.webhooks.replicaCount}}
{{- with .Values.upgradeStrategy.webhooks }}
strategy:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
app: {{ .Values.webhooks.name }}
template:
metadata:
labels:
app: {{ .Values.webhooks.name }}
name: {{ .Values.webhooks.name }}
app.kubernetes.io/name: {{ .Values.webhooks.name }}
{{- include "keda.labels" . | indent 8 }}
annotations:
{{- if .Values.podAnnotations.webhooks }}
{{- toYaml .Values.podAnnotations.webhooks | nindent 8 }}
{{- end }}
{{- if .Values.additionalAnnotations }}
{{- toYaml .Values.additionalAnnotations | nindent 8 }}
{{- end }}
spec:
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName | quote }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ .Values.serviceAccount.name }}
automountServiceAccountToken: true
securityContext:
{{- if .Values.podSecurityContext.webhooks }}
{{- toYaml .Values.podSecurityContext.webhooks | nindent 8 }}
{{- else }}
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- end }}
containers:
- name: {{ .Values.webhooks.name }}
securityContext:
{{- if .Values.securityContext.webhooks }}
{{- toYaml .Values.securityContext.webhooks | nindent 12 }}
{{- else }}
{{- toYaml .Values.securityContext | nindent 12 }}
{{- end }}
image: "{{ .Values.image.webhooks.repository }}:{{ .Values.image.webhooks.tag | default .Chart.AppVersion }}"
command:
- /keda-admission-webhooks
args:
- "--zap-log-level={{ .Values.logging.webhooks.level }}"
- "--zap-encoder={{ .Values.logging.webhooks.format }}"
- "--zap-time-encoding={{ .Values.logging.webhooks.timeEncoding }}"
- "--cert-dir={{ .Values.certificates.mountPath }}"
{{- if .Values.prometheus.webhooks.enabled }}
- --metrics-bind-address=:{{ .Values.prometheus.webhooks.port }}
{{- end }}
{{- range $key, $value := .Values.extraArgs.webhooks }}
- --{{ $key }}={{ $value }}
{{- end }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 25
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 20
ports:
- containerPort: 9443
name: http
protocol: TCP
{{- if .Values.prometheus.webhooks.enabled }}
- containerPort: {{ .Values.prometheus.webhooks.port }}
name: metrics
protocol: TCP
{{- end }}
env:
- name: WATCH_NAMESPACE
value: {{ .Values.watchNamespace | quote }}
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if .Values.env }}
{{- toYaml .Values.env | nindent 12 -}}
{{- end }}
volumeMounts:
- mountPath: {{ .Values.certificates.mountPath }}
name: certificates
readOnly: true
{{- if .Values.volumes.webhooks.extraVolumeMounts }}
{{- toYaml .Values.volumes.webhooks.extraVolumeMounts | nindent 12 }}
{{- end }}
resources:
{{- if .Values.resources.webhooks }}
{{- toYaml .Values.resources.webhooks | nindent 12 }}
{{- else }}
{{- toYaml .Values.resources | nindent 12 }}
{{- end }}
volumes:
- name: certificates
secret:
defaultMode: 420
secretName: {{ .Values.certificates.secretName }}
{{- if .Values.volumes.webhooks.extraVolumes }}
{{- toYaml .Values.volumes.webhooks.extraVolumes | nindent 8 }}
{{- end }}
nodeSelector:
kubernetes.io/os: linux
{{- with .Values.nodeSelector }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.webhooks.affinity }}
affinity:
{{- toYaml .Values.webhooks.affinity | nindent 8 }}
{{- else if .Values.affinity }}
affinity:
{{- toYaml .Values.affinity | nindent 8 }}
{{- end }}
{{- with .Values.topologySpreadConstraints.webhooks }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
27 changes: 27 additions & 0 deletions keda/templates/31-webhooks-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Service
metadata:
annotations:
{{- if and .Values.prometheus.webhooks.enabled ( not .Values.prometheus.webhooks.serviceMonitor.enabled ) }}
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.prometheus.webhooks.port | quote }}
prometheus.io/path: "/metrics"
{{- end }}
labels:
app.kubernetes.io/name: {{ .Values.webhooks.name }}
{{- include "keda.labels" . | indent 4 }}
name: {{ .Values.webhooks.name }}
namespace: {{ .Release.Namespace }}
spec:
ports:
- name: http
port: 443
protocol: TCP
targetPort: 9443
{{- if .Values.prometheus.webhooks.enabled }}
- name: {{ .Values.prometheus.webhooks.serviceMonitor.port }}
port: {{ .Values.prometheus.webhooks.port }}
targetPort: {{ .Values.prometheus.webhooks.port }}
{{- end }}
selector:
app: {{ .Values.webhooks.name }}
30 changes: 30 additions & 0 deletions keda/templates/32-webhooks-poddisruptionbudget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- if or (or .Values.podDisruptionBudget.minAvailable .Values.podDisruptionBudget.maxUnavailable) .Values.podDisruptionBudget.webhooks }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
namespace: {{ .Release.Namespace }}
name: {{ .Values.webhooks.name }}
annotations:
{{- toYaml .Values.additionalAnnotations | nindent 4 }}
labels:
app.kubernetes.io/name: {{ .Values.serviceAccount.name }}
{{- include "keda.labels" . | indent 4 }}
spec:
{{- if .Values.podDisruptionBudget.minAvailable }}
minAvailable: {{ .Values.podDisruptionBudget.minAvailable }}
{{- end }}
{{- if .Values.podDisruptionBudget.maxUnavailable }}
maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }}
{{- end }}
{{- if .Values.podDisruptionBudget.webhooks }}
{{- if .Values.podDisruptionBudget.webhooks.minAvailable }}
minAvailable: {{ .Values.podDisruptionBudget.webhooks.minAvailable }}
{{- end }}
{{- if .Values.podDisruptionBudget.webhooks.maxUnavailable }}
maxUnavailable: {{ .Values.podDisruptionBudget.webhooks.maxUnavailable }}
{{- end }}
{{- end }}
selector:
matchLabels:
app: {{ .Values.webhooks.name }}
{{- end }}
Loading