Skip to content

Commit

Permalink
Added Secret Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Aneesh Bhat authored and Aneesh Bhat committed Dec 4, 2023
1 parent 1e6fe27 commit 524dd0c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ E2E_PVC ?= test/e2e/resources/pvc-maven.yaml
E2E_MAVEN_PARAMS_REVISION ?= master
E2E_MAVEN_PARAMS_URL ?= https://github.com/shashirajraja/shopping-cart
E2E_TEST_DIR ?= ./test/e2e
E2E_MAVEN_PARAMS_SERVER_SECRET ?= secret-maven

# generic arguments employed on most of the targets
ARGS ?=
Expand All @@ -38,7 +39,6 @@ endef
# renders the task resource file printing it out on the standard output
helm-template:
$(call render-template)

# renders and installs the resources (task)
install:
$(call render-template) |kubectl $(ARGS) apply -f -
Expand Down
1 change: 1 addition & 0 deletions scripts/maven-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ if [ -n "${SERVER_USER}" -a -n "${SERVER_PASSWORD}" ]; then
xml="$xml\
</server>"
sed -i "s|<!-- ### SERVER's USER INFO from ENV ### -->|$xml|" ${MAVEN_SETTINGS_FILE}
echo "SERVER Creds Updated"
fi

if [ -n "${PARAMS_MAVEN_MIRROR_URL}" ]; then
Expand Down
12 changes: 12 additions & 0 deletions templates/task-maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spec:
The subdirectory within the repository for sources on
which we want to execute maven goals.
default: "."
- name: SERVER_SECRET
type: string

stepTemplate:
env:
Expand All @@ -53,6 +55,16 @@ spec:
env:
- name: HOME
value: /tekton/home
- name: SERVER_USER
valueFrom:
secretKeyRef:
name: $(params.SERVER_SECRET)
key: username
- name: SERVER_PASSWORD
valueFrom:
secretKeyRef:
name: $(params.SERVER_SECRET)
key: password
command:
- /scripts/maven-generate.sh
securityContext:
Expand Down
12 changes: 5 additions & 7 deletions test/e2e/e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ source ./test/helper/helper.sh
@test "[e2e] maven task" {
[ -n "${E2E_MAVEN_PARAMS_URL}" ]
[ -n "${E2E_MAVEN_PARAMS_REVISION}" ]
[ -n "${E2E_MAVEN_PARAMS_SERVER_SECRET}" ]

kubectl delete secret secret-maven || true

kubectl delete secret regcred || true
run kubectl create secret generic regcred \
--from-file=.dockerconfigjson=$HOME/.docker/config.json \
--type=kubernetes.io/dockerconfigjson
assert_success
run kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regcred"}]}'
assert_success
kubectl apply -f test/e2e/resources/secret-maven.yaml

run tkn pipeline start task-maven \
--param="URL=${E2E_MAVEN_PARAMS_URL}" \
--param="REVISION=${E2E_MAVEN_PARAMS_REVISION}" \
--param="VERBOSE=true" \
--param="SERVER_SECRET=${E2E_MAVEN_PARAMS_SERVER_SECRET}" \
--workspace="name=source,claimName=task-maven,subPath=source" \
--filename=test/e2e/resources/pipeline-maven.yaml \
--showlog
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/resources/pipeline-maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ spec:
type: string
- name: VERBOSE
type: string
- name: SERVER_SECRET
type: string

tasks:
- name: git
Expand All @@ -37,6 +39,9 @@ spec:
- name: maven
taskRef:
name: maven
params:
- name: SERVER_SECRET
value: "$(params.SERVER_SECRET)"
runAfter:
- git
workspaces:
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/resources/secret-maven.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: secret-maven
type: Opaque
stringData:
username: some-username
password: some-password

0 comments on commit 524dd0c

Please sign in to comment.