Skip to content

Commit

Permalink
Support parameters like --values=secrets.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Aug 28, 2020
1 parent d8ef1d6 commit 76b61db
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Don't check if file exists on edit (https://github.com/jkroepke/helm-secrets/pull/31)
- Better Windows support (https://github.com/jkroepke/helm-secrets/pull/28)
- Support parameters like --values=secrets.yaml (https://github.com/jkroepke/helm-secrets/pull/34)

## [3.2.0] - 2020-05-08

Expand Down
21 changes: 15 additions & 6 deletions scripts/commands/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,22 @@ helm_wrapper() {
shift
break
;;
-f | --values)
set -- "$@" "$1"
-f | --values | --values=?*)
case "$1" in
*=*)
file="${1#*=}"

set -- "$@" "${1%%=*}"
;;
*)
file="${2}"

set -- "$@" "$1"
shift
j=$((j + 1))
;;
esac

file="${2}"
file_dec="$(file_dec_name "${file}")"
if [ -f "${file_dec}" ]; then
set -- "$@" "$file_dec"
Expand All @@ -78,9 +90,6 @@ helm_wrapper() {
set -- "$@" "$file"
fi
fi

shift
j=$((j + 1))
;;
*)
set -- "$@" "$1"
Expand Down
60 changes: 60 additions & 0 deletions tests/it/diff.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ load '../bats/extensions/bats-file/load'
assert [ ! -f "${FILE}.dec" ]
}

@test "diff: helm diff upgrade w/ chart + secrets.yaml + --values" {
helm_plugin_install "diff"
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="diff-$(date +%s)-${SEED}"

create_chart "${TEST_TEMP_DIR}"

run helm secrets diff upgrade --no-color --allow-unreleased "${RELEASE}" "${TEST_TEMP_DIR}/chart" --values "${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "port: 81"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]
}

@test "diff: helm diff upgrade w/ chart + secrets.yaml + --values=" {
helm_plugin_install "diff"
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="diff-$(date +%s)-${SEED}"

create_chart "${TEST_TEMP_DIR}"

run helm secrets diff upgrade --no-color --allow-unreleased "${RELEASE}" "${TEST_TEMP_DIR}/chart" --values="${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "port: 81"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]
}

@test "diff: helm diff upgrade w/ chart + some-secrets.yaml" {
helm_plugin_install "diff"
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
Expand All @@ -66,6 +96,36 @@ load '../bats/extensions/bats-file/load'
assert [ ! -f "${FILE}.dec" ]
}

@test "diff: helm diff upgrade w/ chart + some-secrets.yaml + --values" {
helm_plugin_install "diff"
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="diff-$(date +%s)-${SEED}"

create_chart "${TEST_TEMP_DIR}"

run helm secrets diff upgrade --no-color --allow-unreleased "${RELEASE}" "${TEST_TEMP_DIR}/chart" --values "${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "port: 83"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]
}

@test "diff: helm diff upgrade w/ chart + some-secrets.yaml + --values=" {
helm_plugin_install "diff"
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="diff-$(date +%s)-${SEED}"

create_chart "${TEST_TEMP_DIR}"

run helm secrets diff upgrade --no-color --allow-unreleased "${RELEASE}" "${TEST_TEMP_DIR}/chart" --values="${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "port: 83"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]
}

@test "diff: helm diff upgrade w/ chart + secrets.yaml + helm flag" {
helm_plugin_install "diff"
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
Expand Down
68 changes: 68 additions & 0 deletions tests/it/install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@ load '../bats/extensions/bats-file/load'
assert_output --partial "port: 81"
}

@test "install: helm install w/ chart + secrets.yaml + --values" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="install-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets install "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values "${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 81"
}

@test "install: helm install w/ chart + secrets.yaml + --values=" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="install-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets install "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values="${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 81"
}

@test "install: helm install w/ chart + some-secrets.yaml" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="install-$(date +%s)-${SEED}"
Expand All @@ -67,6 +101,40 @@ load '../bats/extensions/bats-file/load'
assert_output --partial "port: 83"
}

@test "install: helm install w/ chart + some-secrets.yaml + --values" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="install-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets install "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values "${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 83"
}

@test "install: helm install w/ chart + some-secrets.yaml + --values=" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="install-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets install "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values="${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 83"
}

@test "install: helm install w/ chart + secrets.yaml + helm flag" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="install-$(date +%s)-${SEED}"
Expand Down
68 changes: 68 additions & 0 deletions tests/it/upgrade.bats
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@ load '../bats/extensions/bats-file/load'
assert_output --partial "port: 81"
}

@test "upgrade: helm upgrade w/ chart + secrets.yaml + --values" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="upgrade-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets upgrade -i "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values "${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 81"
}

@test "upgrade: helm upgrade w/ chart + secrets.yaml + --values=" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="upgrade-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets upgrade -i "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values="${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 81"
}

@test "upgrade: helm upgrade w/ chart + some-secrets.yaml" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="upgrade-$(date +%s)-${SEED}"
Expand All @@ -67,6 +101,40 @@ load '../bats/extensions/bats-file/load'
assert_output --partial "port: 83"
}

@test "upgrade: helm upgrade w/ chart + some-secrets.yaml + --values" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="upgrade-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets upgrade -i "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values "${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 83"
}

@test "upgrade: helm upgrade w/ chart + some-secrets.yaml + --values=" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"
RELEASE="upgrade-$(date +%s)-${SEED}"
create_chart "${TEST_TEMP_DIR}"

run helm secrets upgrade -i "${RELEASE}" "${TEST_TEMP_DIR}/chart" --no-hooks --values="${FILE}" 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "STATUS: deployed"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert [ ! -f "${FILE}.dec" ]

run kubectl get svc -o yaml -l "app.kubernetes.io/name=chart,app.kubernetes.io/instance=${RELEASE}"
assert_success
assert_output --partial "port: 83"
}

@test "upgrade: helm upgrade w/ chart + secrets.yaml + helm flag" {
FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"
RELEASE="upgrade-$(date +%s)-${SEED}"
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/kubeval.bats
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ load '../bats/extensions/bats-file/load'
assert_file_not_exist "${FILE}.dec"
}

@test "kubeval: helm kubeval w/ chart + secrets.yaml + --values" {
helm_plugin_install "kubeval"

FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"

create_chart "${TEST_TEMP_DIR}"

run helm secrets kubeval "${TEST_TEMP_DIR}/chart" --values "${FILE}" --strict 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "The file chart/templates/serviceaccount.yaml contains a valid ServiceAccount"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert_file_not_exist "${FILE}.dec"
}

@test "kubeval: helm kubeval w/ chart + secrets.yaml + --values=" {
helm_plugin_install "kubeval"

FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/secrets.yaml"

create_chart "${TEST_TEMP_DIR}"

run helm secrets kubeval "${TEST_TEMP_DIR}/chart" --values="${FILE}" --strict 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "The file chart/templates/serviceaccount.yaml contains a valid ServiceAccount"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert_file_not_exist "${FILE}.dec"
}

@test "kubeval: helm kubeval w/ chart + some-secrets.yaml" {
helm_plugin_install "kubeval"

Expand All @@ -65,6 +95,36 @@ load '../bats/extensions/bats-file/load'
assert_file_not_exist "${FILE}.dec"
}

@test "kubeval: helm kubeval w/ chart + some-secrets.yaml + --values" {
helm_plugin_install "kubeval"

FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"

create_chart "${TEST_TEMP_DIR}"

run helm secrets kubeval "${TEST_TEMP_DIR}/chart" --values "${FILE}" --strict 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "The file chart/templates/serviceaccount.yaml contains a valid ServiceAccount"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert_file_not_exist "${FILE}.dec"
}

@test "kubeval: helm kubeval w/ chart + some-secrets.yaml + --values=" {
helm_plugin_install "kubeval"

FILE="${TEST_TEMP_DIR}/values/${HELM_SECRETS_DRIVER}/some-secrets.yaml"

create_chart "${TEST_TEMP_DIR}"

run helm secrets kubeval "${TEST_TEMP_DIR}/chart" --values="${FILE}" --strict 2>&1
assert_success
assert_output --partial "[helm-secrets] Decrypt: ${FILE}"
assert_output --partial "The file chart/templates/serviceaccount.yaml contains a valid ServiceAccount"
assert_output --partial "[helm-secrets] Removed: ${FILE}.dec"
assert_file_not_exist "${FILE}.dec"
}

@test "kubeval: helm kubeval w/ chart + secrets.yaml + helm flag" {
helm_plugin_install "kubeval"

Expand Down
Loading

0 comments on commit 76b61db

Please sign in to comment.