Skip to content

Commit 5593a3f

Browse files
author
shenchangqing
committed
fix
1 parent b18e034 commit 5593a3f

File tree

4 files changed

+148
-6
lines changed

4 files changed

+148
-6
lines changed

1.txt

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
labels:
5+
app: k8s-webhook
6+
name: k8s-webhook
7+
namespace: default
8+
---
9+
apiVersion: rbac.authorization.k8s.io/v1
10+
kind: ClusterRole
11+
metadata:
12+
labels:
13+
app: k8s-webhook
14+
name: k8s-webhook
15+
rules:
16+
- apiGroups:
17+
- ""
18+
resources:
19+
- pods
20+
verbs:
21+
- get
22+
- apiGroups:
23+
- ""
24+
resources:
25+
- secrets
26+
verbs:
27+
- get
28+
- apiGroups:
29+
- admissionregistration.k8s.io
30+
resources:
31+
- validatingwebhookconfigurations
32+
- mutatingwebhookconfigurations
33+
verbs:
34+
- create
35+
- apiGroups:
36+
- cert-manager.io
37+
resources:
38+
- clusterissuers
39+
- certificates
40+
verbs:
41+
- create
42+
---
43+
apiVersion: rbac.authorization.k8s.io/v1
44+
kind: ClusterRoleBinding
45+
metadata:
46+
labels:
47+
app: k8s-webhook
48+
name: k8s-webhook
49+
roleRef:
50+
apiGroup: rbac.authorization.k8s.io
51+
kind: ClusterRole
52+
name: k8s-webhook
53+
subjects:
54+
- kind: ServiceAccount
55+
name: k8s-webhook
56+
namespace: default
57+
---
58+
apiVersion: v1
59+
kind: Service
60+
metadata:
61+
labels:
62+
app: k8s-webhook
63+
name: pod-webhook
64+
namespace: default
65+
spec:
66+
ipFamilies:
67+
- IPv4
68+
ports:
69+
- name: https-443
70+
port: 9443
71+
protocol: TCP
72+
targetPort: https
73+
selector:
74+
app: k8s-webhook
75+
sessionAffinity: None
76+
type: ClusterIP
77+
---
78+
apiVersion: apps/v1
79+
kind: Deployment
80+
metadata:
81+
labels:
82+
app: k8s-webhook
83+
name: k8s-webhook
84+
namespace: default
85+
spec:
86+
progressDeadlineSeconds: 600
87+
replicas: 1
88+
revisionHistoryLimit: 10
89+
selector:
90+
matchLabels:
91+
app: k8s-webhook
92+
template:
93+
metadata:
94+
annotations:
95+
sidecar.istio.io/inject: "false"
96+
labels:
97+
app: k8s-webhook
98+
spec:
99+
containers:
100+
- command:
101+
- k8s-webhook
102+
image: ccr.ccs.tencentyun.com/public-proxy/k8s-webhook:validating-v0.1.0
103+
imagePullPolicy: Always
104+
livenessProbe:
105+
failureThreshold: 3
106+
httpGet:
107+
path: /health_check
108+
port: 8080
109+
scheme: HTTP
110+
initialDelaySeconds: 10
111+
periodSeconds: 15
112+
successThreshold: 1
113+
timeoutSeconds: 4
114+
name: app
115+
ports:
116+
- containerPort: 9443
117+
name: https
118+
protocol: TCP
119+
readinessProbe:
120+
failureThreshold: 3
121+
httpGet:
122+
path: /health_check
123+
port: 8080
124+
scheme: HTTP
125+
initialDelaySeconds: 5
126+
periodSeconds: 15
127+
successThreshold: 1
128+
timeoutSeconds: 4
129+
resources:
130+
limits:
131+
cpu: 200m
132+
memory: 512Mi
133+
requests:
134+
cpu: 10m
135+
memory: 56Mi
136+
terminationMessagePath: /dev/termination-log
137+
terminationMessagePolicy: File
138+
dnsPolicy: ClusterFirst
139+
restartPolicy: Always
140+
schedulerName: default-scheduler
141+
serviceAccountName: k8s-webhook
142+
terminationGracePeriodSeconds: 30

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
VERSION_TAG ?= validating-v0.1.0
2-
REGISTRY_HOST ?= ccr.ccs.tencentyun.com/public-proxy/k8s-webhook
2+
REGISTRY_ADDR ?= ccr.ccs.tencentyun.com/public-proxy/k8s-webhook
33

44
build:
55
go build -o k8s-webhook main.go
66
build-image: build
7-
docker build -t $(REGISTRY_HOST):$(VERSION_TAG) .
8-
docker push $(REGISTRY_HOST):$(VERSION_TAG)
7+
docker build -t $(REGISTRY_ADDR):$(VERSION_TAG) .
8+
docker push $(REGISTRY_ADDR):$(VERSION_TAG)
99
deploy-k8s: build-image
10-
kustomize build kustomize/overlays/dev/ | sed "s/VERSION_TAG/${VERSION_TAG}/g" | kubectl apply -f -
10+
kustomize build kustomize/overlays/dev/ | sed -e "s|VERSION_TAG|${VERSION_TAG}|g" -e "s|REGISTRY_ADDR|${REGISTRY_ADDR}|g" > 1.txt
1111

k8s/validation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ValidatingPod(k8sClient *kubernetes.Clientset) http.Handler {
3434
}
3535

3636
if req.Operation == admission_v1.Delete && podCanNotBeDeleted {
37-
slog.Info("pod can not be deleted labels allow-delete=false", "name", req.Name, "namespace", req.Namespace)
37+
slog.Info("pod can not be deleted with labels allow-delete=false", "name", req.Name, "namespace", req.Namespace)
3838
return admission.ValidationResponse(false, "not allow by webhook")
3939
}
4040
return admission.ValidationResponse(true, "ok")

kustomize/overlays/dev/kustomization.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
images:
3-
- newName: ccr.ccs.tencentyun.com/public-proxy/k8s-webhook
3+
- newName: REGISTRY_ADDR
44
name: image_name
55
newTag: VERSION_TAG
66
commonLabels:

0 commit comments

Comments
 (0)