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

JavaExecGenerator does not honor %t setting #3161

Closed
ecausarano opened this issue Jun 12, 2024 · 4 comments · Fixed by #3163
Closed

JavaExecGenerator does not honor %t setting #3161

ecausarano opened this issue Jun 12, 2024 · 4 comments · Fixed by #3163
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ecausarano
Copy link
Contributor

Describe the bug

When setting the image name to %t in order to create a different tag when pushing to the container registy, the JavaExecGenerator will add its own latest tag regardless.

This breaks tagging to immutable repositories, where latest tags make no sense and will cause the push to fail.

Eclipse JKube version

1.16.2

Component

Kubernetes Maven Plugin

Apache Maven version

None

Gradle version

None

Steps to reproduce

Choose %t in the image name configuration
Configure the target repository to be immutable (eg. AWS ECR)
Try to push

Expected behavior

The plugin should only attempt to add the timestamped tag, no latest tags added.

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.25.3

Environment

Amazon

Eclipse JKube Logs

No response

Sample Reproducer Project

No response

Additional context

No response

@ecausarano ecausarano added the bug Something isn't working label Jun 12, 2024
@manusa manusa moved this to Planned in Eclipse JKube Jun 12, 2024
@rohanKanojia
Copy link
Member

@ecausarano : Is it possible to share a reproducer project? I tried reproducing this but could not reproduce the issue. Here are the steps I followed:

  1. Clone https://github.com/rohankanojia/podsetoperatorinjava
  2. Change jkube.generator.name property in pom.xml to quay.io/${image.user}/${project.artifactId}:%t
  3. Run mvn k8s:build

I was able to see image being tagged with timestamp:

[INFO] k8s: [quay.io/rohankanojia/podset-operator-in-java:snapshot-240613-102153-0649] "java-exec": Created docker-build.tar in 65 milliseconds
[INFO] k8s: [quay.io/rohankanojia/podset-operator-in-java:snapshot-240613-102153-0649] "java-exec": Built image sha256:4d492
[INFO] k8s: [quay.io/rohankanojia/podset-operator-in-java:snapshot-240613-102153-0649] "java-exec": Tag with latest

@rohanKanojia
Copy link
Member

okay, I think I now understand the problem now. Image is correctly tagged with timestamp, however JKube is adding an additional <tag> in Build configuration. This results in an extra image getting created:

REPOSITORY                                     TAG                           IMAGE ID       CREATED              SIZE
quay.io/rohankanojia/podset-operator-in-java   latest                        dd581f0fe6ef   About a minute ago   507MB
quay.io/rohankanojia/podset-operator-in-java   snapshot-240613-102851-0116   dd581f0fe6ef   About a minute ago   507MB

This latest tag is being added for projects that have versions containing SNAPSHOT

protected void addLatestTagIfSnapshot(BuildConfiguration.BuildConfigurationBuilder buildBuilder) {
if (getProject().getVersion().endsWith("-SNAPSHOT")) {
buildBuilder.tags(Collections.singletonList("latest"));
}

Adding a check here to not add latest tag when image name contains %t fixes the issue

-        if (getProject().getVersion().endsWith("-SNAPSHOT")) {
+        if (getProject().getVersion().endsWith("-SNAPSHOT") && !getImageName().contains("%t")) {

@ecausarano
Copy link
Contributor Author

That would fix it, but the tag name is already processed in another part of the codebase. (ImageNameFormatter.java

I'm no Docker guru, is there a reason for explicitly adding the latest tag? Wouldn't the Registry automatically add it?

@rohanKanojia
Copy link
Member

I'm checking history of this change and it seems to have been introduced in fabric8io/fabric8-maven-plugin#186 . It doesn't provide much insight on why this was added.

@rohanKanojia rohanKanojia moved this from Planned to Review in Eclipse JKube Jun 13, 2024
@manusa manusa added this to the 1.17.0 milestone Jun 21, 2024 — with automated-tasks
@github-project-automation github-project-automation bot moved this from Review to Done in Eclipse JKube Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants