Skip to content

Commit

Permalink
Add apiserver admission webhook template (#1354)
Browse files Browse the repository at this point in the history
* add admission webhook template
  • Loading branch information
Yisaer authored Dec 19, 2019
1 parent c19f09d commit 35db292
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 160 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{- if eq .Values.admissionWebhook.create true }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: tidb-admission-webhook
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
spec:
replicas: {{ .Values.admissionWebhook.replicas }}
selector:
matchLabels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
template:
metadata:
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
spec:
serviceAccountName: {{ .Values.admissionWebhook.serviceAccount }}
containers:
- name: admission-webhook
image: {{ .Values.operatorImage }}
imagePullPolicy: {{ .Values.imagePullPolicy | default "IfNotPresent" }}
command:
- /usr/local/bin/tidb-admission-webhook
{{- if eq .Values.admissionWebhook.apiservice.insecureSkipTLSVerify false }}
- --tls-cert-file=/var/serving-cert/cert.pem
- --tls-private-key-file=/var/serving-cert/key.pem
{{- end }}
{{- if eq .Values.admissionWebhook.apiservice.insecureSkipTLSVerify false }}
volumeMounts:
- mountPath: /var/serving-cert
name: serving-cert
{{- end }}
{{- if eq .Values.admissionWebhook.apiservice.insecureSkipTLSVerify false }}
volumes:
- name: serving-cert
secret:
defaultMode: 420
secretName: tidb-admission-webhook-certs
{{- end }}
{{- end }}
134 changes: 134 additions & 0 deletions charts/tidb-operator/templates/admission/admission-webhook-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{{- if and (eq .Values.admissionWebhook.create true) (eq .Values.admissionWebhook.rbac.create true) }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.admissionWebhook.serviceAccount }}
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Release.Name }}:tidb-admission-auth
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
rules:
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "create", "update", "delete"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create","patch","update"]
- apiGroups: ["apps"]
resources: ["statefulsets"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["pingcap.com"]
resources: ["tidbclusters"]
verbs: ["*"]
- apiGroups: ["apps.pingcap.com"]
resources: ["statefulsets"]
verbs: ["*"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Release.Name }}:tidb-admission-auth
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
subjects:
- kind: ServiceAccount
name: {{ .Values.admissionWebhook.serviceAccount }}
namespace: {{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Release.Name }}:tidb-admission-auth
---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Release.Name }}:tidb-apiserver-auth
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
rules:
- apiGroups: ["admission.tidb.pingcap.com"]
resources: ["admissionreviews"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Release.Name }}:tidb:extension-apiserver-authentication-reader
namespace: kube-system
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: {{ .Values.admissionWebhook.serviceAccount }}
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Release.Name }}:tidb-auth-delegator
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: {{ .Values.admissionWebhook.serviceAccount }}
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Release.Name }}:tidb-api-server-auth
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Release.Name }}:tidb-apiserver-auth
subjects:
- kind: User
name: kube-apiserver
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{- if eq .Values.admissionWebhook.create true }}
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
name: v1alpha1.admission.tidb.pingcap.com
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
spec:
{{- if eq .Values.admissionWebhook.apiservice.insecureSkipTLSVerify true }}
insecureSkipTLSVerify: true
{{- else }}
caBundle: {{ .Values.admissionWebhook.apiservice.cert | b64enc }}
{{- end }}
group: admission.tidb.pingcap.com
groupPriorityMinimum: 1000
versionPriority: 15
service:
name: tidb-admission-webhook
namespace: {{ .Release.Namespace }}
version: v1alpha1
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: validation-delete-tidb-admission-webhook-cfg
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
webhooks:
- name: delete.podadmission.tidb.pingcap.com
{{- if semverCompare ">=1.15-0" .Capabilities.KubeVersion.GitVersion }}
objectSelector:
matchLabels:
"app.kubernetes.io/managed-by": "tidb-operator"
"app.kubernetes.io/name": "tidb-cluster"
{{- end }}
failurePolicy: {{ .Values.admissionWebhook.failurePolicy.deletePod | default "Fail" }}
clientConfig:
service:
name: kubernetes
namespace: default
path: "/apis/admission.tidb.pingcap.com/v1alpha1/admissionreviews"
{{- if .Values.admissionWebhook.cabundle }}
caBundle: {{ .Values.admissionWebhook.cabundle | b64enc }}
{{- else }}
caBundle: null
{{- end }}
rules:
- operations: ["DELETE"]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: validation-create-tidb-admission-webhook-cfg
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
webhooks:
- name: create.podadmission.tidb.pingcap.com
{{- if semverCompare ">=1.15-0" .Capabilities.KubeVersion.GitVersion }}
objectSelector:
matchLabels:
"app.kubernetes.io/managed-by": "tidb-operator"
"app.kubernetes.io/name": "tidb-cluster"
{{- end }}
failurePolicy: {{ .Values.admissionWebhook.failurePolicy.createPod | default "Ignore" }}
clientConfig:
service:
name: kubernetes
namespace: default
path: "/apis/admission.tidb.pingcap.com/v1alpha1/admissionreviews"
{{- if .Values.admissionWebhook.cabundle }}
caBundle: {{ .Values.admissionWebhook.cabundle | b64enc }}
{{- else }}
caBundle: null
{{- end }}
rules:
- operations: ["CREATE"]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]
---
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{{- if and (eq .Values.admissionWebhook.enabled true) (eq .Values.admissionWebhook.certProvider "selfProvider") }}
{{- if and (eq .Values.admissionWebhook.create true) (eq .Values.admissionWebhook.apiservice.insecureSkipTLSVerify false ) }}
apiVersion: v1
data:
ca: {{ .Values.admissionWebhook.selfProvider.ca }}
cert.pem: {{ .Values.admissionWebhook.selfProvider.cert }}
key.pem: {{ .Values.admissionWebhook.selfProvider.key }}
kind: Secret
metadata:
name: tidb-admission-webhook-certs
Expand All @@ -13,5 +9,7 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-cert
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
type: Opaque
data:
cert.pem: {{ .Values.admissionWebhook.apiservice.cert | b64enc }}
key.pem: {{ .Values.admissionWebhook.apiservice.key | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if eq .Values.admissionWebhook.create true }}
apiVersion: v1
kind: Service
metadata:
name: tidb-admission-webhook
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
spec:
ports:
- name: https-webhook # optional
port: 443
targetPort: 443
selector:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: admission-webhook
{{- end }}

This file was deleted.

14 changes: 0 additions & 14 deletions charts/tidb-operator/templates/admission/certManager/issuer.yaml

This file was deleted.

Loading

0 comments on commit 35db292

Please sign in to comment.