Skip to content

Commit b523d59

Browse files
Add more fields to BackendConfig: (#804)
* Add more fields to BackendConfig: - Labels - NodeSelector - Affinity - Tolerations - Annotations - SecurityContext - TerminationGracePeriodSeconds - ImagePullSecrets - ServiceAccountName * Fix ci * Fix ci * Fix ci * Add global backend config argument * update ci * update ci * fix ci * Reuse the PodPolicy
1 parent 2bb5b67 commit b523d59

File tree

16 files changed

+11836
-65
lines changed

16 files changed

+11836
-65
lines changed

.ci/clusters/global_backend_config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,20 @@ 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+
- weight: 100
25+
preference:
26+
matchExpressions:
27+
- key: disktype
28+
operator: In
29+
values:
30+
- 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+
sts=$1
665+
expected=$2
666+
result=$(kubectl get statefulset $sts -o jsonpath='{.spec.template.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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,20 @@ 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+
- weight: 100
26+
preference:
27+
matchExpressions:
28+
- key: disktype
29+
operator: In
30+
values:
31+
- 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 '[{"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_affinity function-sample-env-function-0 '{"nodeAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"preference":{"matchExpressions":[{"key":"disktype","operator":"In","values":["ssd"]}]},"weight":100}]}}' 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_affinity function-sample-env-function-0 '{"nodeAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"preference":{"matchExpressions":[{"key":"disktype","operator":"In","values":["hdd"]}]},"weight":100}]}}' 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 '[{"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 '' 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_affinity 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 '' 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_affinity 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: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,13 @@ type BackendConfigSpec struct {
3535
Env map[string]string `json:"env,omitempty"`
3636

3737
// +kubebuilder:validation:Optional
38-
Pod *BackendConfigPodPolicy `json:"pod,omitempty"`
38+
Pod *PodPolicy `json:"pod,omitempty"`
3939

4040
// +kubebuilder:validation:Optional
4141
// indicate whether auto update functions&sinks&source when the BackendConfig is updated
4242
AutoUpdate bool `json:"autoUpdate,omitempty"`
4343
}
4444

45-
// BackendConfigPodPolicy defines the policy for the pod
46-
// TODO: Support more fields from PodPolicy
47-
type BackendConfigPodPolicy struct {
48-
// +kubebuilder:validation:Optional
49-
Liveness *Liveness `json:"liveness,omitempty"`
50-
}
51-
5245
// BackendConfigStatus defines the observed state of BackendConfig
5346
type BackendConfigStatus struct {
5447
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster

api/compute/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)