xDS interop: Handle the edge case when rand deployment_id is all nums (#30901)

Fun edge case: when `rand_string()` happen to generate numbers only,
yaml interprets `deployment_id` label value as an integer,
but k8s expects label values to be strings.

K8s responds with a barely readable 400 Bad Request error:
`ReadString: expects \" or n, but found 9, error found in #10 byte of ...|ent_id`.

Prepending deployment name forces deployment_id into a string,
as well as it's just a better description.
pull/30904/head
Sergii Tkachenko 2 years ago committed by GitHub
parent bc5db5395a
commit 326a88a9a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      tools/run_tests/xds_k8s_test_driver/framework/test_app/runners/k8s/k8s_base_runner.py

@ -225,12 +225,28 @@ class KubernetesBaseRunner(base_runner.BaseRunner):
return resource
def _create_deployment(self, template, **kwargs) -> k8s.V1Deployment:
# Not making deployment_name an explicit kwarg to be consistent with
# the rest of the _create_* methods, which pass kwargs as-is
# to _create_from_template(), so that the kwargs dict is unpacked into
# template variables and their values.
if 'deployment_name' not in kwargs:
raise TypeError('Missing required keyword-only argument: '
'deployment_name')
# 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)
rand_id: str = framework.helpers.rand.rand_string(lowercase=True)
# Fun edge case: when rand_string() happen to generate numbers only,
# yaml interprets deployment_id label value as an integer,
# but k8s expects label values to be strings. Lol. K8s responds
# with a barely readable 400 Bad Request error: 'ReadString: expects
# \" or n, but found 9, error found in #10 byte of ...|ent_id'.
# Prepending deployment name forces deployment_id into a string,
# as well as it's just a better description.
kwargs['deployment_id'] = f'{kwargs["deployment_name"]}-{rand_id}'
deployment = self._create_from_template(template, **kwargs)
if not isinstance(deployment, k8s.V1Deployment):
raise _RunnerError('Expected V1Deployment to be created '

Loading…
Cancel
Save