Skip to content

Commit

Permalink
fix: shell and logs websocket #28 #29
Browse files Browse the repository at this point in the history
Signed-off-by: devopstales <[email protected]>
  • Loading branch information
devopstales committed Jun 17, 2023
1 parent 0809f6e commit 01b54c7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docker/kubedash/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ echo "Start Migration"
flask db upgrade

echo "Start Gunicorn"
gunicorn --conf gunicorn_conf.py kubedash:app
gunicorn --worker-class eventlet --conf gunicorn_conf.py kubedash:app
3 changes: 2 additions & 1 deletion docker/kubedash/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ gevent-websocket>=0.10.1
eventlet>=0.33.3

# security
gunicorn>=20.1.0
#gunicorn>=20.1.0
https://github.com/benoitc/gunicorn/archive/add8a4c951f02a67ca1f81264e5c107fa68e6496.zip
certifi>=2022.12.7
setuptools>=65.6.3
pyOpenSSL>=23.0.0
Expand Down
22 changes: 12 additions & 10 deletions src/kubedash/functions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ def pods_data():
def pods_logs():
if request.method == 'POST':
session['ns_select'] = request.form.get('ns_select')
print("async_mode: %s" % socketio.async_mode)
logger.info("async_mode: %s" % socketio.async_mode)
return render_template(
'pod-logs.html.j2',
po_name = request.form.get('po_name'),
Expand All @@ -1149,10 +1149,11 @@ def message(data):
else:
user_token = None

global thread
with thread_lock:
if thread is None:
thread = socketio.start_background_task(k8sPodLogsStream, session['user_role'], user_token, session['ns_select'], data)
#global thread
#with thread_lock:
# if thread is None:
# thread = socketio.start_background_task(k8sPodLogsStream, session['user_role'], user_token, session['ns_select'], data)
socketio.start_background_task(k8sPodLogsStream, session['user_role'], user_token, session['ns_select'], data)

##############################################################
## Pod Exec
Expand All @@ -1163,7 +1164,7 @@ def message(data):
def pods_exec():
if request.method == 'POST':
session['ns_select'] = request.form.get('ns_select')
print("async_mode: %s" % socketio.async_mode)
logger.info("async_mode: %s" % socketio.async_mode)
return render_template(
'pod-exec.html.j2',
po_name = request.form.get('po_name'),
Expand All @@ -1188,10 +1189,11 @@ def message(data):
global wsclient
wsclient = k8sPodExecSocket(session['user_role'], user_token, session['ns_select'], data)

global thread
with thread_lock:
if thread is None:
socketio.start_background_task(k8sPodExecStream, wsclient)
#global thread
#with thread_lock:
# if thread is None:
# socketio.start_background_task(k8sPodExecStream, wsclient)
socketio.start_background_task(k8sPodExecStream, wsclient)

@socketio.on("exec-input", namespace="/exec")
@authenticated_only
Expand Down
2 changes: 1 addition & 1 deletion src/kubedash/kubedash.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def create_app(config_name="development"):

if os.getenv('FLASK_CONFIG') == "production":
config_name = "production"
app.config['SECRET_KEY'] = os.urandom(12).hex()
else:
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
app.config['SECRET_KEY'] = os.urandom(12).hex()
logging.captureWarnings(True)
logger.info("Running in %s mode" % config_name)

Expand Down
5 changes: 2 additions & 3 deletions src/kubedash/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash

#export FLASK_APP=kubedash
#export FLASK_DEBUG=1
#export TEMPLATES_AUTO_RELOAD=1
#export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

export FLASK_CONFIG="production"
export FLASK_APP="kubedash"

Expand All @@ -16,4 +14,5 @@ echo "Start Migration"
flask db upgrade

echo "Start Gunicorn"
gunicorn --conf gunicorn_conf.py kubedash:app
#flask run --host=0.0.0.0 --port=8000
gunicorn --worker-class eventlet --conf gunicorn_conf.py kubedash:app
2 changes: 1 addition & 1 deletion src/kubedash/templates/users.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<div class="form-group">
<label>Type:</label>
<select class="form-select" aria-label="Select role" name="type">
<option value="Local">Local</option>
<option value="{{ user.user_type }}">{{ user.user_type }}</option>
{% for contect in k8s_contect_list%}
<option value="{{ contect }}">{{ contect }}</option>
{% endfor %}
Expand Down

0 comments on commit 01b54c7

Please sign in to comment.