Skip to content

Commit 403d570

Browse files
committed
Development client/server
1 parent 2c8254a commit 403d570

File tree

3 files changed

+1322
-864
lines changed

3 files changed

+1322
-864
lines changed

workshop/demo-client/app.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
year = datetime.now().year
1010

11-
VERSION = "1.9.0"
11+
VERSION = "1.0.0"
1212
CAPTION = f"© {year} Splunk Inc. All rights reserved. **Version {VERSION}**"
1313

1414
st.set_page_config(
@@ -29,15 +29,16 @@
2929
if not "valid_inputs_received" in st.session_state:
3030
st.session_state.valid_inputs_received = False
3131

32-
with st.form("demo_form") as form:
33-
host = st.text_input("Host", placeholder="hostname")
34-
port = st.text_input("Port", placeholder="8083", value="8083")
35-
query = st.selectbox("Query", ("pods", "health", "Deploy Online Boutique"))
36-
submit_button = st.form_submit_button(label="Submit")
32+
with st.sidebar:
33+
with st.form("demo_form") as form:
34+
host = st.text_input("Host", placeholder="hostname")
35+
port = st.text_input("Port", placeholder="8083", value="8083")
36+
query = st.selectbox("Query", ("pods", "health", "Deploy Online Boutique"))
37+
submit_button = st.form_submit_button(label="Submit")
3738

38-
if submit_button:
39-
st.cache_data.clear()
40-
st.session_state.valid_inputs_received = True
39+
if submit_button:
40+
st.cache_data.clear()
41+
st.session_state.valid_inputs_received = True
4142

4243
if st.session_state.valid_inputs_received == False:
4344
st.warning(

workshop/demo-server/app.py

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
1-
from kubernetes import client, config, utils
1+
#from kubernetes import client, config, utils
22
from flask import Flask, json, jsonify, request
33
from os import path
44
import yaml
55
import pandas as pd
6-
6+
import kr8s
7+
from kr8s.objects import objects_from_files
8+
import kr8s.asyncio
9+
import os
10+
import subprocess
711
app = Flask(__name__)
812

9-
config.load_kube_config()
13+
#config.load_kube_config()
14+
15+
#core_v1 = client.CoreV1Api()
16+
#apps_v1 = client.AppsV1Api()
17+
#api = client.ApiClient()
18+
19+
def otel_collector_init():
20+
get_chart = subprocess.check_output(["helm", "repo", "add", "splunk-otel-collector-chart", "https://signalfx.github.io/splunk-otel-collector-chart"])
21+
helm_update = subprocess.check_output(["helm", "repo", "update"])
22+
print(get_chart)
23+
print(helm_update)
1024

11-
core_v1 = client.CoreV1Api()
12-
apps_v1 = client.AppsV1Api()
13-
api = client.ApiClient()
1425

26+
@app.route('start_collector', methods=['GET'])
27+
def start_collector():
28+
start = subprocess.check_output
1529
@app.route('/pods', methods=['GET'])
1630
def get_pods():
17-
result = core_v1.list_pod_for_all_namespaces(_preload_content=False)
18-
pods = json.loads(result.data)
19-
df = pd.DataFrame(columns=["Namespace", "Name", "Status", "Pod IP"])
20-
21-
for r in pods['items']:
22-
row = (r["metadata"]["namespace"], r["metadata"]["name"], r["status"]["phase"], r["status"]["podIP"])
31+
df = pd.DataFrame(columns=["Namespace", "Name", "Status", "HostIP"])
32+
pods = kr8s.get("pods", namespace=kr8s.ALL)
33+
for pod in pods:
34+
print(pod.raw)
35+
row = (pod.raw["metadata"]["namespace"], pod.raw["metadata"]["name"], pod.raw["status"]["phase"], pod.raw["status"]["hostIP"])
2336
df.loc[len(df)] = row
2437

38+
2539
return df.to_dict(orient='records')
2640

2741

@@ -30,21 +44,38 @@ def health():
3044
return "OK"
3145

3246

33-
@app.route('/apply_deployment', methods=['POST'])
47+
@app.route('/apply_deployment', methods=['GET'])
3448
def deployment():
49+
try:
3550
deployment = "deployment.yaml"
3651
#resp = apps_v1.create_namespaced_deployment(
3752
# body=deployment, namespace=namespace, _preload_content=False)
38-
resp = utils.create_from_yaml(api, deployment, namespace="default")
39-
print(resp)
53+
#resp = utils.create_from_yaml(api, deployment, namespace="default")
54+
#print(resp)
55+
resources = objects_from_files(deployment)
56+
for r in resources:
57+
print(r)
58+
r.create()
4059
return "200"
60+
except Exception as e:
61+
return str(e)
4162

4263
@app.route('/delete_deployment', methods=['GET'])
4364
def delete_deployment():
44-
filename = request.args.get('type', default = 'deployment.yaml', type = str)
45-
namespace = request.args.get('namespace', default = 'default', type = str)
46-
resp = apps_v1.delete_namespaced_deployment(name="nginx-deployment", namespace=namespace, _preload_content=False)
47-
return resp
65+
try:
66+
deployment = "deployment.yaml"
67+
resources = objects_from_files(deployment)
68+
for r in resources:
69+
print(r)
70+
r.delete()
71+
return "200"
72+
except Exception as e:
73+
return str(e)
74+
#filename = request.args.get('type', default = 'deployment.yaml', type = str)
75+
#namespace = request.args.get('namespace', default = 'default', type = str)
76+
#resp = apps_v1.delete_namespaced_deployment(name="nginx-deployment", namespace=namespace, _preload_content=False)
77+
#return resp
4878

4979
if __name__ == '__main__':
50-
app.run(host="0.0.0.0", port=8083, debug=True)
80+
otel_collector_init()
81+
app.run(host="0.0.0.0", port=8083, debug=True)

0 commit comments

Comments
 (0)