Skip to content

Commit

Permalink
Add liveness in backend config (#767)
Browse files Browse the repository at this point in the history
* Add liveness config in backendconfig

* Add ci

* Add pod field
  • Loading branch information
jiangpengcheng committed Jul 12, 2024
1 parent b7d924a commit 58b397d
Show file tree
Hide file tree
Showing 24 changed files with 2,400 additions and 50 deletions.
6 changes: 5 additions & 1 deletion .ci/clusters/global_backend_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ metadata:
spec:
env:
global1: globalvalue1
shared1: fromglobal
shared1: fromglobal
pod:
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 @@ -608,4 +608,16 @@ function ci::verify_env() {
return 0
fi
return 1
}

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,7 @@ spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
pod:
liveness:
initialDelaySeconds: 50
periodSeconds: 60
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ metadata:
spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
shared1: fromnamespace
pod:
liveness:
initialDelaySeconds: 30
periodSeconds: 10
33 changes: 33 additions & 0 deletions .ci/tests/integration/cases/global-and-namespaced-config/verify.sh
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
10 changes: 10 additions & 0 deletions api/compute/v1alpha1/backendconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ type BackendConfigSpec struct {

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

// +kubebuilder:validation:Optional
Pod *BackendConfigPodPolicy `json:"pod,omitempty"`
}

// BackendConfigPodPolicy defines the policy for the pod
// TODO: Support more fields from PodPolicy
type BackendConfigPodPolicy struct {
// +kubebuilder:validation:Optional
Liveness *Liveness `json:"liveness,omitempty"`
}

// BackendConfigStatus defines the observed state of BackendConfig
Expand Down
25 changes: 25 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 @@ -54,6 +54,24 @@ spec:
type: object
name:
type: string
pod:
properties:
liveness:
properties:
failureThreshold:
format: int32
type: integer
initialDelaySeconds:
format: int32
type: integer
periodSeconds:
format: int32
type: integer
successThreshold:
format: int32
type: integer
type: object
type: object
type: object
status:
type: object
Expand Down
Loading

0 comments on commit 58b397d

Please sign in to comment.