Skip to content

Commit

Permalink
Add condition for running scan image
Browse files Browse the repository at this point in the history
Adds support for a condition that will look for a secret.  This is integrated with the pipeline to skip the scan-image step if sysdig secret isn't there, unfortunately optional steps are not supported yet in Tekton so the whole rest of the pipeline will fail if there is no secret per here: tektoncd/pipeline#1023
  • Loading branch information
hatmarch committed Aug 7, 2020
1 parent 19a0248 commit 3b35b6e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions kube/tekton/conditions/secret-exists-condition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
name: secret-exists
spec:
params:
- name: SECRET_NAME
description: "The name of the secret to check for in the specified project"
- name: PROJECT
description: "The name of the project in which to seek SECRET_NAME. Defaults to the project this condition is defined in"
default: ""
check:
image: quay.io/openshift/origin-cli:latest
script: |
#!/usr/bin/env bash
set -e -o pipefail
declare CHECK_PRJ="$(params.PROJECT)"
if [[ -z "${CHECK_PRJ}" ]]; then
echo "Looking to the pod to determine the current namespace"
CHECK_PRJ=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
fi
echo "command to run is: oc get secret $(params.SECRET_NAME) -n ${CHECK_PRJ} 2>/dev/null"
# check for non-empty string result looking for secret
test -n "$(oc get secret $(params.SECRET_NAME) -n ${CHECK_PRJ} 2>/dev/null)"
8 changes: 8 additions & 0 deletions kube/tekton/pipelines/fraud-model-dev-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ spec:
- name: workvol
workspace: local-workspace
- name: scan-image
# FIXME: Unfortunately, we can't skip this step and have the rest of the pipeline run in this version of tekton
# See feature request here: https://github.com/tektoncd/pipeline/issues/1023
conditions:
- conditionRef: secret-exists
params:
- name: SECRET_NAME
value: sysdig-secret
# END FIXME
taskRef:
name: sysdig-image-scan
runAfter:
Expand Down

0 comments on commit 3b35b6e

Please sign in to comment.