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

Resouce name with whitespaces #38175

Closed
mcruzdev opened this issue Jan 13, 2024 · 3 comments · Fixed by #38192
Closed

Resouce name with whitespaces #38175

mcruzdev opened this issue Jan 13, 2024 · 3 comments · Fixed by #38192

Comments

@mcruzdev
Copy link
Contributor

mcruzdev commented Jan 13, 2024

Describe the bug

When we are using kubernets extensions, when the quarkus.application.name has the value "k6-with-quarkus " (with whtespace) name the generated Kubernetes resources are wrong:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    app.quarkus.io/commit-id: ece8c3e3b8ad7664b7cdec32a91d37f28383792f
    app.quarkus.io/vcs-uri: git@github.com:mcruzdev/k6-with-quarkus.git
    app.quarkus.io/build-timestamp: 2024-01-13 - 16:16:30 +0000
  labels:
    app.kubernetes.io/name: 'k6-with-quarkus '
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
    app.kubernetes.io/managed-by: quarkus
  name: 'k6-with-quarkus ' # <------ whitespace

When you apply those resources into Kubernetes cluster, you get:

Error from server (Invalid): error when creating "target/kubernetes/kind.yml": Service "k6-with-quarkus " is invalid: [metadata.name: Invalid value: "k6-with-quarkus ": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name',  or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?'), metadata.labels: Invalid value: "k6-with-quarkus ": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?'), spec.selector: Invalid value: "k6-with-quarkus ": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')]
Error from server (Invalid): error when creating "target/kubernetes/kind.yml": Deployment.apps "k6-with-quarkus " is invalid: [metadata.name: Invalid value: "k6-with-quarkus ": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'), metadata.labels: Invalid value: "k6-with-quarkus ": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?'), spec.selector.matchLabels: Invalid value: "k6-with-quarkus ": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?'), spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app.kubernetes.io/name":"k6-with-quarkus ", "app.kubernetes.io/version":"1.0.0-SNAPSHOT"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: invalid label selector]

Expected behavior

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    app.quarkus.io/commit-id: ece8c3e3b8ad7664b7cdec32a91d37f28383792f
    app.quarkus.io/vcs-uri: git@github.com:mcruzdev/k6-with-quarkus.git
    app.quarkus.io/build-timestamp: 2024-01-13 - 16:16:30 +0000
  labels:
    app.kubernetes.io/name: 'k6-with-quarkus '
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
    app.kubernetes.io/managed-by: quarkus
  name: 'k6-with-quarkus' # <------ EXPECTED: without whitespace

Actual behavior

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    app.quarkus.io/commit-id: ece8c3e3b8ad7664b7cdec32a91d37f28383792f
    app.quarkus.io/vcs-uri: git@github.com:mcruzdev/k6-with-quarkus.git
    app.quarkus.io/build-timestamp: 2024-01-13 - 16:16:30 +0000
  labels:
    app.kubernetes.io/name: 'k6-with-quarkus '
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
    app.kubernetes.io/managed-by: quarkus
  name: 'k6-with-quarkus ' # <------ whitespace

How to Reproduce?

Install the following extensions:

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-kubernetes</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-container-image-jib</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-kind</artifactId>
    </dependency>

And configure your quarkus.application.name with whitespace.

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

  • We can solve this one handling the application name before creating KubernetesResourceMetadataBuildItem:

  • We can change the following code to remove this whitespace, because it is used for all Kubernetes related processors, but is necessary to pay attention to another consumers:

public static String getResourceName(PlatformConfiguration platformConfiguration,

image

@quarkus-bot
Copy link

quarkus-bot bot commented Jan 13, 2024

/cc @geoand (jib,kubernetes), @iocanel (kubernetes)

@mcruzdev
Copy link
Contributor Author

Hi @geoand and @iocanel, If it makes sense, I can open a pull request!

@geoand
Copy link
Contributor

geoand commented Jan 15, 2024

I personally think it makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants