From 665afb5183f671c24555e0a2e1c44f649174b66a Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 12:13:15 +0800 Subject: [PATCH 01/17] Update HTML javacsript --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 9fa1e69..028d9e0 100644 --- a/main.py +++ b/main.py @@ -49,9 +49,8 @@ def get_deployments(namespace): data = json.loads(output) return data -def get_charts(tiller_ns, namespace): - command = "/usr/local/bin/helm --tiller-namespace " + tiller_ns + " list --output json" #helm2 - #command = "/usr/local/bin/helm -n " + namespace + " list -ojson" #helm3 +def get_charts(ns): + command = "/usr/local/bin/helm -n " + namespace + " list -ojson" #helm3 info(f"Running command: {command}") try: output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") From b59e2d73a2ac801d0b2dea93a7360bafa5371785 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 12:29:07 +0800 Subject: [PATCH 02/17] Fix namespace lookup code --- main.py | 10 ++++------ routes/kube_helm_routes.py | 6 +++--- templates/nameChartSelect.html | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 028d9e0..61ff79e 100644 --- a/main.py +++ b/main.py @@ -67,9 +67,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(namespace, chart, records): + command = "/usr/local/bin/helm -n " + namespace + " history " + chart + " --max " + records + " -ojson" #helm3 info(f"Running command: {command}") try: output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") @@ -82,11 +81,10 @@ def get_chartdata(tiller_ns, namespace, chart, records): for revision in data: revision['chartName'] = chart revision["namespace"] = namespace - revision["tiller_ns"] = tiller_ns return data -def chartRollback(revision, chart, tiller_ns): - command = "/usr/local/bin/helm --tiller-namespace " + tiller_ns + " rollback " + chart + " " + revision # helm2 +def chartRollback(ns, revision, chart): + command = "/usr/local/bin/helm -n " + ns + " rollback " + chart + " " + revision # helm2 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 184de81..86147ac 100644 --- a/routes/kube_helm_routes.py +++ b/routes/kube_helm_routes.py @@ -25,9 +25,9 @@ def chartVersions(): return render_template('chartRevisionList.html', table=table) -@routes.route('/nsLookup//') -def namespaceLookup(tiller_ns, namespace): - charts = get_charts(tiller_ns, namespace) +@routes.route('/nsLookup/') +def namespaceLookup(ns): + charts = get_charts(ns) return jsonify(charts) @routes.route('/deployChartRevision///', methods=['POST']) diff --git a/templates/nameChartSelect.html b/templates/nameChartSelect.html index 17a72a4..f47d91c 100644 --- a/templates/nameChartSelect.html +++ b/templates/nameChartSelect.html @@ -59,7 +59,7 @@ 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 = ''; From 02bbf98084f2e65f42e58202437de48ce6a7159d Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 12:47:18 +0800 Subject: [PATCH 03/17] Fixing helm chart lookup --- main.py | 2 +- templates/nameChartSelect.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 61ff79e..69d9301 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,7 @@ def get_deployments(namespace): return data def get_charts(ns): - command = "/usr/local/bin/helm -n " + namespace + " list -ojson" #helm3 + command = "/usr/local/bin/helm -n " + ns + " list -ojson" #helm3 info(f"Running command: {command}") try: output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") diff --git a/templates/nameChartSelect.html b/templates/nameChartSelect.html index f47d91c..4171be7 100644 --- a/templates/nameChartSelect.html +++ b/templates/nameChartSelect.html @@ -64,7 +64,7 @@ if (data != 'EMPTY') { var optionHTML = ''; for (var chart of data.Releases) { - optionHTML += ''; + optionHTML += ''; } chartSelect.innerHTML = optionHTML; } From 7bf1de86be665acd0ab8643ff63c7442f412e146 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 13:18:23 +0800 Subject: [PATCH 04/17] Remove print command --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 69d9301..269f7a6 100644 --- a/main.py +++ b/main.py @@ -21,8 +21,6 @@ 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 def get_tiller_namespaces(): From 09470d125a904a374c6f284d40c87ac838a9f390 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 13:39:16 +0800 Subject: [PATCH 05/17] List charts from namespace correctly --- templates/nameChartSelect.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/nameChartSelect.html b/templates/nameChartSelect.html index 4171be7..2b6c06c 100644 --- a/templates/nameChartSelect.html +++ b/templates/nameChartSelect.html @@ -63,7 +63,7 @@ response.json().then(function(data) { if (data != 'EMPTY') { var optionHTML = ''; - for (var chart of data.Releases) { + for (var chart of data) { optionHTML += ''; } chartSelect.innerHTML = optionHTML; From a8a7a19fddb08e5b642cc1a3682200849f90e93b Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 13:42:21 +0800 Subject: [PATCH 06/17] Remove tiller namespace lookup --- main.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/main.py b/main.py index 269f7a6..1d31045 100644 --- a/main.py +++ b/main.py @@ -23,18 +23,6 @@ def get_namespaces(): ns = v1.list_namespace() return ns -def get_tiller_namespaces(): - command = "/usr/local/bin/kubectl get deploy --all-namespaces -l name=tiller -ojson" - info(f"Running command: {command}") - try: - output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") - except CalledProcessError as err: - error(err.output.decode("utf-8")) - raise err - info(f"Output from command:\n{output}") - data = json.loads(output) - return data - def get_deployments(namespace): command = "/usr/local/bin/kubectl -n " + namespace + " get deploy -ojson" info(f"Running command: {command}") From 92868a330756bf273d5483a8842323850817415d Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 13:45:20 +0800 Subject: [PATCH 07/17] Fix chart list to use helm3 --- routes/kube_helm_routes.py | 5 ++--- tables.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/routes/kube_helm_routes.py b/routes/kube_helm_routes.py index 86147ac..54dc44a 100644 --- a/routes/kube_helm_routes.py +++ b/routes/kube_helm_routes.py @@ -14,11 +14,10 @@ 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) + namespace = request.form['ns'] + chartVersions = get_chartdata(namespace, chart, records) table = chartVersionTable(chartVersions) table.border = True table.classes = ['table-striped', 'table-condensed', 'table-hover'] diff --git a/tables.py b/tables.py index 85bb003..8b11938 100644 --- a/tables.py +++ b/tables.py @@ -4,7 +4,6 @@ class chartVersionTable(Table): revision = Col('Chart Revision') updated = Col('Updated') status = Col('Status') - tiller_ns = Col('Tiiler 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 From 317d0b1a0642c6751ac7ea4fde50b4f98846edd7 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 13:53:47 +0800 Subject: [PATCH 08/17] Fix rollback to use helm3 --- main.py | 4 ++-- routes/kube_helm_routes.py | 4 ++-- tables.py | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 1d31045..6c586d0 100644 --- a/main.py +++ b/main.py @@ -69,8 +69,8 @@ def get_chartdata(namespace, chart, records): revision["namespace"] = namespace return data -def chartRollback(ns, revision, chart): - command = "/usr/local/bin/helm -n " + 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 54dc44a..3f3231b 100644 --- a/routes/kube_helm_routes.py +++ b/routes/kube_helm_routes.py @@ -29,7 +29,7 @@ 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 8b11938..773a91b 100644 --- a/tables.py +++ b/tables.py @@ -4,6 +4,7 @@ class chartVersionTable(Table): revision = Col('Chart Revision') updated = Col('Updated') status = Col('Status') + 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 From 6b6895d62e19f7cb3acccdce83f52d0d0160cf99 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 13:54:23 +0800 Subject: [PATCH 09/17] Remove kuibectl commands --- main.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/main.py b/main.py index 6c586d0..f2b637c 100644 --- a/main.py +++ b/main.py @@ -23,18 +23,6 @@ def get_namespaces(): ns = v1.list_namespace() return ns -def get_deployments(namespace): - command = "/usr/local/bin/kubectl -n " + namespace + " get deploy -ojson" - info(f"Running command: {command}") - try: - output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") - except CalledProcessError as err: - error(err.output.decode("utf-8")) - raise err - info(f"Output from command:\n{output}") - data = json.loads(output) - return data - def get_charts(ns): command = "/usr/local/bin/helm -n " + ns + " list -ojson" #helm3 info(f"Running command: {command}") From f79ca80094194a10cd36e5528bf52480fe266436 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:10:15 +0800 Subject: [PATCH 10/17] Remove reference to get tiller namespace --- routes/kube_helm_routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/kube_helm_routes.py b/routes/kube_helm_routes.py index 3f3231b..7493569 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 From 5f9096e6b2282a1126949123b10c242ecd12568d Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:21:22 +0800 Subject: [PATCH 11/17] Standardise variable names --- routes/kube_helm_routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/kube_helm_routes.py b/routes/kube_helm_routes.py index 7493569..2507592 100644 --- a/routes/kube_helm_routes.py +++ b/routes/kube_helm_routes.py @@ -16,7 +16,7 @@ def index(): def chartVersions(): chart = request.form['chart'] records = request.form['records'] - namespace = request.form['ns'] + ns = request.form['ns'] chartVersions = get_chartdata(namespace, chart, records) table = chartVersionTable(chartVersions) table.border = True From 5a88c253a5e4e8325d172670bddce6d1d4befc9d Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:22:09 +0800 Subject: [PATCH 12/17] Standardise variable names --- routes/kube_helm_routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/kube_helm_routes.py b/routes/kube_helm_routes.py index 2507592..a18efa9 100644 --- a/routes/kube_helm_routes.py +++ b/routes/kube_helm_routes.py @@ -17,7 +17,7 @@ def chartVersions(): chart = request.form['chart'] records = request.form['records'] ns = request.form['ns'] - chartVersions = get_chartdata(namespace, chart, records) + chartVersions = get_chartdata(ns, chart, records) table = chartVersionTable(chartVersions) table.border = True table.classes = ['table-striped', 'table-condensed', 'table-hover'] From 820e6b6ce8f1d590e044c7f156cf12fef55fbfe8 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:23:11 +0800 Subject: [PATCH 13/17] Standardise variable names --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index f2b637c..e0d5c1d 100644 --- a/main.py +++ b/main.py @@ -41,8 +41,8 @@ def get_charts(ns): def sortRevision(n): return n['revision'] -def get_chartdata(namespace, chart, records): - command = "/usr/local/bin/helm -n " + namespace + " history " + chart + " --max " + records + " -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") @@ -54,7 +54,7 @@ def get_chartdata(namespace, chart, records): data.sort(reverse=True, key=sortRevision) for revision in data: revision['chartName'] = chart - revision["namespace"] = namespace + revision["namespace"] = ns return data def chartRollback(revision, chart, ns): From 24489389648b23339839974f8ded4dfcedc94d22 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine <57888439+jervine-gogo@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:52:10 +0800 Subject: [PATCH 14/17] Standardise variable names --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index e0d5c1d..f205039 100644 --- a/main.py +++ b/main.py @@ -54,7 +54,7 @@ def get_chartdata(ns, chart, records): data.sort(reverse=True, key=sortRevision) for revision in data: revision['chartName'] = chart - revision["namespace"] = ns + revision["ns"] = ns return data def chartRollback(revision, chart, ns): From add3f7df7598c851389bd127447dc7670bcde15a Mon Sep 17 00:00:00 2001 From: Jonathan Ervine Date: Fri, 18 Dec 2020 09:55:27 +0800 Subject: [PATCH 15/17] Add test sign out button --- templates/nameChartSelect.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/nameChartSelect.html b/templates/nameChartSelect.html index 2b6c06c..8cf46a7 100644 --- a/templates/nameChartSelect.html +++ b/templates/nameChartSelect.html @@ -43,6 +43,8 @@ {{ form.submitButton(class_="btn btn-success") }} Cancel

+
+ Log Off @@ -76,4 +78,4 @@ } - \ No newline at end of file + From 6456a4a3ab8926b6398638c76c0ee222ac05f47e Mon Sep 17 00:00:00 2001 From: Jonathan Ervine Date: Fri, 18 Dec 2020 11:06:13 +0800 Subject: [PATCH 16/17] Fixed URL --- Dockerfile | 6 ++---- templates/nameChartSelect.html | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) 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/templates/nameChartSelect.html b/templates/nameChartSelect.html index 8cf46a7..82637b3 100644 --- a/templates/nameChartSelect.html +++ b/templates/nameChartSelect.html @@ -44,7 +44,7 @@ Cancel


- Log Off + Log Off From 25e2b74b9611c07e69ff941ccf01423e125a78ba Mon Sep 17 00:00:00 2001 From: Jonathan Ervine Date: Fri, 18 Dec 2020 13:37:21 +0800 Subject: [PATCH 17/17] Added more logout buttons --- templates/chartRevisionList.html | 4 +++- templates/nameDeploySelect.html | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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/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 +