diff --git a/Dockerfile b/Dockerfile index 3e1ae92..c093629 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,16 +6,14 @@ LABEL MAINTAINER="Jonathan Ervine " ENV LANG='en_US.UTF-8' \ LANGUAGE='en_US.UTF-8' \ FLASK_APP=/data/app-dev/app.py \ - VERSION=1.1.4 + VERSION=1.1.5 RUN apk update && \ apk -U upgrade --ignore alpine-baselayout && \ apk -U add python3 gcc py3-pip python3-dev musl-dev libffi-dev git curl && \ adduser -D python && \ - mkdir /data && cd /data && git clone --single-branch --branch master https://github.com/jervine-gogo/python-helm-web /data && \ + mkdir /data && cd /data && git clone --single-branch --branch issue-#2 https://github.com/jervine-gogo/python-helm-web /data && \ pip3 install -r /data/requirements.txt && \ - curl -L "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl && \ - chmod 755 /usr/local/bin/kubectl && \ curl -L https://get.helm.sh/helm-v2.13.1-linux-amd64.tar.gz -o /tmp/helm-2.13.1.tgz && \ tar -zxvf /tmp/helm-2.13.1.tgz --strip-components=1 -C /usr/local/bin linux-amd64/helm && \ rm -rf /tmp/src && rm -rf /var/cache/apk/* diff --git a/main.py b/main.py index 63261ff..ab09c7e 100644 --- a/main.py +++ b/main.py @@ -21,10 +21,9 @@ def get_namespaces(): config.load_incluster_config() v1 = client.CoreV1Api() ns = v1.list_namespace() - for namespace in ns.items: - print("%s" % (namespace.metadata.name)) return ns +<<<<<<< HEAD def get_tiller_namespaces(): command = "/usr/local/bin/kubectl get deploy --all-namespaces -l name=tiller -ojson" info(f"Running command: {command}") @@ -49,6 +48,8 @@ def get_deployments(namespace): data = json.loads(output) return data +======= +>>>>>>> a7df40eb7710553f5d0185c3fa04ea6991c06f89 def get_charts(ns): command = "/usr/local/bin/helm -n " + ns + " list -ojson" #helm3 info(f"Running command: {command}") @@ -67,9 +68,8 @@ def get_charts(ns): def sortRevision(n): return n['revision'] -def get_chartdata(tiller_ns, namespace, chart, records): - command = "/usr/local/bin/helm --tiller-namespace " + tiller_ns + " history " + chart + " --max " + records + " --output json" #helm2 - #command = "/usr/local/bin/helm -n " + namespace + " history " + chart + " -ojson" #helm3 +def get_chartdata(ns, chart, records): + command = "/usr/local/bin/helm -n " + ns + " history " + chart + " --max " + records + " -ojson" #helm3 info(f"Running command: {command}") try: output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") @@ -81,12 +81,11 @@ def get_chartdata(tiller_ns, namespace, chart, records): data.sort(reverse=True, key=sortRevision) for revision in data: revision['chartName'] = chart - revision["namespace"] = namespace - revision["tiller_ns"] = tiller_ns + revision["ns"] = ns return data -def chartRollback(revision, chart, tiller_ns): - command = "/usr/local/bin/helm --tiller-namespace " + tiller_ns + " rollback " + chart + " " + revision # helm2 +def chartRollback(revision, chart, ns): + command = "/usr/local/bin/helm -n " + ns + " rollback " + chart + " " + revision # helm3? info(f"Running command: {command}") try: output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") diff --git a/routes/kube_helm_routes.py b/routes/kube_helm_routes.py index 32835eb..53ba0ce 100644 --- a/routes/kube_helm_routes.py +++ b/routes/kube_helm_routes.py @@ -1,6 +1,6 @@ from flask import render_template, request, jsonify from forms import deploySelectForm -from main import get_namespaces, get_charts, get_chartdata, get_tiller_namespaces, chartRollback +from main import get_namespaces, get_charts, get_chartdata, chartRollback from . import routes from tables import chartVersionTable import json @@ -14,23 +14,26 @@ def index(): @routes.route('/chartSelect', methods=['POST']) def chartVersions(): - tiller_ns = request.form['tiller_ns'] chart = request.form['chart'] records = request.form['records'] - namespace = 'default' - chartVersions = get_chartdata(tiller_ns, namespace, chart, records) + ns = request.form['ns'] + chartVersions = get_chartdata(ns, chart, records) table = chartVersionTable(chartVersions) table.border = True table.classes = ['table-striped', 'table-condensed', 'table-hover'] return render_template('chartRevisionList.html', table=table) +<<<<<<< HEAD @routes.route('/nsLookup//') +======= +@routes.route('/nsLookup/') +>>>>>>> a7df40eb7710553f5d0185c3fa04ea6991c06f89 def namespaceLookup(ns): charts = get_charts(ns) return jsonify(charts) -@routes.route('/deployChartRevision///', methods=['POST']) +@routes.route('/deployChartRevision///', methods=['POST']) def deployChartRevision(revision, chart, tiller_ns): - rollback = chartRollback(revision, chart, tiller_ns) + rollback = chartRollback(revision, chart, ns) return rollback \ No newline at end of file diff --git a/tables.py b/tables.py index 85bb003..773a91b 100644 --- a/tables.py +++ b/tables.py @@ -4,7 +4,7 @@ class chartVersionTable(Table): revision = Col('Chart Revision') updated = Col('Updated') status = Col('Status') - tiller_ns = Col('Tiiler Namespace') + ns = Col('Namespace') chart = Col('Chart Version') description = Col('Description') - deploy = ButtonCol('Deploy', 'routes.deployChartRevision', url_kwargs=dict(revision='revision', chart='chartName', tiller_ns='tiller_ns'), button_attrs={"type" : "submit", "class" : "btn btn-danger"}) \ No newline at end of file + deploy = ButtonCol('Deploy', 'routes.deployChartRevision', url_kwargs=dict(revision='revision', chart='chartName', ns='ns'), button_attrs={"type" : "submit", "class" : "btn btn-danger"}) \ No newline at end of file diff --git a/templates/chartRevisionList.html b/templates/chartRevisionList.html index afd34d1..6de4ee5 100644 --- a/templates/chartRevisionList.html +++ b/templates/chartRevisionList.html @@ -23,4 +23,6 @@ {{ table }} Home - \ No newline at end of file +
+ Log Off + diff --git a/templates/nameChartSelect.html b/templates/nameChartSelect.html index 17a72a4..82637b3 100644 --- a/templates/nameChartSelect.html +++ b/templates/nameChartSelect.html @@ -43,6 +43,8 @@ {{ form.submitButton(class_="btn btn-success") }} Cancel

+
+ Log Off @@ -59,12 +61,12 @@ ns = nsSelect.value; - fetch('/nsLookup/' + ns + '/default').then(function(response) { + fetch('/nsLookup/' + ns).then(function(response) { response.json().then(function(data) { if (data != 'EMPTY') { var optionHTML = ''; - for (var chart of data.Releases) { - optionHTML += ''; + for (var chart of data) { + optionHTML += ''; } chartSelect.innerHTML = optionHTML; } @@ -76,4 +78,4 @@ } - \ No newline at end of file + diff --git a/templates/nameDeploySelect.html b/templates/nameDeploySelect.html index 4e2fb0e..9bc7ff9 100644 --- a/templates/nameDeploySelect.html +++ b/templates/nameDeploySelect.html @@ -32,7 +32,9 @@

{{ form.submitButton(class_="btn btn-success") }} Cancel -

+
+ Log Off +

@@ -62,4 +64,4 @@ } - \ No newline at end of file +