Skip to content

Commit f83a591

Browse files
committed
fix must have config bug
1 parent a429a08 commit f83a591

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

kubesys/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ class KubernetesClient():
3535
def __init__(self, url=None, token=None, analyzer=None,
3636
config=None, relearning=True) -> None:
3737
# if not url and not token:
38-
self.config = readConfig(config)
38+
self.config = config
3939

4040
if self.config is None:
4141
if url is None or token is None:
4242
sys.exit('missing url or token')
4343
self.url = url.rstrip("/")
4444
self.token = token
4545
else:
46+
self.config = readConfig(config)
4647
self.url = self.config.server
4748
self.token = None
4849

watch-resources-example.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##
2+
# Copyright (2021, ) Institute of Software, Chinese Academy of Sciences
3+
##
4+
import os.path
5+
6+
import yaml
7+
8+
from kubesys.client import KubernetesClient
9+
from kubesys.common import dictToJsonString, getActiveThreadCount, goodPrintDict
10+
from kubesys.watch_handler import WatchHandler
11+
import time
12+
13+
14+
def test_watcher(client, namespce, kind):
15+
print("--start to watch...")
16+
client.watchResources(kind=kind, namespace=namespce, watcherhandler=WatchHandler(
17+
add_func=lambda json_dict: print(kind, "ADDED ", dictToJsonString(json_dict)[:20]),
18+
modify_func=lambda json_dict: print(kind, "MODIFIED ", dictToJsonString(json_dict)[:20]),
19+
delete_func=lambda json_dict: print(kind, "DELETED ", dictToJsonString(json_dict)[:20])))
20+
time.sleep(10000)
21+
22+
23+
if __name__ == '__main__':
24+
client = KubernetesClient(url="https://133.133.135.193:8443",
25+
token="")
26+
test_watcher(client=client, namespce="", kind="Pod")

0 commit comments

Comments
 (0)