From 7259a6315c7f7d97665d928de6357fc3cbcae136 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 26 Apr 2022 15:53:36 -0400 Subject: Truncate annotations when generating kubernetes yaml files Kubernetes only allows 63 characters in an annotation. Make sure that we only add 63 or less charaters when generating kube. Warn if containers or pods have longer length and truncate. Discussion: https://github.com/containers/podman/discussions/13901 Fixes: https://github.com/containers/podman/issues/13962 Signed-off-by: Daniel J Walsh --- test/system/700-play.bats | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test') diff --git a/test/system/700-play.bats b/test/system/700-play.bats index 8af4cd25b..b0624cbf2 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -233,3 +233,48 @@ _EOF run_podman stop -a -t 0 run_podman pod rm -t 0 -f test_pod } + +@test "podman play --annotation > Max" { + TESTDIR=$PODMAN_TMPDIR/testdir + RANDOMSTRING=$(random_string 65) + mkdir -p $TESTDIR + echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml + run_podman 125 play kube --annotation "name=$RANDOMSTRING" $PODMAN_TMPDIR/test.yaml + assert "$output" =~ "annotation exceeds maximum size, 63, of kubernetes annotation:" "Expected to fail with Length greater than 63" +} + +@test "podman play Yaml with annotation > Max" { + RANDOMSTRING=$(random_string 65) + testBadYaml=" +apiVersion: v1 +kind: Pod +metadata: + annotations: + test: ${RANDOMSTRING} + labels: + app: test + name: test_pod +spec: + containers: + - command: + - id + env: + - name: PATH + value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + - name: TERM + value: xterm + - name: container + + value: podman + image: quay.io/libpod/userimage + name: test + resources: {} +status: {} +" + TESTDIR=$PODMAN_TMPDIR/testdir + mkdir -p $TESTDIR + echo "$testBadYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml + + run_podman 125 play kube - < $PODMAN_TMPDIR/test.yaml + assert "$output" =~ "invalid annotation \"test\"=\"$RANDOMSTRING\"" "Expected to fail with annotation length greater than 63" +} -- cgit v1.2.3-54-g00ecf