2018-11-28 22:40:37 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load _helpers
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
@test "server/ha: testing deployment" {
|
|
|
|
cd `chart_dir`
|
2019-08-22 15:05:31 +00:00
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
helm install --name="$(name_prefix)" \
|
|
|
|
--set='server.ha.enabled=true' .
|
|
|
|
wait_for_running $(name_prefix)-0
|
2018-11-28 22:40:37 +00:00
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
# Sealed, not initialized
|
|
|
|
local sealed_status=$(kubectl exec "$(name_prefix)-0" -- vault status -format=json |
|
|
|
|
jq -r '.sealed' )
|
2018-11-28 22:40:37 +00:00
|
|
|
[ "${sealed_status}" == "true" ]
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
local init_status=$(kubectl exec "$(name_prefix)-0" -- vault status -format=json |
|
|
|
|
jq -r '.initialized')
|
2018-11-28 22:40:37 +00:00
|
|
|
[ "${init_status}" == "false" ]
|
2019-07-31 18:26:12 +00:00
|
|
|
|
2019-09-23 05:11:04 +00:00
|
|
|
# Security
|
|
|
|
local ipc=$(kubectl get statefulset "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.template.spec.containers[0].securityContext.capabilities.add[0]')
|
|
|
|
[ "${ipc}" == "IPC_LOCK" ]
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
# 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')
|
|
|
|
[ "${volumeCount}" == "1" ]
|
|
|
|
|
|
|
|
# Volumes
|
|
|
|
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
|
|
|
|
jq -r '.spec.template.spec.volumes | length')
|
|
|
|
[ "${volumeCount}" == "1" ]
|
|
|
|
|
|
|
|
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')
|
2019-08-08 18:14:58 +00:00
|
|
|
[ "${service}" != "None" ]
|
2019-07-31 18:26:12 +00:00
|
|
|
|
|
|
|
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" ]
|
|
|
|
|
|
|
|
# Vault Init
|
|
|
|
local token=$(kubectl exec -ti "$(name_prefix)-0" -- \
|
|
|
|
vault operator init -format=json -n 1 -t 1 | \
|
|
|
|
jq -r '.unseal_keys_b64[0]')
|
|
|
|
[ "${token}" != "" ]
|
|
|
|
|
|
|
|
# Vault Unseal
|
2019-08-07 18:55:32 +00:00
|
|
|
local pods=($(kubectl get pods --selector='app.kubernetes.io/name=vault' -o json | jq -r '.items[].metadata.name'))
|
2019-07-31 18:26:12 +00:00
|
|
|
for pod in "${pods[@]}"
|
2019-08-22 15:05:31 +00:00
|
|
|
do
|
2019-07-31 18:26:12 +00:00
|
|
|
kubectl exec -ti ${pod} -- vault operator unseal ${token}
|
|
|
|
done
|
|
|
|
|
|
|
|
wait_for_ready "$(name_prefix)-0"
|
|
|
|
|
|
|
|
# Sealed, not initialized
|
|
|
|
local sealed_status=$(kubectl exec "$(name_prefix)-0" -- vault status -format=json |
|
|
|
|
jq -r '.sealed' )
|
|
|
|
[ "${sealed_status}" == "false" ]
|
|
|
|
|
|
|
|
local init_status=$(kubectl exec "$(name_prefix)-0" -- vault status -format=json |
|
|
|
|
jq -r '.initialized')
|
|
|
|
[ "${init_status}" == "true" ]
|
2018-11-28 22:40:37 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
# TODO: Auto unseal test
|
|
|
|
|
2018-11-28 22:40:37 +00:00
|
|
|
# setup a consul env
|
|
|
|
setup() {
|
2019-07-31 18:26:12 +00:00
|
|
|
helm install https://github.com/hashicorp/consul-helm/archive/v0.8.1.tar.gz \
|
2018-11-28 22:40:37 +00:00
|
|
|
--name consul \
|
|
|
|
--set 'ui.enabled=false' \
|
2018-11-28 22:54:03 +00:00
|
|
|
|
2019-08-22 15:05:31 +00:00
|
|
|
wait_for_running_consul
|
2018-11-28 22:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#cleanup
|
|
|
|
teardown() {
|
2019-08-22 15:05:31 +00:00
|
|
|
helm delete --purge vault
|
2018-11-30 22:01:25 +00:00
|
|
|
helm delete --purge consul
|
2019-08-22 15:05:31 +00:00
|
|
|
kubectl delete --all pvc
|
2018-11-28 22:40:37 +00:00
|
|
|
}
|