Skip to content

Commit 3a3bb4d

Browse files
Add more fields to BackendConfig:
- Labels - NodeSelector - Affinity - Tolerations - Annotations - SecurityContext - TerminationGracePeriodSeconds - ImagePullSecrets - ServiceAccountName
1 parent 2bb5b67 commit 3a3bb4d

File tree

14 files changed

+1485
-17
lines changed

14 files changed

+1485
-17
lines changed

.ci/clusters/global_backend_config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,21 @@ spec:
1111
liveness:
1212
initialDelaySeconds: 10
1313
periodSeconds: 30
14+
labels:
15+
from: global-backendconfig
16+
tolerations:
17+
- key: disktype
18+
operator: Exists
19+
effect: NoExecute
20+
tolerationSeconds: 600
21+
affinity:
22+
nodeAffinity:
23+
preferredDuringSchedulingIgnoredDuringExecution:
24+
nodeSelectorTerms:
25+
- weight: 100
26+
preference:
27+
matchExpressions:
28+
- key: disktype
29+
operator: In
30+
values:
31+
- hdd

.ci/clusters/global_backend_config_without_env.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,21 @@ spec:
88
liveness:
99
initialDelaySeconds: 10
1010
periodSeconds: 30
11+
labels:
12+
from: global-backendconfig
13+
tolerations:
14+
- key: disktype
15+
operator: Exists
16+
effect: NoExecute
17+
tolerationSeconds: 600
18+
affinity:
19+
nodeAffinity:
20+
preferredDuringSchedulingIgnoredDuringExecution:
21+
nodeSelectorTerms:
22+
- weight: 100
23+
preference:
24+
matchExpressions:
25+
- key: disktype
26+
operator: In
27+
values:
28+
- hdd

.ci/helm.sh

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,4 +645,41 @@ function ci::verify_liveness_probe() {
645645
return 1
646646
fi
647647
echo "succeeded"
648-
}
648+
}
649+
650+
function ci::verify_label() {
651+
pod=$1
652+
label=$2
653+
expected=$3
654+
result=$(kubectl get pod $pod -o jsonpath="{.metadata.labels['$label']}")
655+
echo "value of $lable is $result"
656+
if [[ "$result" != "$expected" ]]; then
657+
echo "failed"
658+
return 1
659+
fi
660+
echo "succeeded"
661+
}
662+
663+
function ci::verify_tolerations() {
664+
pod=$1
665+
expected=$2
666+
result=$(kubectl get pod $pod -o jsonpath='{.spec.tolerations}')
667+
echo "tolerations is $result"
668+
if [[ "$result" != "$expected" ]]; then
669+
echo "failed"
670+
return 1
671+
fi
672+
echo "succeeded"
673+
}
674+
675+
function ci::verify_affinity() {
676+
pod=$1
677+
expected=$2
678+
result=$(kubectl get pod $pod -o jsonpath='{.spec.affinity}')
679+
echo "affinity is $result"
680+
if [[ "$result" != "$expected" ]]; then
681+
echo "failed"
682+
return 1
683+
fi
684+
echo "succeeded"
685+
}

.ci/tests/integration/cases/global-and-namespaced-config/mesh-config-kube-system.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ spec:
1212
liveness:
1313
initialDelaySeconds: 50
1414
periodSeconds: 60
15+
labels:
16+
from: other-namespace-backendconfig
17+
tolerations:
18+
- key: disktype
19+
operator: Exists
20+
effect: NoExecute
21+
tolerationSeconds: 300
22+
affinity:
23+
nodeAffinity:
24+
preferredDuringSchedulingIgnoredDuringExecution:
25+
nodeSelectorTerms:
26+
- weight: 100
27+
preference:
28+
matchExpressions:
29+
- key: disktype
30+
operator: In
31+
values:
32+
- other-ssd

.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,20 @@ spec:
1313
liveness:
1414
initialDelaySeconds: 30
1515
periodSeconds: 10
16+
labels:
17+
from: namespace-backendconfig
18+
tolerations:
19+
- key: disktype
20+
operator: Exists
21+
effect: NoExecute
22+
tolerationSeconds: 300
23+
affinity:
24+
nodeAffinity:
25+
preferredDuringSchedulingIgnoredDuringExecution:
26+
- weight: 100
27+
preference:
28+
matchExpressions:
29+
- key: disktype
30+
operator: In
31+
values:
32+
- ssd

.ci/tests/integration/cases/global-and-namespaced-config/verify.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,33 @@ if [ $? -ne 0 ]; then
8282
exit 1
8383
fi
8484

85+
# verify label
86+
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from namespace-backendconfig 2>&1)
87+
if [ $? -ne 0 ]; then
88+
echo "$verify_label_result"
89+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
90+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
91+
exit 1
92+
fi
93+
94+
# verify tolerations
95+
verify_tolerations_result=$(ci::verify_tolerations function-sample-env-function-0 '[{"effect":"NoExecute","key":"disktype","operator":"Exists","tolerationSeconds":600},{"effect":"NoExecute","key":"disktype","operator":"Exists","tolerationSeconds":300}]' 2>&1)
96+
if [ $? -ne 0 ]; then
97+
echo "$verify_tolerations_result"
98+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
99+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
100+
exit 1
101+
fi
102+
103+
# verify affinity
104+
verify_affinity_result=$(ci::verify_tolerations function-sample-env-function-0 '{"nodeAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"weight":100,"preference":{"matchExpressions":[{"key":"disktype","operator":"In","values":["ssd"]}]}}]}}' 2>&1)
105+
if [ $? -ne 0 ]; then
106+
echo "$verify_affinity_result"
107+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
108+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
109+
exit 1
110+
fi
111+
85112
# verify liveness config
86113
verify_liveness_result=$(ci::verify_liveness_probe function-sample-env-function-0 '{"failureThreshold":3,"httpGet":{"path":"/","port":9094,"scheme":"HTTP"},"initialDelaySeconds":30,"periodSeconds":10,"successThreshold":1,"timeoutSeconds":10}' 2>&1)
87114
if [ $? -ne 0 ]; then
@@ -115,6 +142,19 @@ if [ $? -ne 0 ]; then
115142
exit 1
116143
fi
117144

145+
# the labels should also be updated
146+
kubectl patch BackendConfig backend-config --type='json' -p='[{"op": "replace", "path": "/spec/pod/labels/from", "value": "new_label"}]' > /dev/null 2>&1
147+
sleep 30
148+
149+
# verify label
150+
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from "new_label" 2>&1)
151+
if [ $? -ne 0 ]; then
152+
echo "$verify_label_result"
153+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
154+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
155+
exit 1
156+
fi
157+
118158
# delete the namespaced config, the function should be reconciled without namespaced env injected
119159
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
120160
sleep 30
@@ -147,6 +187,33 @@ if [ $? -ne 0 ]; then
147187
exit 1
148188
fi
149189

190+
# verify label
191+
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from global-backendconfig 2>&1)
192+
if [ $? -ne 0 ]; then
193+
echo "$verify_label_result"
194+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
195+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
196+
exit 1
197+
fi
198+
199+
# verify affinity
200+
verify_affinity_result=$(ci::verify_tolerations function-sample-env-function-0 '{"nodeAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"weight":100,"preference":{"matchExpressions":[{"key":"disktype","operator":"In","values":["hdd"]}]}}]}}' 2>&1)
201+
if [ $? -ne 0 ]; then
202+
echo "$verify_affinity_result"
203+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
204+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
205+
exit 1
206+
fi
207+
208+
# verify tolerations
209+
verify_tolerations_result=$(ci::verify_tolerations function-sample-env-function-0 '[{"effect":"NoExecute","key":"disktype","operator":"Exists","tolerationSeconds":600}]' 2>&1)
210+
if [ $? -ne 0 ]; then
211+
echo "$verify_tolerations_result"
212+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
213+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
214+
exit 1
215+
fi
216+
150217
# it should use liveness config from global config
151218
verify_liveness_result=$(ci::verify_liveness_probe function-sample-env-function-0 '{"failureThreshold":3,"httpGet":{"path":"/","port":9094,"scheme":"HTTP"},"initialDelaySeconds":10,"periodSeconds":30,"successThreshold":1,"timeoutSeconds":30}' 2>&1)
152219
if [ $? -ne 0 ]; then
@@ -173,6 +240,33 @@ if [ $? -ne 0 ]; then
173240
exit 1
174241
fi
175242

243+
# verify label
244+
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from "" 2>&1)
245+
if [ $? -ne 0 ]; then
246+
echo "$verify_label_result"
247+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
248+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
249+
exit 1
250+
fi
251+
252+
# verify tolerations
253+
verify_tolerations_result=$(ci::verify_tolerations function-sample-env-function-0 '' 2>&1)
254+
if [ $? -ne 0 ]; then
255+
echo "$verify_tolerations_result"
256+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
257+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
258+
exit 1
259+
fi
260+
261+
# verify affinity
262+
verify_affinity_result=$(ci::verify_tolerations function-sample-env-function-0 '' 2>&1)
263+
if [ $? -ne 0 ]; then
264+
echo "$verify_affinity_result"
265+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
266+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
267+
exit 1
268+
fi
269+
176270
# it should has no liveness config
177271
verify_liveness_result=$(ci::verify_liveness_probe function-sample-env-function-0 "" 2>&1)
178272
if [ $? -ne 0 ]; then
@@ -209,4 +303,31 @@ else
209303
exit 1
210304
fi
211305

306+
# verify label
307+
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from "" 2>&1)
308+
if [ $? -ne 0 ]; then
309+
echo "$verify_label_result"
310+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
311+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
312+
exit 1
313+
fi
314+
315+
# verify tolerations
316+
verify_tolerations_result=$(ci::verify_tolerations function-sample-env-function-0 '' 2>&1)
317+
if [ $? -ne 0 ]; then
318+
echo "$verify_tolerations_result"
319+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
320+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
321+
exit 1
322+
fi
323+
324+
# verify affinity
325+
verify_affinity_result=$(ci::verify_tolerations function-sample-env-function-0 '' 2>&1)
326+
if [ $? -ne 0 ]; then
327+
echo "$verify_affinity_result"
328+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
329+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
330+
exit 1
331+
fi
332+
212333
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true

api/compute/v1alpha1/backendconfig_types.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package v1alpha1
1919

2020
import (
21+
v1 "k8s.io/api/core/v1"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
)
2324

@@ -43,8 +44,39 @@ type BackendConfigSpec struct {
4344
}
4445

4546
// BackendConfigPodPolicy defines the policy for the pod
46-
// TODO: Support more fields from PodPolicy
4747
type BackendConfigPodPolicy struct {
48+
// Labels specify the labels to attach to pod the operator creates for the cluster.
49+
Labels map[string]string `json:"labels,omitempty"`
50+
51+
// NodeSelector specifies a map of key-value pairs. For a pod to be eligible to run
52+
// on a node, the node must have each of the indicated key-value pairs as labels.
53+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
54+
55+
// Affinity specifies the scheduling constraints of a pod
56+
Affinity *v1.Affinity `json:"affinity,omitempty"`
57+
58+
// Tolerations specifies the tolerations of a Pod
59+
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
60+
61+
// Annotations specifies the annotations to attach to pods the operator creates
62+
Annotations map[string]string `json:"annotations,omitempty"`
63+
64+
// SecurityContext specifies the security context for the entire pod
65+
// More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context
66+
SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"`
67+
68+
// TerminationGracePeriodSeconds is the amount of time that kubernetes will give
69+
// for a pod before terminating it.
70+
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
71+
72+
// ImagePullSecrets is an optional list of references to secrets in the same
73+
// namespace to use for pulling any of the images used by this PodSpec.
74+
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
75+
76+
// ServiceAccountName is the name of the ServiceAccount to use to run this pod.
77+
// +optional
78+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
79+
4880
// +kubebuilder:validation:Optional
4981
Liveness *Liveness `json:"liveness,omitempty"`
5082
}

api/compute/v1alpha1/zz_generated.deepcopy.go

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)