Fix CNF update check in V2 API

This patch fixes the following issues with the CNF update check
in V2 API.
* If there are Failed Pods when executing CNF Heal, the update
  check will timeout even if the Pods have started normally.
  This patch fixes "list_namespaced_pods" so that it can specify
  only "Running" state in addition to all Pods. It also fixes the
  "is_update" for Deployment, DaemonSet, and ReplicaSet.
* When executing Heal operation on a StatefulSet Pod,
  the Heal operation may become COMPLETED before the Pods is
  recreated, so this patch fixes the "is_update" for StatefulSet.

Closes-Bug: #2091854
Change-Id: I64eeb2810cb3e1c7daf22b7222c1e8a87efc7e43
This commit is contained in:
Ken Fujimoto 2024-11-27 08:48:15 +00:00
parent 285b1959bf
commit 06b61b6f86
4 changed files with 18 additions and 12 deletions

View File

@ -60,7 +60,7 @@ class KubernetesCommon(object):
# check running Pod
all_pods = kubernetes_utils.list_namespaced_pods(
k8s_api_client, namespace)
k8s_api_client, namespace, isall=True)
current_pods_name = [pod.metadata.name for pod in all_pods]
old_pods_names = set()

View File

@ -395,8 +395,7 @@ class DaemonSet(NamespacedResource):
replicas = daemonset_info.status.desired_number_scheduled
for pod_info in pods_info:
if (pod_info.status.phase != 'Running' or
pod_info.metadata.name in old_pods_names):
if pod_info.metadata.name in old_pods_names:
return False
return len(pods_info) == replicas
@ -416,8 +415,7 @@ class Deployment(NamespacedResource):
replicas = deployment_info.spec.replicas
for pod_info in pods_info:
if (pod_info.status.phase != 'Running' or
pod_info.metadata.name in old_pods_names):
if pod_info.metadata.name in old_pods_names:
return False
return len(pods_info) == replicas
@ -435,10 +433,8 @@ class ReplicaSet(NamespacedResource):
def is_update(self, pods_info, old_pods_names):
replicaset_info = self.read()
replicas = replicaset_info.spec.replicas
for pod_info in pods_info:
if (pod_info.status.phase != 'Running' or
pod_info.metadata.name in old_pods_names):
if pod_info.metadata.name in old_pods_names:
return False
return len(pods_info) == replicas
@ -522,7 +518,12 @@ class StatefulSet(NamespacedResource):
replicas = statefulset_info.spec.replicas
for pod_info in pods_info:
if pod_info.status.phase != 'Running':
# NOTE: Pods created with StatefulSet will have the same name
# when recreated. As the Pod is still in a "Running" state
# immediately after deletion, StatefulSet uses the
# "metadata.deletion_timestamp" to determine whether the update
# has been completed.
if pod_info.metadata.deletion_timestamp is not None:
return False
return len(pods_info) == replicas

View File

@ -116,9 +116,14 @@ def get_k8s_reses_from_json_files(target_k8s_files, vnfd, k8s_api_client,
return k8s_reses, namespace
def list_namespaced_pods(k8s_api_client, namespace):
def list_namespaced_pods(k8s_api_client, namespace, isall=False):
k8s_client = client.CoreV1Api(api_client=k8s_api_client)
return k8s_client.list_namespaced_pod(namespace=namespace).items
all_pods = k8s_client.list_namespaced_pod(namespace=namespace).items
if isall:
return all_pods
# return 'Running' pods only, if isall == False
return [pod for pod in all_pods if pod.status.phase == 'Running']
class AuthContextManager:

View File

@ -302,7 +302,7 @@ class ContainerUpdateMgmtDriver(kubernetes.Kubernetes):
k8s_config_obj.replace()
pods = kubernetes_utils.list_namespaced_pods(
k8s_api_client, namespace=namespace)
k8s_api_client, namespace=namespace, isall=True)
old_pods_names = set()
for k8s_pod_obj in k8s_pod_objs:
# Call the replace API