Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate annotations when generating kubernetes yaml files #14023

Merged
merged 1 commit into from
Apr 27, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Apr 26, 2022

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: #13901

Fixes: #13962

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 26, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 26, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Apr 26, 2022

@umohnani8 PTAL

@rhatdan
Copy link
Member Author

rhatdan commented Apr 26, 2022

@nivekuil PTAL

@mheon
Copy link
Member

mheon commented Apr 26, 2022

I'd just as soon error instead of truncate, but I don't mind enough to not merge. LGTM

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and tests LGTM but there are typos in user-facing messages and in comments.

kubeOptions.Annotations[splitN[0]] = splitN[1]
annotation := splitN[1]
if len(annotation) > define.MaxKubeAnnotation {
return errors.Errorf("annotation exheeds maximum size, %d, of kubernetes annotation: %s", define.MaxKubeAnnotation, annotation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, should be exceeds with a 'c'

@@ -135,6 +135,8 @@ const (
// creating a checkpoint image to specify the name of host distribution on
// which the checkpoint was created.
CheckpointAnnotationDistributionName = "io.podman.annotations.checkpoint.distribution.name"
// MaxKubeAnnotation is the max length of Annotions allowed by Kubernetes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, should be Annotations


for name, val := range podYAML.Annotations {
if len(val) > define.MaxKubeAnnotation {
return nil, errors.Errorf("invalid annotation %q=%q value length exheeds Kubernetetes max %d", name, val, define.MaxKubeAnnotation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, exceeds

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 exheeds maximum size, 63, of kubernetes annotation:" "Expected to fail with Length greater then 63"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, exceeds.

Also, should be "greater than", not then

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 then 63"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

greater than

@@ -288,6 +289,16 @@ func newServicePortState() servicePortState {
}
}

func TruncateKubeAnnotation(str string) string {
str = strings.TrimSpace(str)
if utf8.RuneCountInString(str) < define.MaxKubeAnnotation {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, one more. The only spec I can find (I didn't look too hard) mentions 63 characters but doesn't actually indicate if we're talking new-style Unicode or old-style ASCII C chars. Does anyone know how to figure this one out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK, but I"m interested in seeing the answer....

Copy link
Member

@Luap99 Luap99 Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also inconsistent since in cmd/podman/play/kube.go the byte len is checked and not utf8 len.

@TomSweeneyRedHat
Copy link
Member

LGTM
once @edsantiago's comments are addressed.

@umohnani8
Copy link
Member

Changes LGTM once comments addressed

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: containers#13901

Fixes: containers#13962

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@rhatdan rhatdan added the lgtm Indicates that a PR is ready to be merged. label Apr 27, 2022
@openshift-merge-robot openshift-merge-robot merged commit bbe419e into containers:main Apr 27, 2022
@Luap99
Copy link
Member

Luap99 commented Apr 27, 2022

@rhatdan Why did you merge this? #14023 (comment) is not resolved!

It is inconsistent, on the one part you check for 63 bytes and on the other you check for 63 utf8 characters

@rhatdan
Copy link
Member Author

rhatdan commented Apr 27, 2022

I merged with two LGTM and fixed comments. We can open other PRs on the inconsistency.

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

label length vs kubernetes
7 participants