2020-03-18 19:49:14 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load _helpers
|
|
|
|
|
|
|
|
@test "server/ha-raft: testing deployment" {
|
|
|
|
cd `chart_dir`
|
|
|
|
|
|
|
|
helm install "$(name_prefix)" \
|
|
|
|
--set='server.ha.enabled=true' \
|
|
|
|
--set='server.ha.raft.enabled=true' .
|
|
|
|
wait_for_running $(name_prefix)-0
|
|
|
|
|
|
|
|
# Sealed, not initialized
|
2021-12-11 01:11:35 +00:00
|
|
|
wait_for_sealed_vault $(name_prefix)-0
|
2020-03-18 19:49:14 +00:00
|
|
|
|
2024-05-22 18:33:41 +00:00
|
|
|
local init_status=$(kubectl exec "$(name_prefix)-0" -- bao status -format=json |
|
2020-03-18 19:49:14 +00:00
|
|
|
jq -r '.initialized')
|
|
|
|
[ "${init_status}" == "false" ]
|
|
|
|
|
|
|
|
# Replicas
|
|
|
|
local replicas=$(kubectl get statefulset "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.replicas')
|
|
|
|
[ "${replicas}" == "3" ]
|
|
|
|
|
|
|
|
# Volume Mounts
|
|
|
|
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.template.spec.containers[0].volumeMounts | length')
|
2020-06-03 02:10:41 +00:00
|
|
|
[ "${volumeCount}" == "3" ]
|
2020-03-18 19:49:14 +00:00
|
|
|
|
|
|
|
# Volumes
|
|
|
|
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.template.spec.volumes | length')
|
2020-06-03 02:10:41 +00:00
|
|
|
[ "${volumeCount}" == "2" ]
|
2020-03-18 19:49:14 +00:00
|
|
|
|
|
|
|
local volume=$(kubectl get statefulset "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.template.spec.volumes[0].configMap.name')
|
|
|
|
[ "${volume}" == "$(name_prefix)-config" ]
|
|
|
|
|
|
|
|
# Service
|
|
|
|
local service=$(kubectl get service "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.clusterIP')
|
|
|
|
[ "${service}" != "None" ]
|
|
|
|
|
|
|
|
local service=$(kubectl get service "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.type')
|
|
|
|
[ "${service}" == "ClusterIP" ]
|
|
|
|
|
|
|
|
local ports=$(kubectl get service "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.ports | length')
|
|
|
|
[ "${ports}" == "2" ]
|
|
|
|
|
|
|
|
local ports=$(kubectl get service "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.ports[0].port')
|
|
|
|
[ "${ports}" == "8200" ]
|
|
|
|
|
|
|
|
local ports=$(kubectl get service "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.ports[1].port')
|
|
|
|
[ "${ports}" == "8201" ]
|
|
|
|
|
2024-05-28 11:52:10 +00:00
|
|
|
# OpenBao Init
|
2020-03-18 19:49:14 +00:00
|
|
|
local init=$(kubectl exec -ti "$(name_prefix)-0" -- \
|
2024-05-22 18:33:41 +00:00
|
|
|
bao operator init -format=json -n 1 -t 1)
|
2020-03-18 19:49:14 +00:00
|
|
|
|
|
|
|
local token=$(echo ${init} | jq -r '.unseal_keys_b64[0]')
|
|
|
|
[ "${token}" != "" ]
|
2024-05-22 18:33:41 +00:00
|
|
|
|
2020-03-18 19:49:14 +00:00
|
|
|
local root=$(echo ${init} | jq -r '.root_token')
|
|
|
|
[ "${root}" != "" ]
|
|
|
|
|
2024-05-22 18:33:41 +00:00
|
|
|
kubectl exec -ti openbao-0 -- bao operator unseal ${token}
|
2020-03-18 19:49:14 +00:00
|
|
|
wait_for_ready "$(name_prefix)-0"
|
|
|
|
|
|
|
|
sleep 5
|
|
|
|
|
2024-05-28 11:52:10 +00:00
|
|
|
# OpenBao Unseal
|
2024-05-22 18:33:41 +00:00
|
|
|
local pods=($(kubectl get pods --selector='app.kubernetes.io/name=openbao' -o json | jq -r '.items[].metadata.name'))
|
2020-03-18 19:49:14 +00:00
|
|
|
for pod in "${pods[@]}"
|
|
|
|
do
|
|
|
|
if [[ ${pod?} != "$(name_prefix)-0" ]]
|
|
|
|
then
|
2024-05-22 18:33:41 +00:00
|
|
|
kubectl exec -ti ${pod} -- bao operator raft join http://$(name_prefix)-0.$(name_prefix)-internal:8200
|
|
|
|
kubectl exec -ti ${pod} -- bao operator unseal ${token}
|
2020-03-18 19:49:14 +00:00
|
|
|
wait_for_ready "${pod}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Sealed, not initialized
|
2024-05-22 18:33:41 +00:00
|
|
|
local sealed_status=$(kubectl exec "$(name_prefix)-0" -- bao status -format=json |
|
2020-03-18 19:49:14 +00:00
|
|
|
jq -r '.sealed' )
|
|
|
|
[ "${sealed_status}" == "false" ]
|
|
|
|
|
2024-05-22 18:33:41 +00:00
|
|
|
local init_status=$(kubectl exec "$(name_prefix)-0" -- bao status -format=json |
|
2020-03-18 19:49:14 +00:00
|
|
|
jq -r '.initialized')
|
|
|
|
[ "${init_status}" == "true" ]
|
|
|
|
|
2024-05-22 18:33:41 +00:00
|
|
|
kubectl exec "$(name_prefix)-0" -- bao login ${root}
|
2020-03-18 19:49:14 +00:00
|
|
|
|
2024-05-22 18:33:41 +00:00
|
|
|
local raft_status=$(kubectl exec "$(name_prefix)-0" -- bao operator raft list-peers -format=json |
|
2020-03-18 19:49:14 +00:00
|
|
|
jq -r '.data.config.servers | length')
|
|
|
|
[ "${raft_status}" == "3" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
kubectl delete namespace acceptance --ignore-not-found=true
|
|
|
|
kubectl create namespace acceptance
|
|
|
|
kubectl config set-context --current --namespace=acceptance
|
|
|
|
}
|
|
|
|
|
|
|
|
#cleanup
|
|
|
|
teardown() {
|
2020-04-09 13:26:58 +00:00
|
|
|
if [[ ${CLEANUP:-true} == "true" ]]
|
|
|
|
then
|
2021-12-11 01:11:35 +00:00
|
|
|
# If the test failed, print some debug output
|
|
|
|
if [[ "$BATS_ERROR_STATUS" -ne 0 ]]; then
|
2024-05-22 18:33:41 +00:00
|
|
|
kubectl logs -l app.kubernetes.io/name=openbao
|
2021-12-11 01:11:35 +00:00
|
|
|
fi
|
2024-05-22 18:33:41 +00:00
|
|
|
helm delete openbao
|
2020-04-09 13:26:58 +00:00
|
|
|
kubectl delete --all pvc
|
|
|
|
kubectl delete namespace acceptance --ignore-not-found=true
|
|
|
|
fi
|
2020-03-18 19:49:14 +00:00
|
|
|
}
|