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 name size when the name is too long #122

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Truncate name size when the name is too long #122

merged 3 commits into from
Jul 24, 2024

Conversation

fhielpos
Copy link
Member

Description

This PR addresses an issue where if the name of a Deployment was too long, Kubernetes would truncate it in order to be able to add Pod identifiers to it.

@fhielpos fhielpos requested a review from a team as a code owner July 19, 2024 20:21
@fhielpos fhielpos self-assigned this Jul 19, 2024
Copy link
Contributor

@stone-z stone-z left a comment

Choose a reason for hiding this comment

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

This seems correct but is great unit test territory 😉

@fhielpos
Copy link
Member Author

I created a PolicyException with a super long name:

spec:
  policies:
  - disallow-capabilities-strict
  - disallow-privilege-escalation
  - require-run-as-nonroot
  - restrict-seccomp-strict
  targets:
  - kind: Deployment
    names:
    - this-is-a-really-long-deployment-name-that-i-hope-is-longer-than-63-chars
    namespaces:
    - test

The output of the Kyverno PolicyException is as expected:

    match:
      any:
      - resources:
          kinds:
          - Deployment
          - ReplicaSet
          - Pod
          names:
          - this-is-a-really-long-deployment-name-that-i-hope-is-longe*
          namespaces:
          - test

Incredibly enough, Kubernetes let me create the deployment as is:

Warning: metadata.name: this is used in Pod names and hostnames, which can result in surprising behavior; a DNS label is recommended: [must be no more than 63 characters]
deployment.apps/this-is-a-really-long-deployment-name-that-i-hope-is-longer-than-63-chars created

And the Pods followed the 59 char limit:

NAME                                                              READY   STATUS    RESTARTS   AGE
this-is-a-really-long-deployment-name-that-i-hope-is-longexw8j6   1/1     Running   0          3m57s
                                                         ^
                                                         | - 59 chars

@fhielpos
Copy link
Member Author

Will merge this one for now. It works as expected, probably could be improved in the future and split Deployment and Pods, but this at least will fix the issues we are seeing now.

@fhielpos fhielpos merged commit 43f639e into main Jul 24, 2024
7 checks passed
@fhielpos fhielpos deleted the fix-char-limit branch July 24, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants