Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add liveness in backend config #767

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .ci/clusters/global_backend_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ metadata:
spec:
env:
global1: globalvalue1
shared1: fromglobal
shared1: fromglobal
liveness:
initialDelaySeconds: 10
periodSeconds: 30
12 changes: 12 additions & 0 deletions .ci/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,16 @@ function ci::verify_pod_log() {
sleep 5
kubectl logs --tail=-1 $pod | grep "$log"
done
}

function ci::verify_liveness_probe() {
pod=$1
expected=$2
result=$(kubectl get pod $pod -o jsonpath='{.spec.containers[*].livenessProbe}')
echo "liveness probe is $result"
if [[ "$result" != "$expected" ]]; then
echo "failed"
return 1
fi
echo "succeeded"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
liveness:
initialDelaySeconds: 50
periodSeconds: 60
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ metadata:
spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
shared1: fromnamespace
liveness:
initialDelaySeconds: 30
periodSeconds: 10
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ if [ $? -ne 0 ]; then
exit 1
fi

# verify liveness config
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)
if [ $? -ne 0 ]; then
echo "$verify_liveness_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# delete the namespaced config, the function should be reconciled without namespaced env injected
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
sleep 30
Expand Down Expand Up @@ -105,6 +114,14 @@ if [ $? -ne 0 ]; then
exit 1
fi

# it should use liveness config from global config
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)
if [ $? -ne 0 ]; then
echo "$verify_liveness_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# delete the global config, the function should be reconciled without global env injected
kubectl delete -f "${global_mesh_config_file}" -n $FUNCTION_MESH_NAMESPACE > /dev/null 2>&1 || true
sleep 30
Expand All @@ -123,6 +140,14 @@ if [ $? -ne 0 ]; then
exit 1
fi

# it should has no liveness config
verify_liveness_result=$(ci::verify_liveness_probe function-sample-env-function-0 "" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_liveness_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# config created in an another namespace should not affect functions in other namespaces
kubectl apply -f "${mesh_config_file_in_kube_system}" > /dev/null 2>&1
sleep 30
Expand All @@ -134,6 +159,14 @@ if [ $? -ne 0 ]; then
exit 1
fi

# it should has no liveness config
verify_liveness_result=$(ci::verify_liveness_probe function-sample-env-function-0 "" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_liveness_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_env_result=$(ci::verify_env "function-sample-env" namespaced1 "" 2>&1)
if [ $? -eq 0 ]; then
echo "e2e-test: ok" | yq eval -
Expand Down
3 changes: 3 additions & 0 deletions api/compute/v1alpha1/backendconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type BackendConfigSpec struct {

// +kubebuilder:validation:Optional
Env map[string]string `json:"env,omitempty"`

// +kubebuilder:validation:Optional
Liveness *Liveness `json:"liveness,omitempty"`
freeznet marked this conversation as resolved.
Show resolved Hide resolved
}

// BackendConfigStatus defines the observed state of BackendConfig
Expand Down
5 changes: 5 additions & 0 deletions api/compute/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
{{- if eq .Values.admissionWebhook.certificate.provider "cert-manager" }}
{{- include "function-mesh-operator.certManager.annotation" . | nindent 4 -}}
{{- end }}
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.15.0
name: backendconfigs.compute.functionmesh.io
spec:
conversion:
Expand Down Expand Up @@ -52,6 +52,21 @@ spec:
additionalProperties:
type: string
type: object
liveness:
properties:
failureThreshold:
format: int32
type: integer
initialDelaySeconds:
format: int32
type: integer
periodSeconds:
format: int32
type: integer
successThreshold:
format: int32
type: integer
type: object
name:
type: string
type: object
Expand Down
Loading
Loading