Merge "Fix CNF update check in V2 API"

This commit is contained in:
Zuul 2024-12-20 02:56:17 +00:00 committed by Gerrit Code Review
commit 364a723283
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