kaqing 1.98.140__py3-none-any.whl → 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,15 +34,20 @@ class UndeployPod(Command):
34
34
  if not self.validate_state(state):
35
35
  return state
36
36
 
37
- if KubeContext.in_cluster():
38
- log2('This is doable only from outside of the Kubernetes cluster.')
39
- return state
40
-
41
37
  label_selector = Config().get('pod.label-selector', 'run=ops')
42
- ServiceAccounts.delete(state.namespace, label_selector=label_selector)
43
- Deployments.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
38
+ try:
39
+ ServiceAccounts.delete(state.namespace, label_selector=label_selector)
40
+ except Exception as e:
41
+ log2(e)
42
+ try:
43
+ Deployments.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
44
+ except Exception as e:
45
+ log2(e)
44
46
  # instantly destroy the pod
45
- Pods.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
47
+ try:
48
+ Pods.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
49
+ except Exception as e:
50
+ log2(e)
46
51
  undeploy_frontend(state.namespace, label_selector)
47
52
 
48
53
  return state
@@ -1,36 +1,9 @@
1
- from collections.abc import Callable
2
- from concurrent.futures import ThreadPoolExecutor, as_completed
3
- import sys
4
- import time
5
- from typing import TypeVar, cast
6
1
  from kubernetes import client
7
- from kubernetes.stream import stream
8
- from kubernetes.stream.ws_client import ERROR_CHANNEL
9
2
 
10
- from adam.config import Config
11
3
  from adam.k8s_utils.pods import Pods
12
- from adam.pod_exec_result import PodExecResult
13
- from adam.utils import elapsed_time, log2
14
- from .kube_context import KubeContext
15
-
16
- T = TypeVar('T')
17
- _TEST_POD_EXEC_OUTS: PodExecResult = None
18
4
 
19
5
  # utility collection on deployments; methods are all static
20
6
  class Deployments:
21
- def set_test_pod_exec_outs(outs: PodExecResult):
22
- global _TEST_POD_EXEC_OUTS
23
- _TEST_POD_EXEC_OUTS = outs
24
-
25
- return _TEST_POD_EXEC_OUTS
26
-
27
- def delete(pod_name: str, namespace: str):
28
- try:
29
- v1 = client.CoreV1Api()
30
- api_response = v1.delete_namespaced_pod(pod_name, namespace)
31
- except Exception as e:
32
- log2("Exception when calling CoreV1Api->delete_namespaced_pod: %s\n" % e)
33
-
34
7
  def delete_with_selector(namespace: str, label_selector: str, grace_period_seconds: int = None):
35
8
  v1 = client.AppsV1Api()
36
9
 
@@ -38,134 +11,6 @@ class Deployments:
38
11
  for i in ret.items:
39
12
  v1.delete_namespaced_deployment(name=i.metadata.name, namespace=namespace, grace_period_seconds=grace_period_seconds)
40
13
 
41
- def on_pods(pods: list[str],
42
- namespace: str,
43
- body: Callable[[ThreadPoolExecutor, str, str, bool], T],
44
- post: Callable[[T], T] = None,
45
- action: str = 'action', max_workers=0, show_out=True) -> list[T]:
46
- show_out = KubeContext.show_out(show_out)
47
-
48
- if not max_workers:
49
- max_workers = Config().action_workers(action, 0)
50
- if max_workers > 0:
51
- # if parallel, node sampling is suppressed
52
- if KubeContext.show_parallelism():
53
- log2(f'Executing on all nodes from statefulset in parallel...')
54
- start_time = time.time()
55
- try:
56
- with ThreadPoolExecutor(max_workers=max_workers) as executor:
57
- # disable stdout from the pod_exec, then show the output in a for loop
58
- futures = [body(executor, pod, namespace, show_out) for pod in pods]
59
- if len(futures) == 0:
60
- return cast(list[T], [])
61
-
62
- rs = [future.result() for future in as_completed(futures)]
63
- if post:
64
- rs = [post(r, show_out=show_out) for r in rs]
65
-
66
- return rs
67
- finally:
68
- if KubeContext.show_parallelism():
69
- log2(f"Parallel {action} elapsed time: {elapsed_time(start_time)} with {max_workers} workers")
70
- else:
71
- results: list[T] = []
72
-
73
- samples = Config().action_node_samples(action, sys.maxsize)
74
- l = min(len(pods), samples)
75
- adj = 'all'
76
- if l < len(pods):
77
- adj = f'{l} sample'
78
- if show_out:
79
- log2(f'Executing on {adj} nodes from statefulset...')
80
- for pod_name in pods:
81
- try:
82
- result = body(None, pod_name, namespace, show_out)
83
- if post:
84
- result = post(result, show_out=show_out)
85
- results.append(result)
86
- if result:
87
- l -= 1
88
- if not l:
89
- break
90
- except Exception as e:
91
- log2(e)
92
-
93
- return results
94
-
95
- def exec(pod_name: str, container: str, namespace: str, command: str, show_out = True, throw_err = False, interaction: Callable[[any, list[str]], any] = None):
96
- if _TEST_POD_EXEC_OUTS:
97
- return _TEST_POD_EXEC_OUTS
98
-
99
- show_out = KubeContext.show_out(show_out)
100
-
101
- api = client.CoreV1Api()
102
-
103
- exec_command = ["/bin/sh", "-c", command]
104
- k_command = f'kubectl exec {pod_name} -c {container} -n {namespace} -- {command}'
105
- if show_out:
106
- print(k_command)
107
-
108
- resp = stream(
109
- api.connect_get_namespaced_pod_exec,
110
- pod_name,
111
- namespace,
112
- command=exec_command,
113
- container=container,
114
- stderr=True,
115
- stdin=True,
116
- stdout=True,
117
- tty=True,
118
- _preload_content=False,
119
- )
120
-
121
- stdout = []
122
- stderr = []
123
- error_output = None
124
- try:
125
- while resp.is_open():
126
- resp.update(timeout=1)
127
- if resp.peek_stdout():
128
- frag = resp.read_stdout()
129
- stdout.append(frag)
130
- if show_out: print(frag, end="")
131
-
132
- if interaction:
133
- interaction(resp, stdout)
134
- if resp.peek_stderr():
135
- frag = resp.read_stderr()
136
- stderr.append(frag)
137
- if show_out: print(frag, end="")
138
-
139
- try:
140
- # get the exit code from server
141
- error_output = resp.read_channel(ERROR_CHANNEL)
142
- except Exception:
143
- pass
144
- except Exception as e:
145
- if throw_err:
146
- raise e
147
- else:
148
- log2(e)
149
- finally:
150
- resp.close()
151
-
152
- return PodExecResult("".join(stdout), "".join(stderr), k_command, error_output)
153
-
154
- def get_container(namespace: str, pod_name: str, container_name: str):
155
- pod = Pods.get(namespace, pod_name)
156
- if not pod:
157
- return None
158
-
159
- for container in pod.spec.containers:
160
- if container_name == container.name:
161
- return container
162
-
163
- return None
164
-
165
- def get(namespace: str, pod_name: str):
166
- v1 = client.CoreV1Api()
167
- return v1.read_namespaced_pod(name=pod_name, namespace=namespace)
168
-
169
14
  def create_deployment_spec(name: str, image: str, image_pull_secret: str,
170
15
  envs: list, container_security_context: client.V1SecurityContext,
171
16
  volume_name: str, pvc_name:str, mount_path:str,
@@ -202,18 +47,4 @@ class Deployments:
202
47
  name=deployment_name,
203
48
  labels=labels
204
49
  ))
205
- )
206
-
207
- def wait_for_running(namespace: str, pod_name: str, msg: str=None):
208
- msged = False
209
-
210
- while Pods.get(namespace, pod_name).status.phase != 'Running':
211
- if not msged:
212
- if not msg:
213
- msg = f'Waiting for the {pod_name} pod to start up...'
214
- log2(msg)
215
- msged = True
216
- time.sleep(5)
217
-
218
- def completed(namespace: str, pod_name: str):
219
- return Pods.get(namespace, pod_name).status.phase in ['Succeeded', 'Failed']
50
+ )
adam/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- __version__ = "1.98.140" #: the working version
4
+ __version__ = "2.0.1" #: the working version
5
5
  __release__ = "1.0.0" #: the release version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kaqing
3
- Version: 1.98.140
3
+ Version: 2.0.1
4
4
  Summary: UNKNOWN
5
5
  Home-page: UNKNOWN
6
6
  License: UNKNOWN
@@ -14,7 +14,7 @@ adam/repl_commands.py,sha256=ionPWjPhzrzm59zbhO1WsGGcLVba3bnPl6uPjvQ4C34,4093
14
14
  adam/repl_session.py,sha256=uIogcvWBh7wd8QQ-p_JgLsyJ8YJgINw5vOd6JIsd7Vo,472
15
15
  adam/repl_state.py,sha256=QarrUAwYWOz3YTemtaf2opbHLa5a3LEsyuonNwhvOhk,7131
16
16
  adam/utils.py,sha256=j7p7iruLuV11swa0z9ZLBgoJHu_nkTSVKtQe0q71gmk,7025
17
- adam/version.py,sha256=aHmraJ9rwWAccgp_8uuEZLVAOkQ32VkuKXEpe6zSLEA,141
17
+ adam/version.py,sha256=LGSXrWr8-Nw59OeemDBaeRL_DEXmvkmNpfaRTFS_h10,138
18
18
  adam/checks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  adam/checks/check.py,sha256=Qopr3huYcMu2bzQgb99dEUYjFzkjKHRI76S6KA9b9Rk,702
20
20
  adam/checks/check_context.py,sha256=FEHkQ32jY1EDopQ2uYWqy9v7aEEX1orLpJWhopwAlh4,402
@@ -87,7 +87,7 @@ adam/commands/deploy/deploy_pod.py,sha256=IaDmrxpYw_YqkK599Vq4N7_4tINq5ihBlccVPE
87
87
  adam/commands/deploy/deploy_utils.py,sha256=-YB-XUwr8zVsf9HKYWx_TP-dB2WgOpEmUGyYNcoie0U,1046
88
88
  adam/commands/deploy/undeploy.py,sha256=CNgbB00TR1YRgX0xGgdGAT8YNPlcLssMsRX-pSby-Ao,1842
89
89
  adam/commands/deploy/undeploy_frontend.py,sha256=mbHlWb5UHUVpR1trfflCS_TDip7eAqxqoZ47RzRZcno,1257
90
- adam/commands/deploy/undeploy_pod.py,sha256=Notj7_MNU-sHxulJPnWKi1QUDUE8cWArZZEko8hKw3A,1901
90
+ adam/commands/deploy/undeploy_pod.py,sha256=n3AQ9EQ1TUPTzUVwWeyRLiK4dlnF_Zpq3nPEzrjSwjM,1962
91
91
  adam/commands/medusa/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
92
92
  adam/commands/medusa/medusa.py,sha256=Y_yyOZRb6u45wfTVBRp3kuklyYDTSlaAJQdAiymP_8M,2185
93
93
  adam/commands/medusa/medusa_backup.py,sha256=j4DTVWFT-4rzs4gG_pBvjE-JuPsVCJIsnyQjIzJ4EbA,1801
@@ -137,7 +137,7 @@ adam/k8s_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
137
137
  adam/k8s_utils/cassandra_clusters.py,sha256=9gUn31SsyW32asSFM8cKdkDSw5LYqPY2Iv0r4fDg_fU,2017
138
138
  adam/k8s_utils/cassandra_nodes.py,sha256=jQlaxIQKnavvsXH7lMM8WPriusp7KO698UygytIA8Xw,1134
139
139
  adam/k8s_utils/custom_resources.py,sha256=cIeaZRQET2DelTGU2f5QsMckh7TddPpWZDFeNK3txeQ,7647
140
- adam/k8s_utils/deployment.py,sha256=ai5DwdU0y6s6i0jmOKnfydbXSfZZCkG3f-XTf7P7-64,8504
140
+ adam/k8s_utils/deployment.py,sha256=Jw1To66E-DGY8dPbphWYakevNndKvv5nXtSEx23aqp0,2505
141
141
  adam/k8s_utils/ingresses.py,sha256=ul3Z6fDGc_Cxcn-ExP0vXhZatoShCUZFtpwtCY4Qx7o,3460
142
142
  adam/k8s_utils/jobs.py,sha256=P7j3JiZ33TRnkjkPLLrGlypAPxK1BZQHvVpF8s7eHA8,2604
143
143
  adam/k8s_utils/kube_context.py,sha256=nocEyVNjXWG-N-GNnEYHDvnot7H5LQUFmpZIwIyE7As,3310
@@ -157,8 +157,8 @@ adam/sso/idp.py,sha256=fvcwUw_URTgsO6ySaqTIw0zQT2qRO1IPSGhf6rPtybo,5804
157
157
  adam/sso/idp_login.py,sha256=QAtCUeDTVWliJy40RK_oac8Vgybr13xH8wzeBoxPaa8,1754
158
158
  adam/sso/idp_session.py,sha256=9BUHNRf70u4rVKrVY1HKPOEmOviXvkjam8WJxmXSKIM,1735
159
159
  adam/sso/sso_config.py,sha256=5N8WZgIJQBtHUy585XLRWKjpU87_v6QluyNK9E27D5s,2459
160
- kaqing-1.98.140.dist-info/METADATA,sha256=6GDFpkMOLNGQdRq63lPYleF-ifTzXW_GVOO9d4tBywI,134
161
- kaqing-1.98.140.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
162
- kaqing-1.98.140.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
163
- kaqing-1.98.140.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
164
- kaqing-1.98.140.dist-info/RECORD,,
160
+ kaqing-2.0.1.dist-info/METADATA,sha256=xfAMlT42lHrPoIH8DRfW0iXkfwfg_vjygQ2maAOVW8A,131
161
+ kaqing-2.0.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
162
+ kaqing-2.0.1.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
163
+ kaqing-2.0.1.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
164
+ kaqing-2.0.1.dist-info/RECORD,,