Merge branch 'master' of ssh://git.ervine.org/jonny/flask-python-helm

This commit is contained in:
Jonathan Ervine 2020-12-28 15:45:17 +08:00
commit e021f099a8
7 changed files with 34 additions and 28 deletions

View File

@ -6,16 +6,14 @@ LABEL MAINTAINER="Jonathan Ervine <jonathan.ervine@gogox.com>"
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/*

17
main.py
View File

@ -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")

View File

@ -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/<ns>/<namespace>')
=======
@routes.route('/nsLookup/<ns>')
>>>>>>> a7df40eb7710553f5d0185c3fa04ea6991c06f89
def namespaceLookup(ns):
charts = get_charts(ns)
return jsonify(charts)
@routes.route('/deployChartRevision/<revision>/<chart>/<tiller_ns>', methods=['POST'])
@routes.route('/deployChartRevision/<revision>/<chart>/<ns>', methods=['POST'])
def deployChartRevision(revision, chart, tiller_ns):
rollback = chartRollback(revision, chart, tiller_ns)
rollback = chartRollback(revision, chart, ns)
return rollback

View File

@ -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"})
deploy = ButtonCol('Deploy', 'routes.deployChartRevision', url_kwargs=dict(revision='revision', chart='chartName', ns='ns'), button_attrs={"type" : "submit", "class" : "btn btn-danger"})

View File

@ -23,4 +23,6 @@
{{ table }}
</table>
<a class="btn btn-primary" href="/" role="button">Home</a>
</body>
<br>
<a class="btn btn-primary" href="/oauth2/sign_out" role="button">Log Off</a>
</body>

View File

@ -43,6 +43,8 @@
{{ form.submitButton(class_="btn btn-success") }}
<a class="btn btn-danger" href="/" role="button">Cancel</a>
</p>
<br>
<a class="btn btn-primary" href="/oauth2/sign_out" role="button">Log Off</a>
</form>
</div>
</div>
@ -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 += '<option value="' + chart.Name + '">' + chart.Name + '</option>';
for (var chart of data) {
optionHTML += '<option value="' + chart.name + '">' + chart.name + '</option>';
}
chartSelect.innerHTML = optionHTML;
}
@ -76,4 +78,4 @@
}
</script>
</body>
</html>
</html>

View File

@ -32,7 +32,9 @@
<p>
{{ form.submitButton(class_="btn btn-success") }}
<a class="btn btn-danger" href="/" role="button">Cancel</a>
</p>
<br>
<a class="btn btn-primary" href="/oauth2/sign_out" role="button">Log Off</a>
</p>
</form>
</div>
</div>
@ -62,4 +64,4 @@
}
</script>
</body>
</html>
</html>