Skip to content

Commit 56e5bad

Browse files
Add liveness in backend config (#767)
* Add liveness config in backendconfig * Add ci * Add pod field
1 parent 4342dc4 commit 56e5bad

24 files changed

+2400
-50
lines changed

.ci/clusters/global_backend_config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ metadata:
55
spec:
66
env:
77
global1: globalvalue1
8-
shared1: fromglobal
8+
shared1: fromglobal
9+
pod:
10+
liveness:
11+
initialDelaySeconds: 10
12+
periodSeconds: 30

.ci/helm.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,4 +619,16 @@ function ci::verify_pod_log() {
619619
sleep 5
620620
kubectl logs --tail=-1 $pod | grep "$log"
621621
done
622+
}
623+
624+
function ci::verify_liveness_probe() {
625+
pod=$1
626+
expected=$2
627+
result=$(kubectl get pod $pod -o jsonpath='{.spec.containers[*].livenessProbe}')
628+
echo "liveness probe is $result"
629+
if [[ "$result" != "$expected" ]]; then
630+
echo "failed"
631+
return 1
632+
fi
633+
echo "succeeded"
622634
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ spec:
77
env:
88
namespaced1: namespacedvalue1
99
shared1: fromnamespace
10+
pod:
11+
liveness:
12+
initialDelaySeconds: 50
13+
periodSeconds: 60

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ metadata:
66
spec:
77
env:
88
namespaced1: namespacedvalue1
9-
shared1: fromnamespace
9+
shared1: fromnamespace
10+
pod:
11+
liveness:
12+
initialDelaySeconds: 30
13+
periodSeconds: 10

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ if [ $? -ne 0 ]; then
7373
exit 1
7474
fi
7575

76+
# verify liveness config
77+
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)
78+
if [ $? -ne 0 ]; then
79+
echo "$verify_liveness_result"
80+
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
81+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
82+
exit 1
83+
fi
84+
7685
# delete the namespaced config, the function should be reconciled without namespaced env injected
7786
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
7887
sleep 30
@@ -105,6 +114,14 @@ if [ $? -ne 0 ]; then
105114
exit 1
106115
fi
107116

117+
# it should use liveness config from global config
118+
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)
119+
if [ $? -ne 0 ]; then
120+
echo "$verify_liveness_result"
121+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
122+
exit 1
123+
fi
124+
108125
# delete the global config, the function should be reconciled without global env injected
109126
kubectl delete -f "${global_mesh_config_file}" -n $FUNCTION_MESH_NAMESPACE > /dev/null 2>&1 || true
110127
sleep 30
@@ -123,6 +140,14 @@ if [ $? -ne 0 ]; then
123140
exit 1
124141
fi
125142

143+
# it should has no liveness config
144+
verify_liveness_result=$(ci::verify_liveness_probe function-sample-env-function-0 "" 2>&1)
145+
if [ $? -ne 0 ]; then
146+
echo "$verify_liveness_result"
147+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
148+
exit 1
149+
fi
150+
126151
# config created in an another namespace should not affect functions in other namespaces
127152
kubectl apply -f "${mesh_config_file_in_kube_system}" > /dev/null 2>&1
128153
sleep 30
@@ -134,6 +159,14 @@ if [ $? -ne 0 ]; then
134159
exit 1
135160
fi
136161

162+
# it should has no liveness config
163+
verify_liveness_result=$(ci::verify_liveness_probe function-sample-env-function-0 "" 2>&1)
164+
if [ $? -ne 0 ]; then
165+
echo "$verify_liveness_result"
166+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
167+
exit 1
168+
fi
169+
137170
verify_env_result=$(ci::verify_env "function-sample-env" namespaced1 "" 2>&1)
138171
if [ $? -eq 0 ]; then
139172
echo "e2e-test: ok" | yq eval -

api/compute/v1alpha1/backendconfig_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ type BackendConfigSpec struct {
3333

3434
// +kubebuilder:validation:Optional
3535
Env map[string]string `json:"env,omitempty"`
36+
37+
// +kubebuilder:validation:Optional
38+
Pod *BackendConfigPodPolicy `json:"pod,omitempty"`
39+
}
40+
41+
// BackendConfigPodPolicy defines the policy for the pod
42+
// TODO: Support more fields from PodPolicy
43+
type BackendConfigPodPolicy struct {
44+
// +kubebuilder:validation:Optional
45+
Liveness *Liveness `json:"liveness,omitempty"`
3646
}
3747

3848
// BackendConfigStatus defines the observed state of BackendConfig

api/compute/v1alpha1/zz_generated.deepcopy.go

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

charts/function-mesh-operator/charts/admission-webhook/templates/crd-compute.functionmesh.io-backendconfigs.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
{{- if eq .Values.admissionWebhook.certificate.provider "cert-manager" }}
77
{{- include "function-mesh-operator.certManager.annotation" . | nindent 4 -}}
88
{{- end }}
9-
controller-gen.kubebuilder.io/version: v0.9.2
9+
controller-gen.kubebuilder.io/version: v0.15.0
1010
name: backendconfigs.compute.functionmesh.io
1111
spec:
1212
conversion:
@@ -54,6 +54,24 @@ spec:
5454
type: object
5555
name:
5656
type: string
57+
pod:
58+
properties:
59+
liveness:
60+
properties:
61+
failureThreshold:
62+
format: int32
63+
type: integer
64+
initialDelaySeconds:
65+
format: int32
66+
type: integer
67+
periodSeconds:
68+
format: int32
69+
type: integer
70+
successThreshold:
71+
format: int32
72+
type: integer
73+
type: object
74+
type: object
5775
type: object
5876
status:
5977
type: object

0 commit comments

Comments
 (0)