Skip to content
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

Add Milestone Job integration tests for Helm Chart #171

Merged
merged 6 commits into from
Aug 20, 2020
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
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ You can now deploy a local development environment for Kubernetes using [Docker

1. Navigate to Docker preferences

1. Click on "Advanced" and slide the "Memory" bar to 6
1. Click on "Resources" and slide the "Memory" bar to 6

1. If you intend to deploy the Secrets Provider via Helm, you will need to install the Helm CLI. See [here](https://helm.sh/docs/intro/install/) for instructions on how to do so.

#### Deploy

Expand All @@ -80,9 +82,9 @@ Run ` kubectl config current-context` to verify which context you are currently

Run `kubectl config use-context docker-desktop` to switch to a local context. This is the context you will need to run the development environment

1. Navigate to `bootstrap.env` and uncomment the `Local DEV Env` section, ensuring that `DEV=true`
1. Navigate to `bootstrap.env` and uncomment the `Local DEV Env` section, ensuring that `DEV=true`. Additionally, you can deploy the Secrets Provider locally using HELM. To do so, _also_ uncomment `DEV_HELM`
sigalsax marked this conversation as resolved.
Show resolved Hide resolved

1. Run `./bin/start --dev --gke`, appending `--oss` or `--dap` according to the environment that needs to be deployed
1. Run `./bin/start --dev`, appending `--oss` or `--dap` according to the environment that needs to be deployed

1. To view the pod(s) that were deployed and the Secrets Provider logs, run `kubectl get pods` and `kubectl logs <pod-name> -c cyberark-secrets-provider` respectively.
You can also view Conjur/DAP pod logs by running `kubectl get pods -n local-conjur` and `kubectl logs <conjur-pod-name> -n local-conjur`
Expand Down
6 changes: 3 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ pipeline {
tasks["Kubernetes GKE, oss"] = {
sh "./bin/start --docker --oss --gke"
}
tasks["Openshift v3.11, oss"] = {
sh "./bin/start --docker --oss --oc311"
}
// tasks["Openshift v3.11, oss"] = {
// sh "./bin/start --docker --oss --oc311"
// }
// skip oc310 tests until the environment will be ready to use
// tasks["Openshift v3.10, oss"] = {
// sh "./bin/start --docker --oss --oc310"
Expand Down
8 changes: 4 additions & 4 deletions bin/build_utils
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ set -euo pipefail

readonly VERSION_GO_FILE="pkg/secrets/version.go"

function short_version_tag() {
short_version_tag() {
grep -v '^//' "${VERSION_GO_FILE}" | grep 'var Version =' | awk -F'= ' '{print $2}' | tr -d '"'
}

function git_tag() {
git_tag() {
git rev-parse --short HEAD
}

function full_version_tag() {
full_version_tag() {
echo "$(short_version_tag)-$(git_tag)"
}

# generate less specific versions, eg. given 1.2.3 will print 1.2 and 1
# (note: the argument itself is not printed, append it explicitly if needed)
function gen_versions() {
gen_versions() {
local version=$1
while [[ $version = *.* ]]; do
version=${version%.*}
Expand Down
4 changes: 2 additions & 2 deletions bin/start
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -ex

function print_help() {
print_help() {
cat << EOF
Test the secrets-provider-for-k8s image. This script sets up a Conjur cluster in k8s and deploys a k8s environment with an app
container and a secrets-provider-for-k8s init container. Finally it tests that the outcome is as expected (for example,
Expand Down Expand Up @@ -29,7 +29,7 @@ EOF
exit
}

function runScriptWithSummon() {
runScriptWithSummon() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer we will work with one convention
Lower-case, with underscores to separate words. (most of our code is written in this way)

Copy link
Contributor Author

@sigalsax sigalsax Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since I didn't write these I dont want to touch them too too much. It will become a huge PR. is that ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already a huge PR. do you have an issue to fix it in another?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in it's own commit so it is contained

summon --environment $SUMMON_ENV -f ./summon/secrets.yml $1
}

Expand Down
6 changes: 4 additions & 2 deletions bootstrap.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export APP_NAMESPACE_NAME=app-$UNIQUE_TEST_ID
# export AUTHENTICATOR_ID=authn-dev-env
# export APP_NAMESPACE_NAME=local-secrets-provider
# export CONJUR_NAMESPACE_NAME=local-conjur
# export DEV=true
# export STOP_RUNNING_ENV=true
# export CONJUR_ACCOUNT=cucumber
# export CONJUR_LOG_LEVEL=debug

# export CONJUR_AUTHENTICATORS=authn-k8s/${AUTHENTICATOR_ID}
# export DEV=true
# Uncomment to deploy the Secrets Provider using HELM
# export DEV_HELM=true
5 changes: 1 addition & 4 deletions deploy/2_create_app_namespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ fi

$cli_with_timeout delete --ignore-not-found rolebinding app-conjur-authenticator-role-binding-$CONJUR_NAMESPACE_NAME

CONFIG_DIR="config/k8s"
if [[ "$PLATFORM" = "openshift" ]]; then
CONFIG_DIR="config/openshift"
fi
set_config_directory_path

wait_for_it 600 "./$CONFIG_DIR/app-conjur-authenticator-role-binding.sh.yml | $cli_without_timeout apply -f -"

Expand Down
36 changes: 23 additions & 13 deletions deploy/dev/5_load_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,40 @@ set -euxo pipefail

. utils.sh

function main() {
main() {
export DEV_HELM=${DEV_HELM:-"false"}
./teardown_resources.sh

set_namespace "$APP_NAMESPACE_NAME"

configure_secret
if [ "${DEV_HELM}" = "true" ]; then
setup_helm_environment

deploy_env
}
create_k8s_secret
export IMAGE_PULL_POLICY="Never"
export IMAGE="secrets-provider-for-k8s"
export TAG="dev"
deploy_chart

deploy_helm_app
else
create_k8s_secret

function configure_secret() {
announce "Configuring K8s Secret and access."
create_secret_access_role

export CONFIG_DIR="$PWD/config/k8s"
if [[ "$PLATFORM" = "openshift" ]]; then
export CONFIG_DIR="$PWD/config/openshift"
create_secret_access_role_binding

orenbm marked this conversation as resolved.
Show resolved Hide resolved
deploy_init_env
fi
}

echo "Create secret k8s-secret"
$cli_with_timeout create -f $CONFIG_DIR/k8s-secret.yml
create_k8s_secret() {
announce "Creating K8s Secret."

create_secret_access_role
set_config_directory_path

create_secret_access_role_binding
echo "Create secret k8s-secret"
$cli_with_timeout create -f $CONFIG_DIR/k8s-secret.yml
}

main
8 changes: 4 additions & 4 deletions deploy/dev/config/k8s/secrets-provider-init-container.sh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: init-env
name: init-env
app: test-env
name: test-env
spec:
replicas: 1
selector:
matchLabels:
app: init-env
app: test-env
template:
metadata:
labels:
app: init-env
app: test-env
spec:
serviceAccountName: ${APP_NAMESPACE_NAME}-sa
containers:
Expand Down
59 changes: 38 additions & 21 deletions deploy/dev/reload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,49 @@ set -xeuo pipefail

. utils.sh

# Script for making it easy to make a change locally and redeploy
pushd ..
./bin/build
popd
main() {
export DEV_HELM=${DEV_HELM:-"false"}

set_namespace $APP_NAMESPACE_NAME
# Clean-up previous run
if [ "$(helm ls -aq | wc -l | tr -d ' ')" != 0 ]; then
helm delete $(helm ls -aq)
fi
$cli_with_timeout "delete deployment test-env --ignore-not-found=true"

docker tag "secrets-provider-for-k8s:dev" "${APP_NAMESPACE_NAME}/secrets-provider"
pushd ..
./bin/build
popd

selector="role=follower"
cert_location="/opt/conjur/etc/ssl/conjur.pem"
if [ "$CONJUR_DEPLOYMENT" = "oss" ]; then
selector="app=conjur-cli"
cert_location="/root/conjur-${CONJUR_ACCOUNT}.pem"
fi
set_namespace $APP_NAMESPACE_NAME

conjur_pod_name=$($cli_with_timeout get pods --selector=$selector --namespace $CONJUR_NAMESPACE_NAME --no-headers | awk '{ print $1 }' | head -1)
ssl_cert=$($cli_with_timeout "exec ${conjur_pod_name} --namespace $CONJUR_NAMESPACE_NAME cat $cert_location")
if [ "${DEV_HELM}" = "true" ]; then
orenbm marked this conversation as resolved.
Show resolved Hide resolved
setup_helm_environment

export CONJUR_SSL_CERTIFICATE=$ssl_cert
export IMAGE_PULL_POLICY="Never"
export IMAGE="secrets-provider-for-k8s"
export TAG="dev"
deploy_chart

export CONFIG_DIR="$PWD/config/k8s"
if [[ "$PLATFORM" = "openshift" ]]; then
export CONFIG_DIR="$PWD/config/openshift"
fi
deploy_helm_app
else
selector="role=follower"
cert_location="/opt/conjur/etc/ssl/conjur.pem"
if [ "$CONJUR_DEPLOYMENT" = "oss" ]; then
selector="app=conjur-cli"
cert_location="/root/conjur-${CONJUR_ACCOUNT}.pem"
fi

$cli_with_timeout "delete deployment init-env --ignore-not-found=true"
conjur_pod_name=$($cli_with_timeout get pods --selector=$selector --namespace $CONJUR_NAMESPACE_NAME --no-headers | awk '{ print $1 }' | head -1)
ssl_cert=$($cli_with_timeout "exec ${conjur_pod_name} --namespace $CONJUR_NAMESPACE_NAME cat $cert_location")

deploy_env
export CONJUR_SSL_CERTIFICATE=$ssl_cert

set_config_directory_path

$cli_with_timeout "delete deployment init-env --ignore-not-found=true"

deploy_init_env
fi
}

main
2 changes: 1 addition & 1 deletion deploy/platform_login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail
IFS=$'\n\t'

function main() {
main() {
# Log in to platform
if [[ "$PLATFORM" = "kubernetes" ]]; then
gcloud auth activate-service-account \
Expand Down
1 change: 1 addition & 0 deletions deploy/policy/templates/conjur-secrets.template.sh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cat << EOL
body:
- &variables
- !variable test_secret
- !variable another_test_secret
- !variable var with spaces
- !variable var+with+pluses

Expand Down
4 changes: 2 additions & 2 deletions deploy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ set -xeuo pipefail
. utils.sh
printenv > /tmp/printenv_local.debug

function main() {
main() {
deployConjur
./run_with_summon.sh
}

function deployConjur() {
deployConjur() {
orenbm marked this conversation as resolved.
Show resolved Hide resolved
pushd ..
git clone [email protected]:cyberark/kubernetes-conjur-deploy kubernetes-conjur-deploy-$UNIQUE_TEST_ID

Expand Down
13 changes: 8 additions & 5 deletions deploy/run_with_summon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ set -xeuo pipefail
. utils.sh

# Clean up when script completes and fails
function finish {
finish() {
# There is a TRAP in test_in_docker.sh to account for Docker deployments so we do not need to add another one here
# Stop the running processes
if [[ $RUN_IN_DOCKER = false && $DEV = false ]]; then
announce 'Wrapping up and removing environment'
./stop
cd ./kubernetes-conjur-deploy-$UNIQUE_TEST_ID && ./stop
repo_root_path=$(git rev-parse --show-toplevel)
"$repo_root_path/deploy/stop"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we do changes for running with summon ?

Copy link
Contributor Author

@sigalsax sigalsax Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this?

Gives us the head of the repo because we pushd in and out of directories so paths get messed up.I was having a real tough time with paths and so this ensures that we are at the root of the repo (thanks @hughsaunders )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but what's happening in this line? you just declare it without doing anything with it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is nothing happening? Stop is being run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See image attached
Screen Shot 2020-08-18 at 8 44 11 AM

pushd $repo_root_path/kubernetes-conjur-deploy-$UNIQUE_TEST_ID
./stop
popd
# Remove the deploy directory
rm -rf "../kubernetes-conjur-deploy-$UNIQUE_TEST_ID"
rm -rf "$repo_root_path/kubernetes-conjur-deploy-$UNIQUE_TEST_ID"
fi
}
trap finish EXIT
Expand Down Expand Up @@ -59,7 +62,7 @@ ssl_cert=$($cli_with_timeout "exec ${conjur_pod_name} --namespace $CONJUR_NAMESP

export CONJUR_SSL_CERTIFICATE=$ssl_cert

if [ "${DEV}" = "false" ]; then
if [[ "${DEV}" = "false" ]]; then
sigalsax marked this conversation as resolved.
Show resolved Hide resolved
pushd ./test/test_cases > /dev/null
./run_tests.sh
popd > /dev/null
Expand Down
43 changes: 37 additions & 6 deletions deploy/teardown_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,62 @@ set -euxo pipefail
set_namespace $CONJUR_NAMESPACE_NAME

configure_cli_pod
if [ "${DEV}" = "false" ]; then
$cli_with_timeout "exec $(get_conjur_cli_pod_name) -- conjur variable values add secrets/test_secret \"supersecret\""

## Helm Chart clean-up
#rm -f conjur.pem

helm_ci_path="../helm/secrets-provider/ci"
if [[ "${DEV}" = "false" || "${RUN_IN_DOCKER}" = "true" ]]; then
helm_ci_path="../../../helm/secrets-provider/ci"
fi
pushd $helm_ci_path
find . -type f ! -name '*template.yaml' -delete
popd
sigalsax marked this conversation as resolved.
Show resolved Hide resolved

# Delete Helm Chart if already exists
set_namespace $APP_NAMESPACE_NAME
if [ "$(helm ls -aq | wc -l | tr -d ' ')" != 0 ]; then
helm delete $(helm ls -aq)
fi

set_namespace $CONJUR_NAMESPACE_NAME

$cli_with_timeout "exec $(get_conjur_cli_pod_name) -- conjur variable values add secrets/test_secret \"supersecret\""
sigalsax marked this conversation as resolved.
Show resolved Hide resolved

set_namespace $APP_NAMESPACE_NAME

$cli_with_timeout "delete secret dockerpullsecret --ignore-not-found=true"

$cli_with_timeout "delete clusterrole secrets-access-${UNIQUE_TEST_ID} --ignore-not-found=true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't we change this to role? if not - why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is part of our previous tests (TEST_ID 1 - 16).
As we spoke about earlier, it is loaded in a different .sh.yml format and so any sort of refactoring will be a whole separate task

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have such a task?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 'sh.yml' are for tests primarily so I think it is worth a discussion with the team. Since we are moving to BDD anyways it might be worth it to weigh this and see if we still need it


$cli_with_timeout "delete role another-secrets-provider-role --ignore-not-found=true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i may have asked this elsewhere but i can't find it - why do we need 2 of each resource? what is the purpose of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short, we have some tests that test two secrets providers (TEST_ID_18_helm_multiple_provider_multiple_secrets.sh) and two secrets providers same secret (TEST_ID_19_helm_multiple_provider_same_secret.sh) and two k8s secrets (TEST_ID_20_helm_service_account_does_not_exist.sh)
2 k8s resources cannot have the same role,rolebinding,serviceaccount,etc so we need to add two of everything for those ones

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't they have the same role and service account?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asked this question to @eladkug and we agreed on two of everything

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd like to challenge that decision. why can't the secrets-providers have the same service account and role? isn't it closer to a customer's environment?

i also want to challenge the decision to have only one file for a secret that is used for 2 secrets. i think that having 2 files is more explicit to what you are trying to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkug please address Oren's first point

@orenbm I am not understanding why having a single files is an issue here. I prefer it being cleaner and having a single one that is dynamically updated and so that we don't have 2 places to clean up and two functions to create the secret etc. Earlier you mentioned why we have two of everything and you were right. I think where we can make resources reused and dynamically created we should because it will lead to a cleaner

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we raised it before its different scenarios.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the multiple files issue is not a blocker.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree


$cli_with_timeout "delete secret test-k8s-secret --ignore-not-found=true"

$cli_with_timeout "delete secret another-test-k8s-secret --ignore-not-found=true"

$cli_with_timeout "delete serviceaccount ${APP_NAMESPACE_NAME}-sa --ignore-not-found=true"

$cli_with_timeout "delete serviceaccount another-secrets-provider-service-account --ignore-not-found=true"

$cli_with_timeout "delete rolebinding secrets-access-role-binding --ignore-not-found=true"

$cli_with_timeout "delete rolebinding another-secrets-provider-role-binding --ignore-not-found=true"

if [ "${PLATFORM}" = "kubernetes" ]; then
$cli_with_timeout "delete deployment test-env --ignore-not-found=true"
$cli_with_timeout "delete deployment another-test-env --ignore-not-found=true"
elif [ "${PLATFORM}" = "openshift" ]; then
$cli_with_timeout "delete deploymentconfig test-env --ignore-not-found=true"
$cli_with_timeout "delete deploymentconfig another-test-env --ignore-not-found=true"
fi

$cli_with_timeout "delete configmap conjur-master-ca-env --ignore-not-found=true"

if [ "${DEV}" = "false" ]; then
echo "Verifying there are no (terminating) pods of type test-env"
$cli_with_timeout "get pods --namespace=$APP_NAMESPACE_NAME --selector app=test-env --no-headers | wc -l | tr -d ' ' | grep '^0$'"
fi
echo "Verifying there are no (terminating) pods of type test-env"
$cli_with_timeout "get pods --namespace=$APP_NAMESPACE_NAME --selector app=test-env --no-headers | wc -l | tr -d ' ' | grep '^0$'"

$cli_with_timeout "get pods --namespace=$APP_NAMESPACE_NAME --selector app=another-test-env --no-headers | wc -l | tr -d ' ' | grep '^0$'"

echo "Verifying there are no (terminating) pods for Secrets Provider deployed with Helm"
$cli_with_timeout "get pods --namespace=$APP_NAMESPACE_NAME --selector app=test-helm --no-headers | wc -l | tr -d ' ' | grep '^0$'"
10 changes: 10 additions & 0 deletions deploy/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ RUN mkdir -p ocbin && \
tar xvf oc.tar.gz --strip-components=1 -C ocbin && \
mv ocbin/oc /usr/local/bin/oc && \
rm -rf ocbin oc.tar.gz

# Install Helm
RUN curl https://baltocdn.com/helm/signing.asc | apt-key add - && \
apt-get install apt-transport-https --yes && \
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list && \
apt-get update && \
apt-get install helm=3.2.*

# Adds ability to perform mathematical operations with floats for testing
RUN apt-get install -y bc
Loading