diff --git a/forms.py b/forms.py index e9a7874..dc42c43 100644 --- a/forms.py +++ b/forms.py @@ -9,7 +9,8 @@ from flask_bootstrap import Bootstrap class deploySelectForm(FlaskForm): + tiller_ns = SelectField('tiller_ns', choices=[], coerce=str) namespace = SelectField('namespace', choices=[], coerce=str) chart = SelectField('chart', choices=[]) version = SelectField('remember me') - submitButton = SubmitField("Submit") \ No newline at end of file + submitButton = SubmitField("Submit") diff --git a/main.py b/main.py index 820ca84..1651edf 100644 --- a/main.py +++ b/main.py @@ -28,6 +28,18 @@ def get_namespaces(): data = json.loads(output) return data +def get_tiller_namespaces(): + command = "/usr/local/bin/kubectl get po --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}") @@ -40,8 +52,9 @@ def get_deployments(namespace): data = json.loads(output) return data -def get_charts(namespace): - command = "/usr/bin/helm -n " + namespace + " list -ojson" +def get_charts(tiller_ns, namespace): + command = "/usr/bin/helm --tiller-namespace " + tiller_ns + " list -ojson" #helm2 + #command = "/usr/bin/helm -n " + namespace + " list -ojson" #helm3 info(f"Running command: {command}") try: output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8") @@ -52,8 +65,9 @@ def get_charts(namespace): data = json.loads(output) return data -def get_chartdata(namespace, chart): - command = "/usr//bin/helm -n " + namespace + " history " + chart + " -ojson" +def get_chartdata(tiller_ns, namespace, chart): + command = "/usr/bin/helm --tiller-namespace " + tiller_ns + " history " + chart + " -ojson" #helm2 + #command = "/usr/bin/helm -n " + namespace + " history " + chart + " -ojson" #helm3 info(f"Running command: {command}") print(f"Running command: {command}") try: diff --git a/routes/.nfs0000000000029d2200000001 b/routes/.nfs0000000000029d2200000001 new file mode 100644 index 0000000..ec2f3a4 Binary files /dev/null and b/routes/.nfs0000000000029d2200000001 differ diff --git a/routes/.nfs0000000000029d2f00000002 b/routes/.nfs0000000000029d2f00000002 new file mode 100644 index 0000000..d60c0b1 Binary files /dev/null and b/routes/.nfs0000000000029d2f00000002 differ diff --git a/routes/kube_helm_routes.py b/routes/kube_helm_routes.py index 6fd82ba..4983ec9 100644 --- a/routes/kube_helm_routes.py +++ b/routes/kube_helm_routes.py @@ -1,32 +1,34 @@ from flask import render_template, request, jsonify from forms import deploySelectForm -from main import get_namespaces, get_charts, get_chartdata +from main import get_namespaces, get_charts, get_chartdata, get_tiller_namespaces from . import routes from tables import chartVersionTable import json @routes.route('/', methods=['GET', 'POST']) def index(): + tiller_ns = get_tiller_namespaces() namespaces = get_namespaces() - print(namespaces) form = deploySelectForm() + form.tiller_ns.choices = [(name['metadata']['namespace'], name['metadata']['namespace']) for name in tiller_ns['items']] form.namespace.choices = [(name['metadata']['name'], name['metadata']['name']) for name in namespaces['items']] - return render_template('nameChartSelect.html', namespaces=namespaces, form=form) + return render_template('nameChartSelect.html', namespaces=namespaces, tiller_ns=tiller_ns, form=form) @routes.route('/chartSelect', methods=['POST']) def chartVersions(): namespace = request.form['namespace'] + tiller_ns = request.form['tiller_ns'] chart = request.form['chart'] - chartVersions = get_chartdata(namespace, chart) + chartVersions = get_chartdata(tiller_ns, namespace, chart) table = chartVersionTable(chartVersions) table.border = True table.classes = ['table-striped', 'table-condensed', 'table-hover'] return render_template('chartRevisionList.html', table=table, namespace=namespace) -@routes.route('/nsLookup/') -def namespaceLookup(namespace): - charts = get_charts(namespace) +@routes.route('/nsLookup//') +def namespaceLookup(tiller, namespace): + charts = get_charts(tiller, namespace) return jsonify(charts) @routes.route('/deployChartRevision///', methods=['POST']) @@ -35,4 +37,4 @@ def deployChartRevision(revision, chart, namespace): print(chart) print(namespace) charts = get_charts(namespace) - return jsonify(charts) \ No newline at end of file + return jsonify(charts) diff --git a/templates/nameChartSelect.html b/templates/nameChartSelect.html index 9b97fa5..48057a5 100644 --- a/templates/nameChartSelect.html +++ b/templates/nameChartSelect.html @@ -18,13 +18,21 @@
- Namespace: - {{ form.namespace(class_="form-control") }} + Tiller Namespace: + {{ form.tiller_ns(class_="form-control") }}
- Chart: + Namespace: + {{ form.namespace(class_="form-control") }} +
+
+
+
+
+
+ Chart: {{ form.chart(class_="form-control") }}
@@ -36,20 +44,24 @@
+ dd