Skip to content

Commit

Permalink
Initial tekton work
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMGranger committed Feb 9, 2022
1 parent 115ee76 commit 99f6cc1
Show file tree
Hide file tree
Showing 29 changed files with 848 additions and 259 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/chart-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Install chart-testing tool `ct`
uses: helm/chart-testing-action@v2.1.0
- name: Lint Helm charts
uses: helm/chart-testing-action@v1.0.0-rc.2
with:
version: "v3.4.0"

- name: Lint charts
run: ct lint --config ct.yaml
command: lint
config: ct.yaml
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,4 @@ policy/

# BATS
_test/test_helper/
_test/prometheus/rules.yaml

# Helm
charts/pelorus/Chart.lock
_test/prometheus/rules.yaml
21 changes: 2 additions & 19 deletions chart_schema.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
name: str()
home: str(required=False)
version: str()
apiVersion: str()
appVersion: any(str(), num(), required=False)
description: str(required=False)
keywords: list(str(), required=False)
sources: list(str(), required=False)
maintainers: list(include('maintainer'), required=False)
dependencies: list(include('dependency'), required=False)
icon: str(required=False)
engine: str(required=False)
condition: str(required=False)
tags: str(required=False)
deprecated: bool(required=False)
kubeVersion: str(required=False)
annotations: map(str(), str(), required=False)
type: str(required=False)
---
maintainer:
name: str()
name: str(required=False)
email: str(required=False)
url: str(required=False)
---
dependency:
name: str()
version: str()
repository: str(required=False)
condition: str(required=False)
tags: list(str(), required=False)
enabled: bool(required=False)
import-values: any(list(str()), list(include('import-value')), required=False)
alias: str(required=False)
---
import-value:
child: str()
parent: str()
url: str(required=False)
6 changes: 1 addition & 5 deletions charts/pelorus/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 1.4.5

dependencies:
- name: exporters
version: "v1.3.0"
version: 1.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
source:
contextDir: {{ .source_context_dir }}
git:
ref: {{ .source_ref | default "v1.4.1" }}
ref: {{ .source_ref | default "1.3.0.1" }}
uri: {{ .source_url }}
type: Git
strategy:
Expand Down
83 changes: 83 additions & 0 deletions demo/demo-tekton
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash
#Assumes User is logged in to cluster
set -euo pipefail

all_cmds_found=0
for cmd in oc tkn; do
if ! which -s $cmd; then
echo "No $cmd executable found in $PATH" >&2
all_cmds_found=1
fi
done
if ! [[ $all_cmds_found ]]; then exit 1; fi


tekton_setup_dir="$(dirname $BASH_SOURCE)/tekton-demo-setup"
python_example_txt="$(dirname $BASH_SOURCE)/python-example/response.txt"

echo "Setting up resources:"

echo "1. Installing tekton operator"
oc apply -f "$tekton_setup_dir/01-tekton-operator.yaml"

echo "2. Setting up python tekton project"
if ! project_setup_output="$(oc apply -f $tekton_setup_dir/02-project.yaml 2>&1)"; then
if echo "$project_setup_output" | grep -q "AlreadyExists"; then
echo "Project already exists"
else
echo "$project_setup_output" >&2
exit 1
fi
else
echo "$project_setup_output"
fi


echo "3. Setting up build and deployment information"
oc process -f "$tekton_setup_dir/03-build-and-deploy.yaml" | oc apply -f -

route="$(oc get -n basic-python-tekton route/basic-python-tekton --output=go-template='http://{{.spec.host}}')"

url=$1

counter=1

current_branch="$(git symbolic-ref HEAD)"
current_branch=${current_branch##refs/heads/}

function run_pipeline {
tkn pipeline start -n basic-python-tekton --showlog basic-python-tekton-pipeline \
-w name=repo,claimName=basic-python-tekton-build-pvc \
-p git-url="$url" -p git-revision="$current_branch"
}

echo -e "\nRunning pipeline\n"
run_pipeline

echo -e "\nWhen ready, page will be available at $route"

while true; do
echo ""
echo "The pipeline and first run of the demo app has started. When it has finished, you may rerun (with commits) or quit now."
echo "1. Rerun with Commit"
echo "2. Quit"
read -p "Type 1 or 2: " -n 1 a
echo ""
case $a in
1* )
echo "We've modified this file, time to build and deploy a new version. Times modified: $counter" | tee -a "$python_example_txt"
git commit -m "modifying python example, number $counter" -- "$python_example_txt"
git push origin "$current_branch"

run_pipeline

echo -e "\nWhen ready, page will be available at $route"

counter=$((counter+1))
;;

2* ) exit 0 ;;
* ) echo "I'm not sure what $a means, please give 1 or 2" >&2 ;;
esac
done

1 change: 1 addition & 0 deletions demo/demo.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#Test oc tool
#Assumes User is logged in to cluster
set -e

path=$1
url=$2
Expand Down
33 changes: 33 additions & 0 deletions demo/python-example/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from http.server import HTTPServer, BaseHTTPRequestHandler

response_file_bytes = b""
response_file_txt = ""


class ResponseHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.log_message(
f"Got request, returning {response_file_txt} (as bytes {response_file_bytes})"
)
self.send_response(200, "PELORUS IS COOL")
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(response_file_bytes)))
self.end_headers()

self.wfile.write(response_file_bytes)


def main():
global response_file_txt, response_file_bytes
with open("response.txt", "br") as f:
response_file_bytes = f.read()
response_file_txt = response_file_bytes.decode("utf-8")
print(
f"Loaded response.txt with contents {response_file_txt} (as bytes {response_file_bytes})"
)
server = HTTPServer(("", 8080), ResponseHandler)
server.serve_forever()


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions demo/python-example/response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
10 changes: 10 additions & 0 deletions demo/tekton-demo-setup/01-tekton-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-pipelines-operator
namespace: openshift-operators
spec:
channel: stable
name: openshift-pipelines-operator-rh
source: redhat-operators
sourceNamespace: openshift-marketplace
6 changes: 6 additions & 0 deletions demo/tekton-demo-setup/02-project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: project.openshift.io/v1
kind: ProjectRequest
displayName: Basic Python Tekton App
metadata:
name: basic-python-tekton
creationTimestam: null
Loading

0 comments on commit 99f6cc1

Please sign in to comment.