|
30 | 30 | AffectedPod,
|
31 | 31 | ApiRequestException,
|
32 | 32 | Container,
|
| 33 | + NodeResources, |
33 | 34 | Pod,
|
34 | 35 | PodsMonitorThread,
|
35 | 36 | PodsStatus,
|
36 | 37 | ServiceHijacking,
|
37 | 38 | Volume,
|
38 | 39 | VolumeMount,
|
39 |
| - NodeResources, |
40 | 40 | )
|
41 | 41 | from krkn_lib.models.krkn import HogConfig, HogType
|
42 | 42 | from krkn_lib.models.telemetry import ClusterEvent, NodeInfo, Taint
|
@@ -851,7 +851,9 @@ def get_all_services(self, namespace: str) -> list[str]:
|
851 | 851 |
|
852 | 852 | # Outputs a json blob with informataion about all pods in a given namespace
|
853 | 853 | def get_all_pod_info(
|
854 |
| - self, namespace: str = "default", label_selector: str = None |
| 854 | + self, |
| 855 | + namespace: str = "default", |
| 856 | + label_selector: str = None, |
855 | 857 | ) -> list[str]:
|
856 | 858 | """
|
857 | 859 | Get details of all pods in a namespace
|
@@ -1137,8 +1139,18 @@ def delete_pod(self, name: str, namespace: str = "default"):
|
1137 | 1139 | :param namespace: namespace (optional default `default`)
|
1138 | 1140 | """
|
1139 | 1141 | try:
|
| 1142 | + starting_creation_timestamp = self.cli.read_namespaced_pod( |
| 1143 | + name=name, namespace=namespace |
| 1144 | + ).metadata.creation_timestamp |
1140 | 1145 | self.cli.delete_namespaced_pod(name=name, namespace=namespace)
|
| 1146 | + |
1141 | 1147 | while self.cli.read_namespaced_pod(name=name, namespace=namespace):
|
| 1148 | + |
| 1149 | + ending_creation_timestamp = self.cli.read_namespaced_pod( |
| 1150 | + name=name, namespace=namespace |
| 1151 | + ).metadata.creation_timestamp |
| 1152 | + if starting_creation_timestamp != ending_creation_timestamp: |
| 1153 | + break |
1142 | 1154 | time.sleep(1)
|
1143 | 1155 | except ApiException as e:
|
1144 | 1156 | if e.status == 404:
|
@@ -1540,6 +1552,7 @@ def get_pod_info(self, name: str, namespace: str = "default") -> Pod:
|
1540 | 1552 | nodeName=response.spec.node_name,
|
1541 | 1553 | volumes=volume_list,
|
1542 | 1554 | status=response.status.phase,
|
| 1555 | + creation_timestamp=response.metadata.creation_timestamp, |
1543 | 1556 | )
|
1544 | 1557 | return pod_info
|
1545 | 1558 | else:
|
@@ -2699,12 +2712,14 @@ def select_pods_by_namespace_pattern_and_label(
|
2699 | 2712 | pods_and_namespaces = [
|
2700 | 2713 | pod for pod in pods_and_namespaces if namespace_re.match(pod[1])
|
2701 | 2714 | ]
|
| 2715 | + |
2702 | 2716 | # select only running pods
|
2703 | 2717 | pods_and_namespaces = [
|
2704 | 2718 | (pod[0], pod[1])
|
2705 | 2719 | for pod in pods_and_namespaces
|
2706 | 2720 | if not self.is_pod_terminating(pod[0], pod[1])
|
2707 | 2721 | ]
|
| 2722 | + |
2708 | 2723 | return pods_and_namespaces
|
2709 | 2724 |
|
2710 | 2725 | def monitor_pods_by_label(
|
@@ -2951,12 +2966,20 @@ def __monitor_pods_worker(
|
2951 | 2966 | # respawned with the same names
|
2952 | 2967 | if set(pods_and_namespaces) == set(current_pods_and_namespaces):
|
2953 | 2968 | for pod in current_pods_and_namespaces:
|
2954 |
| - if not self.is_pod_running(pod[0], pod[1]): |
| 2969 | + pod_info = self.get_pod_info(pod[0], pod[1]) |
| 2970 | + if pod_info is not None: |
| 2971 | + pod_creation_timestamp = ( |
| 2972 | + pod_info.creation_timestamp.timestamp() |
| 2973 | + ) |
| 2974 | + else: |
| 2975 | + continue |
| 2976 | + if ( |
| 2977 | + pod_info.status |
| 2978 | + and start_time < pod_creation_timestamp |
| 2979 | + ): |
| 2980 | + # in this case the pods to wait have been respawn |
| 2981 | + # with the same name |
2955 | 2982 | missing_pods.add(pod)
|
2956 |
| - if len(missing_pods) == 0: |
2957 |
| - continue |
2958 |
| - # in this case the pods to wait have been respawn |
2959 |
| - # with the same name |
2960 | 2983 | pods_to_wait.update(missing_pods)
|
2961 | 2984 |
|
2962 | 2985 | # pods have been killed but respawned with different names
|
@@ -2992,6 +3015,8 @@ def __monitor_pods_worker(
|
2992 | 3015 | with ThreadPoolExecutor() as executor:
|
2993 | 3016 | for pod_and_namespace in pods_to_wait:
|
2994 | 3017 | if pod_and_namespace not in pods_already_watching:
|
| 3018 | + |
| 3019 | + # need name of new pod |
2995 | 3020 | future = executor.submit(
|
2996 | 3021 | self.__wait_until_pod_is_ready_worker,
|
2997 | 3022 | pod_name=pod_and_namespace[0],
|
|
0 commit comments