Kubernetes Web View to list and view all Kubernetes resources https://kube-web-view.readthedocs.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
865 B

from typing import Any
from typing import Dict
def parse_selector(param: str):
if not param:
return None
selector: Dict[str, Any] = {}
conditions = param.split(",")
for condition in conditions:
key, _, val = condition.partition("=")
key = key.strip()
val = val.strip()
if key.endswith("!"):
if key not in selector:
selector[key] = []
selector[key].append(val)
else:
selector[key] = val
return selector
def selector_matches(selector: dict, labels: dict):
if not selector:
return True
for key, val in selector.items():
if key.endswith("!"):
if labels.get(key.rstrip("!")) in val:
return False
else:
if labels.get(key) != val:
return False
return True