-
Notifications
You must be signed in to change notification settings - Fork 66
K8SPG-833 add "custom-envs" e2e test #1315
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should also add check for backup and restore pods.
kubectl create secret generic instance-env-secret \ | ||
--from-literal=DB_USER_TEST_ENV=myuser \ | ||
--from-literal=DB_PASSWORD_TEST_ENV='MyS3cretP@ss' \ | ||
-n "${NAMESPACE}" || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is better to fail a test if secret is not created? Without secret - the next step will fail anyway?
sleep 10 | ||
wait_cluster_consistency custom-envs | ||
check_env_in_pod add instance DB_USER_TEST_ENV myuser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add 2 env vars, why do we check only 1 of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add 2 vars for env and check both
sleep 10 | ||
wait_cluster_consistency custom-envs | ||
check_env_in_pod add instance DB_USER_NEW myuser2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same, pls add hceck for the seond var
sleep 10 | ||
wait_cluster_consistency custom-envs | ||
check_env_in_pod add instance DB_NEW_ENV new-value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add check that old variables stay
kubectl create secret generic instance-env-secret-updated \ | ||
--from-literal=DB_USER_NEW=myuser2 \ | ||
--from-literal=DB_PASSWORD_NEW=NewS3cretP@ss \ | ||
--dry-run=client -o yaml | kubectl -n "${NAMESPACE}" apply -f - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to unify the way we create secrets
…ostgresql-operator into K8SPG-833_add_e2e_test
local namespace=$1 | ||
local pod=$2 | ||
local container=$3 | ||
|
||
if [ -n "$container" ]; then | ||
kubectl exec -n "$namespace" "$pod" -c "$container" -- printenv 2>/dev/null || true | ||
else | ||
kubectl exec -n "$namespace" "$pod" -- printenv 2>/dev/null || true | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shfmt] reported by reviewdog 🐶
local namespace=$1 | |
local pod=$2 | |
local container=$3 | |
if [ -n "$container" ]; then | |
kubectl exec -n "$namespace" "$pod" -c "$container" -- printenv 2>/dev/null || true | |
else | |
kubectl exec -n "$namespace" "$pod" -- printenv 2>/dev/null || true | |
fi | |
local namespace=$1 | |
local pod=$2 | |
local container=$3 | |
if [ -n "$container" ]; then | |
kubectl exec -n "$namespace" "$pod" -c "$container" -- printenv 2>/dev/null || true | |
else | |
kubectl exec -n "$namespace" "$pod" -- printenv 2>/dev/null || true | |
fi |
local check_type=$1 | ||
local pod=$2 | ||
local var_name=$3 | ||
local expected_value=$4 | ||
local env_content=$5 | ||
|
||
local actual_value | ||
actual_value=$(echo "$env_content" | grep -E "^${var_name}=" | cut -d'=' -f2- || true) | ||
|
||
if [[ "$check_type" == "add" ]]; then | ||
if [ "$actual_value" != "$expected_value" ]; then | ||
echo "ERROR: $var_name in $pod — expected '$expected_value', got '${actual_value:-<missing>}'" | ||
return 1 | ||
else | ||
echo "OK: $var_name=$actual_value in $pod" | ||
fi | ||
elif [[ "$check_type" == "delete" ]]; then | ||
if [ -n "$actual_value" ]; then | ||
echo "ERROR: $var_name exists in $pod (should not exist)" | ||
return 1 | ||
else | ||
echo "OK: $var_name deleted in $pod" | ||
fi | ||
else | ||
echo "ERROR: unknown check type '$check_type'" | ||
return 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shfmt] reported by reviewdog 🐶
local check_type=$1 | |
local pod=$2 | |
local var_name=$3 | |
local expected_value=$4 | |
local env_content=$5 | |
local actual_value | |
actual_value=$(echo "$env_content" | grep -E "^${var_name}=" | cut -d'=' -f2- || true) | |
if [[ "$check_type" == "add" ]]; then | |
if [ "$actual_value" != "$expected_value" ]; then | |
echo "ERROR: $var_name in $pod — expected '$expected_value', got '${actual_value:-<missing>}'" | |
return 1 | |
else | |
echo "OK: $var_name=$actual_value in $pod" | |
fi | |
elif [[ "$check_type" == "delete" ]]; then | |
if [ -n "$actual_value" ]; then | |
echo "ERROR: $var_name exists in $pod (should not exist)" | |
return 1 | |
else | |
echo "OK: $var_name deleted in $pod" | |
fi | |
else | |
echo "ERROR: unknown check type '$check_type'" | |
return 1 | |
fi | |
local check_type=$1 | |
local pod=$2 | |
local var_name=$3 | |
local expected_value=$4 | |
local env_content=$5 | |
local actual_value | |
actual_value=$(echo "$env_content" | grep -E "^${var_name}=" | cut -d'=' -f2- || true) | |
if [[ $check_type == "add" ]]; then | |
if [ "$actual_value" != "$expected_value" ]; then | |
echo "ERROR: $var_name in $pod — expected '$expected_value', got '${actual_value:-<missing>}'" | |
return 1 | |
else | |
echo "OK: $var_name=$actual_value in $pod" | |
fi | |
elif [[ $check_type == "delete" ]]; then | |
if [ -n "$actual_value" ]; then | |
echo "ERROR: $var_name exists in $pod (should not exist)" | |
return 1 | |
else | |
echo "OK: $var_name deleted in $pod" | |
fi | |
else | |
echo "ERROR: unknown check type '$check_type'" | |
return 1 | |
fi |
local check_type=$1 # add | delete | ||
local component=$2 # instance | pgbouncer | repohost | ||
local vars=("${@:3}") # everything after the 2nd argument | ||
|
||
case "$component" in | ||
instance) | ||
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/instance-set=instance1 -o 'jsonpath={.items[0].metadata.name}') | ||
CONTAINER="" | ||
;; | ||
pgbouncer) | ||
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/role=pgbouncer -o 'jsonpath={.items[0].metadata.name}') | ||
CONTAINER="pgbouncer" | ||
;; | ||
repohost) | ||
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/data=pgbackrest -o 'jsonpath={.items[0].metadata.name}') | ||
CONTAINER="pgbackrest" | ||
;; | ||
*) | ||
echo "ERROR: unknown component '$component'" | ||
return 1 | ||
;; | ||
esac | ||
|
||
echo "Fetching environment variables for $component pod $POD..." | ||
local env_content | ||
env_content=$(get_envs_from_pod "${NAMESPACE}" "$POD" "$CONTAINER") | ||
|
||
local errors=0 | ||
for var_entry in "${vars[@]}"; do | ||
if [[ "$check_type" == "add" ]]; then | ||
local var_name="${var_entry%%=*}" | ||
local var_expected="${var_entry#*=}" | ||
check_env_in_pod add "$POD" "$var_name" "$var_expected" "$env_content" || errors=$((errors+1)) | ||
else | ||
check_env_in_pod delete "$POD" "$var_entry" "" "$env_content" || errors=$((errors+1)) | ||
fi | ||
done | ||
|
||
if (( errors > 0 )); then | ||
echo "$errors environment check(s) failed for component '$component'" | ||
return 1 | ||
else | ||
echo "All environment checks passed for component '$component'" | ||
fi | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shfmt] reported by reviewdog 🐶
local check_type=$1 # add | delete | |
local component=$2 # instance | pgbouncer | repohost | |
local vars=("${@:3}") # everything after the 2nd argument | |
case "$component" in | |
instance) | |
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/instance-set=instance1 -o 'jsonpath={.items[0].metadata.name}') | |
CONTAINER="" | |
;; | |
pgbouncer) | |
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/role=pgbouncer -o 'jsonpath={.items[0].metadata.name}') | |
CONTAINER="pgbouncer" | |
;; | |
repohost) | |
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/data=pgbackrest -o 'jsonpath={.items[0].metadata.name}') | |
CONTAINER="pgbackrest" | |
;; | |
*) | |
echo "ERROR: unknown component '$component'" | |
return 1 | |
;; | |
esac | |
echo "Fetching environment variables for $component pod $POD..." | |
local env_content | |
env_content=$(get_envs_from_pod "${NAMESPACE}" "$POD" "$CONTAINER") | |
local errors=0 | |
for var_entry in "${vars[@]}"; do | |
if [[ "$check_type" == "add" ]]; then | |
local var_name="${var_entry%%=*}" | |
local var_expected="${var_entry#*=}" | |
check_env_in_pod add "$POD" "$var_name" "$var_expected" "$env_content" || errors=$((errors+1)) | |
else | |
check_env_in_pod delete "$POD" "$var_entry" "" "$env_content" || errors=$((errors+1)) | |
fi | |
done | |
if (( errors > 0 )); then | |
echo "$errors environment check(s) failed for component '$component'" | |
return 1 | |
else | |
echo "All environment checks passed for component '$component'" | |
fi | |
} | |
local check_type=$1 # add | delete | |
local component=$2 # instance | pgbouncer | repohost | |
local vars=("${@:3}") # everything after the 2nd argument | |
case "$component" in | |
instance) | |
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/instance-set=instance1 -o 'jsonpath={.items[0].metadata.name}') | |
CONTAINER="" | |
;; | |
pgbouncer) | |
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/role=pgbouncer -o 'jsonpath={.items[0].metadata.name}') | |
CONTAINER="pgbouncer" | |
;; | |
repohost) | |
POD=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/data=pgbackrest -o 'jsonpath={.items[0].metadata.name}') | |
CONTAINER="pgbackrest" | |
;; | |
*) | |
echo "ERROR: unknown component '$component'" | |
return 1 | |
;; | |
esac | |
echo "Fetching environment variables for $component pod $POD..." | |
local env_content | |
env_content=$(get_envs_from_pod "${NAMESPACE}" "$POD" "$CONTAINER") | |
local errors=0 | |
for var_entry in "${vars[@]}"; do | |
if [[ $check_type == "add" ]]; then | |
local var_name="${var_entry%%=*}" | |
local var_expected="${var_entry#*=}" | |
check_env_in_pod add "$POD" "$var_name" "$var_expected" "$env_content" || errors=$((errors + 1)) | |
else | |
check_env_in_pod delete "$POD" "$var_entry" "" "$env_content" || errors=$((errors + 1)) | |
fi | |
done | |
if ((errors > 0)); then | |
echo "$errors environment check(s) failed for component '$component'" | |
return 1 | |
else | |
echo "All environment checks passed for component '$component'" | |
fi | |
} | |
commit: 09c40b5 |
CHANGE DESCRIPTION
Problem:
Add E2E test to verify custom environment variables across all components (instance, pgBouncer, pgBackRest )
Since we modified several independent parts of the code, I added repeated checks for the instance, pgBouncer, and pgBackRest types.
What this test covers:
connected PRs
#1231
#1306
Cause:
Short explanation of the root cause of the issue if applicable.
Solution:
Short explanation of the solution we are providing with this PR.
CHECKLIST
Jira
Needs Doc
) and QA (Needs QA
)?Tests
Config/Logging/Testability