From 7712f938057f032e024a05b191a59e1fb46d682c Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Wed, 17 Aug 2022 14:06:21 -0700 Subject: [PATCH] xDS interop: Generate deployment_id match label (#30596) This fixes an issue with KubernetesNamespace.list_deployment_pods() as well as the deployment itself would select incorrect pods when multiple deployments share the same namespace. --- .../framework/test_app/runners/k8s/k8s_base_runner.py | 7 +++++++ .../kubernetes-manifests/client-secure.deployment.yaml | 3 +++ .../kubernetes-manifests/client.deployment.yaml | 3 +++ .../kubernetes-manifests/server-secure.deployment.yaml | 3 +++ .../kubernetes-manifests/server.deployment.yaml | 3 +++ 5 files changed, 19 insertions(+) diff --git a/tools/run_tests/xds_k8s_test_driver/framework/test_app/runners/k8s/k8s_base_runner.py b/tools/run_tests/xds_k8s_test_driver/framework/test_app/runners/k8s/k8s_base_runner.py index ec45b4b32c0..5006d681bc0 100644 --- a/tools/run_tests/xds_k8s_test_driver/framework/test_app/runners/k8s/k8s_base_runner.py +++ b/tools/run_tests/xds_k8s_test_driver/framework/test_app/runners/k8s/k8s_base_runner.py @@ -25,6 +25,7 @@ import yaml import framework.helpers.datetime import framework.helpers.highlighter +import framework.helpers.rand from framework.infrastructure import gcp from framework.infrastructure import k8s from framework.test_app.runners import base_runner @@ -198,6 +199,12 @@ class KubernetesBaseRunner(base_runner.BaseRunner): return resource def _create_deployment(self, template, **kwargs) -> k8s.V1Deployment: + # Automatically apply random deployment_id to use in the matchLabels + # to prevent selecting pods in the same namespace belonging to + # a different deployment. + if 'deployment_id' not in kwargs: + kwargs['deployment_id'] = framework.helpers.rand.rand_string( + lowercase=True) deployment = self._create_from_template(template, **kwargs) if not isinstance(deployment, k8s.V1Deployment): raise _RunnerError('Expected V1Deployment to be created ' diff --git a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client-secure.deployment.yaml b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client-secure.deployment.yaml index 3263360bdc4..b2afd0e9d1f 100644 --- a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client-secure.deployment.yaml +++ b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client-secure.deployment.yaml @@ -6,16 +6,19 @@ metadata: namespace: ${namespace_name} labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test spec: replicas: 1 selector: matchLabels: app: ${deployment_name} + deployment_id: ${deployment_id} template: metadata: labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test annotations: security.cloud.google.com/use-workload-certificates: "" diff --git a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client.deployment.yaml b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client.deployment.yaml index 5820803990a..771365eeeb0 100644 --- a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client.deployment.yaml +++ b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/client.deployment.yaml @@ -6,16 +6,19 @@ metadata: namespace: ${namespace_name} labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test spec: replicas: 1 selector: matchLabels: app: ${deployment_name} + deployment_id: ${deployment_id} template: metadata: labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test spec: % if service_account_name: diff --git a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server-secure.deployment.yaml b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server-secure.deployment.yaml index 5a3803bf63e..fd3c7ec2f8f 100644 --- a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server-secure.deployment.yaml +++ b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server-secure.deployment.yaml @@ -6,18 +6,21 @@ metadata: namespace: ${namespace_name} labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test spec: replicas: ${replica_count} selector: matchLabels: app: ${deployment_name} + deployment_id: ${deployment_id} template: metadata: annotations: security.cloud.google.com/use-workload-certificates: "" labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test spec: serviceAccountName: ${service_account_name} diff --git a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server.deployment.yaml b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server.deployment.yaml index 3d1206d8c65..7898592bddd 100644 --- a/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server.deployment.yaml +++ b/tools/run_tests/xds_k8s_test_driver/kubernetes-manifests/server.deployment.yaml @@ -6,16 +6,19 @@ metadata: namespace: ${namespace_name} labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test spec: replicas: ${replica_count} selector: matchLabels: app: ${deployment_name} + deployment_id: ${deployment_id} template: metadata: labels: app: ${deployment_name} + deployment_id: ${deployment_id} owner: xds-k8s-interop-test spec: % if service_account_name: