Skip to content

Commit

Permalink
Merge pull request #772 from zregvart/issue/EC-379
Browse files Browse the repository at this point in the history
Fix tkn-bundle task and add test
  • Loading branch information
lcarva authored Jan 31, 2024
2 parents a6d791a + 565bb62 commit 6b862ce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
45 changes: 43 additions & 2 deletions task/tkn-bundle/0.1/spec/tkn-bundle_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,30 @@ Describe "tkn-bundle task"
curl https://i.jpillora.com/kubernetes-sigs/kind | bash
mv kind "$HOME/.local/bin"
fi
kind get clusters -q | grep -q "${CLUSTER_NAME}" || kind create cluster -q --name="${CLUSTER_NAME}" || { echo 'ERROR: Unable to create a kind cluster'; return 1; }
kind get clusters -q | grep -q "${CLUSTER_NAME}" || {
cat <<EOF | kind create cluster -q --name="${CLUSTER_NAME}" --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
apiServer:
extraArgs:
"service-node-port-range": "1-65535"
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 5000
hostPort: 5000
listenAddress: 127.0.0.1
protocol: TCP
EOF
} || { echo 'ERROR: Unable to create a kind cluster'; return 1; }
kubectl cluster-info 2>&1 || { echo 'ERROR: Failed to access the cluster'; return 1; }

# Install Tekton Pipeline, proceed with the rest of the test of the setup
Expand Down Expand Up @@ -90,7 +113,7 @@ spec:

# Deploy an image registry and expose it via a Service
kubectl create deployment registry --image=docker.io/registry:2.8.1 --port=5000 --dry-run=client -o yaml | kubectl apply -f -
kubectl create service clusterip registry --tcp=5000:5000 --dry-run=client -o yaml | kubectl apply -f -
kubectl create service nodeport registry --tcp=5000:5000 --dry-run=client -o yaml | kubectl patch -f - --type json --dry-run=client -o yaml -p '[{"op": "add", "path": "/spec/ports/0/nodePort", "value":5000}]' | kubectl apply -f -
kubectl wait deployment registry --for=condition=Available --timeout=3m

# Finally wait for Tekton Pipeline to be available
Expand Down Expand Up @@ -163,4 +186,22 @@ spec:
The taskrun should jq '.status.results[] | select(.name=="IMAGE_URL").value | test("\\Aregistry:5000/bundle:summer-home\\z")'
The taskrun should jq '.status.taskSpec.stepTemplate.env[] | select(.name == "HOME").value | test("\\A/tekton/summer-home\\z")'
End

It 'allows overriding the bundle step image'
build_and_inspect() {
tkn task start tkn-bundle -p IMAGE=registry:5000/bundle:replaced-image -p STEPS_IMAGE=registry.io/repository/replaced:latest --use-param-defaults --timeout 1m --showlog -w name=source,claimName=source-pvc
tkn bundle list -o=go-template --template '{{range .spec.steps}}{{printf "%s\n" .image}}{{end}}' localhost:5000/bundle:replaced-image
}

When call build_and_inspect
The output should include 'Added Task: test1 to image'
The output should include 'Added Task: test2 to image'
The output should include 'Added Task: test3 to image'
The output should include 'Pushed Tekton Bundle to registry:5000/bundle'
The output should include 'registry.io/repository/replaced:latest
registry.io/repository/replaced:latest
registry.io/repository/replaced:latest'
The output should not include 'ubuntu'
The stderr should include "*Warning*: This is an experimental command, it's usage and behavior can change in the next release(s)"
End
End
4 changes: 2 additions & 2 deletions task/tkn-bundle/0.1/tkn-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
- name: TASK_FILE
value: tekton_task_files
steps:
- image: registry.access.redhat.com/ubi9/toolbox@sha256:7391628396216c011ed3a310f1fa54c6a9221e36f7fa59c94ae7796de51e7a25
- image: quay.io/redhat-appstudio/hacbs-test:latest@sha256:866675ee3064cf4768691ecca478063ce12f0556fb9d4f24ca95c98664ffbd43
name: modify-task-files
env:
- name: CONTEXT
Expand Down Expand Up @@ -104,7 +104,7 @@ spec:
if [[ -n "${STEPS_IMAGE}" ]]; then
for f in "${FILES[@]}"; do
yq e '(.spec.steps[] | select(has("image")).image) = "env(STEPS_IMAGE)"' -i $f
yq --in-place --yml-output '(.spec.steps[] | select(has("image")).image) = env.STEPS_IMAGE' "$f"
done
fi
Expand Down

0 comments on commit 6b862ce

Please sign in to comment.