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

Images are not tagged as latest when using Helm #1027

Closed
renedupont opened this issue Aug 24, 2023 · 2 comments · Fixed by #1043
Closed

Images are not tagged as latest when using Helm #1027

renedupont opened this issue Aug 24, 2023 · 2 comments · Fixed by #1043
Labels
bug Something isn't working

Comments

@renedupont
Copy link
Member

I provisioned a docker plain component and am using the Dockerfile and the Jenkins stage odsComponentStageBuildOpenShiftImage to just build the image. I deleted the DeploymentConfig in OCP because I really just want to build the image to have it in the registry. Additionally, I added a couple of kubernetes resources (a CronJob and a PVC yaml) into the repo and manage this via Helm (via stage odsComponentStageRolloutOpenShiftDeployment).

Since I added the Helm stuff my above image doesn't get tagged as latest anymore, which is unfortunate because I use this image in the CronJob. I looked into the ods code and saw that when using the tailorDeploymentStrategy it tags the image as latest here: ods-jenkins-shared-library/src/org/ods/component/TailorDeploymentStrategy.groovy at master · opendevstack/ods-jenkins-shared-library (github.com) while the same does not happen in the helmDeploymentStrategy at all.

Regarding this, I have the following questions:

  • I suppose that is a bug? Or is this on purpose?
  • Why does this tagging actually happen in the Deployment stage and not in the Build stage? In my case, if I hadn't the Helm part and would just build an image without deploying it, it would never get tagged latest because I wouldn't use the deployment stage in the Jenkinsfile at all. I think I'm missing something here.
  • Am I structuring this wrong, or lets say not as intended by ODS? If there is no solution to my problem I will probably just create an additional docker plain component in which I just build the docker image (so that the tailorDeploymentStrategy is used) and keep my current component just for the helm stuff. An issue will still be that the pipeline enforces me to have a deployment for my image even though I just want to build the image.

To circumvent the issue, I'm currently setting the imageTag myself:

odsComponentStageBuildOpenShiftImage(context, [imageTag: "0.1"])
odsComponentStageRolloutOpenShiftDeployment(context, [imageTag: "0.1"])

That works, but it is error prone. In case I update the Dockerfile but forget to raise these versions before pushing, it would overwrite the previous image in the registry. I would rather have it automatically tagged as latest.

@renedupont renedupont added the bug Something isn't working label Aug 24, 2023
@renedupont renedupont assigned renedupont and unassigned renedupont Aug 24, 2023
@serverhorror
Copy link
Contributor

TL;DR -- If it doesn't block you I would like to avoid setting latest. It's a frowned upon practice and was deliberately removed for Helm rollouts.

  • I suppose that is a bug? Or is this on purpose?

If I recall correctly this is on purpose. latest is quite frowned upon as it doesn't provide a stable reference.

I think the decision for the difference was based on:

  1. let's not break tailor while it is still in use (officially tailor doesn't support OCP4 anyway)
  2. let's "encourage" better practices. Not setting a tag will make it so the context.shortGitCommit is available (by default)

image

  • Why does this tagging actually happen in the Deployment stage and not in the Build stage? In my case, if I hadn't the Helm part and would just build an image without deploying it, it would never get tagged latest because I wouldn't use the deployment stage in the Jenkinsfile at all. I think I'm missing something here.

It does happen in the build stage. It tags with shortGitCommit and has done so for quite a while, this wasn't even touched when it comes to the Helm stuff.

The latest is a remnant of an old decision that we now have to live with. It was a bad idea in the first place:

  • Am I structuring this wrong, or lets say not as intended by ODS? If there is no solution to my problem I will probably just create an additional docker plain component in which I just build the docker image (so that the tailorDeploymentStrategy is used) and keep my current component just for the helm stuff. An issue will still be that the pipeline enforces me to have a deployment for my image even though I just want to build the image.

If you really only want to build and image, that is pretty unrelated to Helm at all. I'd drop everything that is related to tailor or Helm and just do something along those lines:

// guard build so we don't rebuild unless necessary
// use a stable, but predictable tag that won't give us trouble if we use the wrong `ImagePullPolicy` in our resource descriptions
odsComponentFindOpenShiftImageOrElse(context, [imageTag: context.shortGitCommit]) {
  odsComponentStageBuildOpenShiftImage(context, [context.shortGitCommit])
}
// don't do any odsComponentStageRolloutOpenShiftDeployment at all!

@renedupont
Copy link
Member Author

As discussed with @serverhorror, there is no technically need to change anything since latest is not set on purpose. I am using now the default behaviour where the image is tagged with the git short commit, and in the same pipeline run the helm value imageTag will be set to short commit which I then use to reference the image in my helm template like this:
{{ .Values.imageTag }}

Also, I won't close this ticket yet as it is supposed to serve as a reminder to @serverhorror to add some documentation about this behaviour.

serverhorror added a commit to serverhorror/ods-jenkins-shared-library that referenced this issue Oct 13, 2023
serverhorror added a commit to serverhorror/ods-jenkins-shared-library that referenced this issue Oct 13, 2023
fixes Images are not tagged as latest when using Helm opendevstack#1027
serverhorror added a commit to serverhorror/ods-jenkins-shared-library that referenced this issue Oct 13, 2023
fixes Images are not tagged as latest when using Helm opendevstack#1027
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.

2 participants