Skip to content

Commit

Permalink
Merge pull request #110 from kkirara/sort_list
Browse files Browse the repository at this point in the history
default sort, base_path
  • Loading branch information
kkirara authored Feb 21, 2024
2 parents 71d8f2d + 899f2bf commit 59aefdd
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ cython_debug/

# kubeconfig and cache
.kube/
charts/kubelinks/values_test.yaml
6 changes: 4 additions & 2 deletions charts/kubelinks/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ spec:
- name: {{ $val.name }}
value: {{ $val.value | quote }}
{{- end }}
- name: KUBELINKS_BASE_PATH
value: {{ .Values.base_path | quote }}
livenessProbe:
httpGet:
path: /healthz/live
path: {{ .Values.base_path }}/healthz/live
port: http
readinessProbe:
httpGet:
path: /healthz/ready
path: {{ .Values.base_path }}/healthz/ready
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
Expand Down
20 changes: 15 additions & 5 deletions charts/kubelinks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,33 @@ extraUrls: []
#- name: mycustomurl3
# url: nothinghere.io
# URL filters allow you filter list of URLs
# Warning for match!!! Searches for a substring in url, not a regular expression
# Warning for match!!! Searches for a substring in url, a regular expression
urlFilters: []
# - match:string
# replace: blabla (optional)
# hide: true/false (optional)
# pretty_name: blablabla (optional)
#
# - match: (/|$)(.*)
# replace: ""
# - match: foo/bar.+
# replace: foo
# - match: .io
# hide: true
# - match: https://flux.dash.com
# pretty_name: Flux dashboard
# You can change the header change KUBELINKS_TITLE
# If you want to see namespace change KUBELINKS_ENABLED_NAMESPACE to 1
# you can add base path for example if you want add path /kubelinks/home
# change base_path: "/kubelinks"
base_path: ""
# ENV
# KUBELINKS_TITLE - you can change the header
# KUBELINKS_ENABLED_NAMESPACE - if you want to see namespace change to 1
# KUBELINKS_DEFAULT_SORT - you can create default sort change
# use list the field names without spaces separated by commas value: "pretty_name,url_type"
# name,url,url_name,url_type,namespace,pretty_name
# pretty_name - sort url_name without http then sort url_name start with http
env:
- name: KUBELINKS_TITLE
value: "Ingress and Istio urls"
- name: KUBELINKS_ENABLED_NAMESPACE
value: 0
- name: KUBELINKS_DEFAULT_SORT
value: ""
7 changes: 5 additions & 2 deletions extraConfigs/urlFilters.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
- match: (/|$)(.*)
replace: ""
- match: http://wild.bar.com/bar/.+
replace: http://wild.bar.com/bar/foo
pretty_name: Wild reg bar
- match: http://wild.bar.com/bar.+
replace: http://wild.bar.com/bar
- match: foo2
hide: true
- match: https://eu.bookinfo.com
Expand Down
4 changes: 2 additions & 2 deletions kubelinks_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def create_app(config=config.ProdactionConfig):
app = Flask(__name__)
app.config.from_object(config)

app.register_blueprint(healthz, url_prefix="/healthz")
app.register_blueprint(home_bp)
app.register_blueprint(home_bp, url_prefix=config.BASE_PATH)
app.register_blueprint(healthz, url_prefix=f"{config.BASE_PATH}/healthz")

try:
kube_config.load_config()
Expand Down
5 changes: 5 additions & 0 deletions kubelinks_app/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import os
from kubelinks_app.url_list import extra_list
SET_SORT_FIELD = ('name', 'url', 'url_name', 'url_type',
'namespace', 'pretty_name')


class Config(object):
DEBUG = True
TESTING = True
TITLE = os.getenv('KUBELINKS_TITLE', 'Ingress and Istio urls')
ENABLED_NAMESPACE = bool(int(os.getenv('KUBELINKS_ENABLED_NAMESPACE', 0)))
BASE_PATH = os.getenv('KUBELINKS_BASE_PATH', '')
DEFAULT_SORT = [item.strip() for item in os.getenv(
'KUBELINKS_DEFAULT_SORT', '').lower().split(',') if item.strip() in SET_SORT_FIELD]
HEALTHZ = {
"live": lambda: None,
"ready": lambda: None,
Expand Down
10 changes: 4 additions & 6 deletions kubelinks_app/static/js/color-modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
: "light";
};

const setTheme = function (theme) {
const setTheme = (theme) => {
if (theme === "auto") {
document.documentElement.setAttribute(
"data-bs-theme",
Expand All @@ -25,13 +25,15 @@
}
};

const setStyle = function (theme) {
const setStyle = (theme) => {
const is_dark = theme === "dark";
document.getElementById("div-table").classList.toggle("shadow", !is_dark);
document.getElementById("div-table").classList.toggle("border", is_dark);
};

setTheme(getPreferredTheme());
document.getElementById("themeMode").checked = getPreferredTheme() === "dark";
setStyle(getPreferredTheme());

window
.matchMedia("(prefers-color-scheme: dark)")
Expand All @@ -43,10 +45,6 @@
});

window.addEventListener("DOMContentLoaded", () => {
document.getElementById("themeMode").checked =
getPreferredTheme() === "dark";
setStyle(getPreferredTheme());

document.getElementById("themeMode").addEventListener("change", () => {
const theme = document.getElementById("themeMode").checked
? "dark"
Expand Down
2 changes: 1 addition & 1 deletion kubelinks_app/static/js/color-modes.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions kubelinks_app/static/js/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function createFilterInput(header) {
input.classList.add("form-control-sm");
input.type = "text";
input.placeholder = "Filter...";
input.setAttribute("id", "field");
input.addEventListener("input", applyFilters);
filters[field] = input;
return input;
Expand All @@ -47,6 +48,7 @@ function createFilterSelect(header) {
const select = document.createElement("select");
select.classList.add("form-select");
select.classList.add("form-select-sm");
select.setAttribute("autocomplete", "off");
select.id = field;
var option = document.createElement("option");
option.value = "";
Expand Down
2 changes: 1 addition & 1 deletion kubelinks_app/static/js/table.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions kubelinks_app/url_list/extra_list.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import yaml
from dataclasses import dataclass

from kubelinks_app.logger import logger


@dataclass
class Extra_URL():
name: str = None
url: str = None
url_name: str = None
url_type: str = 'ExtraURL'
from kubelinks_app.url_list.url_class import Extra_URL


def get_extraurls_list():
Expand All @@ -24,7 +16,8 @@ def get_extraurls_list():
list_extraurls.append(Extra_URL(
name=item['name'],
url=item['url'],
url_name=item.get('url_name') or item.get('url')))
url_name=item.get('url_name') or item.get('url')
))
except Exception as e:
logger.error(f'ExtraUrls: {e}')
logger.debug('ExtraUrls: FINISH')
Expand Down
16 changes: 3 additions & 13 deletions kubelinks_app/url_list/gateway_list.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import json
from kubernetes import client
from types import SimpleNamespace
from dataclasses import dataclass

from kubelinks_app.logger import logger
from kubernetes import client
from kubelinks_app.url_list.url_class import Http_Gateway


HTTPS = ['HTTPS']
HTTP = ["HTTP", "HTTP2"]


@dataclass
class Http_Gateway():
name: str = None
url: str = None
url_name: str = None
url_type: str = 'gateway'
is_https: bool = False
host: str = None
namespace: str = None


def dict2obj(data):
return json.loads(json.dumps(data),
object_hook=lambda d: SimpleNamespace(**d))
Expand Down
13 changes: 2 additions & 11 deletions kubelinks_app/url_list/ingress_list.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
from dataclasses import dataclass

from kubelinks_app.logger import logger
from kubernetes import client


@dataclass
class Http_Ingress():
name: str = None
url: str = None
url_name: str = None
url_type: str = 'ingress'
namespace: str = None
from kubelinks_app.logger import logger
from kubelinks_app.url_list.url_class import Http_Ingress


def get_url_name(is_https: bool, host, path):
Expand Down
31 changes: 31 additions & 0 deletions kubelinks_app/url_list/url_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from dataclasses import dataclass


@dataclass
class Url():
name: str = None
url: str = None
url_name: str = None
url_type: str = None
namespace: str = None

@property
def pretty_name(self):
return (1 if self.url_name.startswith('http') else 0, self.url_name)


@dataclass
class Extra_URL(Url):
url_type: str = 'ExtraURL'


@dataclass
class Http_Ingress(Url):
url_type: str = 'ingress'


@dataclass
class Http_Gateway(Url):
url_type: str = 'gateway'
is_https: bool = False
host: str = None
16 changes: 12 additions & 4 deletions kubelinks_app/url_list/url_list.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import re
import copy

from kubelinks_app.logger import logger
from kubelinks_app.config import Config
from kubelinks_app.url_list import gateway_list, ingress_list
import copy
import re


def get_urls(urls_type: int = 0, use_filter: bool = False):
Expand All @@ -19,6 +20,11 @@ def get_urls(urls_type: int = 0, use_filter: bool = False):
case 3: urls = extraurls
case _: urls = extraurls + ingress + gateway

if len(Config.DEFAULT_SORT) > 0:
logger.debug(f'get_urls: SORT = {Config.DEFAULT_SORT}')
urls.sort(key=lambda x: [getattr(x, fileld_name)
for fileld_name in Config.DEFAULT_SORT])

return {'urls': urls,
'ingress': len(ingress),
'gateway': len(gateway),
Expand Down Expand Up @@ -62,7 +68,8 @@ def apply_filter(matched_filter, item):
new_item = copy.copy(item)
same_names = new_item.url == new_item.url_name
if 'replace' in matched_filter.keys():
new_item.url = re.sub(matched_filter["match"], matched_filter["replace"], new_item.url)
new_item.url = re.sub(
matched_filter["match"], matched_filter["replace"], new_item.url)

if matched_filter.get('pretty_name', ''):
new_item.url_name = matched_filter.get('pretty_name', '')
Expand All @@ -73,7 +80,8 @@ def apply_filter(matched_filter, item):

def find_filter(item):
for filter in Config.URL_FILTERS:
logger.debug(f'filter["match"]= {filter["match"]} item.url= {item.url}')
logger.debug(
f'filter["match"]= {filter["match"]} item.url= {item.url}')
if re.search(filter["match"], item.url):
logger.debug(f'filter= {filter}')
return filter
Expand Down

0 comments on commit 59aefdd

Please sign in to comment.