Skip to content

Add more fields to BackendConfig: #804

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

Merged
merged 9 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions .ci/clusters/global_backend_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ spec:
liveness:
initialDelaySeconds: 10
periodSeconds: 30
labels:
from: global-backendconfig
tolerations:
- key: disktype
operator: Exists
effect: NoExecute
tolerationSeconds: 600
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: disktype
operator: In
values:
- hdd
39 changes: 38 additions & 1 deletion .ci/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,41 @@ function ci::verify_liveness_probe() {
return 1
fi
echo "succeeded"
}
}

function ci::verify_label() {
pod=$1
label=$2
expected=$3
result=$(kubectl get pod $pod -o jsonpath="{.metadata.labels['$label']}")
echo "value of $lable is $result"
if [[ "$result" != "$expected" ]]; then
echo "failed"
return 1
fi
echo "succeeded"
}

function ci::verify_tolerations() {
sts=$1
expected=$2
result=$(kubectl get statefulset $sts -o jsonpath='{.spec.template.spec.tolerations}')
echo "tolerations is $result"
if [[ "$result" != "$expected" ]]; then
echo "failed"
return 1
fi
echo "succeeded"
}

function ci::verify_affinity() {
pod=$1
expected=$2
result=$(kubectl get pod $pod -o jsonpath='{.spec.affinity}')
echo "affinity 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 @@ -12,3 +12,20 @@ spec:
liveness:
initialDelaySeconds: 50
periodSeconds: 60
labels:
from: other-namespace-backendconfig
tolerations:
- key: disktype
operator: Exists
effect: NoExecute
tolerationSeconds: 300
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: disktype
operator: In
values:
- ssd
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,20 @@ spec:
liveness:
initialDelaySeconds: 30
periodSeconds: 10
labels:
from: namespace-backendconfig
tolerations:
- key: disktype
operator: Exists
effect: NoExecute
tolerationSeconds: 300
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: disktype
operator: In
values:
- ssd
121 changes: 121 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 @@ -82,6 +82,33 @@ if [ $? -ne 0 ]; then
exit 1
fi

# verify label
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from namespace-backendconfig 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_label_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

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

# verify affinity
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)
if [ $? -ne 0 ]; then
echo "$verify_affinity_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
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
Expand Down Expand Up @@ -115,6 +142,19 @@ if [ $? -ne 0 ]; then
exit 1
fi

# the labels should also be updated
kubectl patch BackendConfig backend-config --type='json' -p='[{"op": "replace", "path": "/spec/pod/labels/from", "value": "new_label"}]' > /dev/null 2>&1
sleep 30

# verify label
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from "new_label" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_label_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 @@ -147,6 +187,33 @@ if [ $? -ne 0 ]; then
exit 1
fi

# verify label
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from global-backendconfig 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_label_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

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

# verify tolerations
verify_tolerations_result=$(ci::verify_tolerations function-sample-env-function '[{"effect":"NoExecute","key":"disktype","operator":"Exists","tolerationSeconds":600}]' 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_tolerations_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
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
Expand All @@ -173,6 +240,33 @@ if [ $? -ne 0 ]; then
exit 1
fi

# verify label
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from "" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_label_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# verify tolerations
verify_tolerations_result=$(ci::verify_tolerations function-sample-env-function '' 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_tolerations_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# verify affinity
verify_affinity_result=$(ci::verify_affinity function-sample-env-function-0 '' 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_affinity_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
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
Expand Down Expand Up @@ -209,4 +303,31 @@ else
exit 1
fi

# verify label
verify_label_result=$(ci::verify_label "function-sample-env-function-0" from "" 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_label_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# verify tolerations
verify_tolerations_result=$(ci::verify_tolerations function-sample-env-function '' 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_tolerations_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# verify affinity
verify_affinity_result=$(ci::verify_affinity function-sample-env-function-0 '' 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_affinity_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
9 changes: 1 addition & 8 deletions api/compute/v1alpha1/backendconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,13 @@ type BackendConfigSpec struct {
Env map[string]string `json:"env,omitempty"`

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

// +kubebuilder:validation:Optional
// indicate whether auto update functions&sinks&source when the BackendConfig is updated
AutoUpdate bool `json:"autoUpdate,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
type BackendConfigStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
22 changes: 1 addition & 21 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.

Loading
Loading