Skip to content

Commit 326a88a

Browse files
authored
xDS interop: Handle the edge case when rand deployment_id is all nums (grpc#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.
1 parent bc5db53 commit 326a88a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tools/run_tests/xds_k8s_test_driver/framework/test_app/runners/k8s/k8s_base_runner.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,28 @@ def _create_service_account(self, template,
225225
return resource
226226

227227
def _create_deployment(self, template, **kwargs) -> k8s.V1Deployment:
228+
# Not making deployment_name an explicit kwarg to be consistent with
229+
# the rest of the _create_* methods, which pass kwargs as-is
230+
# to _create_from_template(), so that the kwargs dict is unpacked into
231+
# template variables and their values.
232+
if 'deployment_name' not in kwargs:
233+
raise TypeError('Missing required keyword-only argument: '
234+
'deployment_name')
235+
228236
# Automatically apply random deployment_id to use in the matchLabels
229237
# to prevent selecting pods in the same namespace belonging to
230238
# a different deployment.
231239
if 'deployment_id' not in kwargs:
232-
kwargs['deployment_id'] = framework.helpers.rand.rand_string(
233-
lowercase=True)
240+
rand_id: str = framework.helpers.rand.rand_string(lowercase=True)
241+
# Fun edge case: when rand_string() happen to generate numbers only,
242+
# yaml interprets deployment_id label value as an integer,
243+
# but k8s expects label values to be strings. Lol. K8s responds
244+
# with a barely readable 400 Bad Request error: 'ReadString: expects
245+
# \" or n, but found 9, error found in #10 byte of ...|ent_id'.
246+
# Prepending deployment name forces deployment_id into a string,
247+
# as well as it's just a better description.
248+
kwargs['deployment_id'] = f'{kwargs["deployment_name"]}-{rand_id}'
249+
234250
deployment = self._create_from_template(template, **kwargs)
235251
if not isinstance(deployment, k8s.V1Deployment):
236252
raise _RunnerError('Expected V1Deployment to be created '

0 commit comments

Comments
 (0)