-
Notifications
You must be signed in to change notification settings - Fork 91
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
make deployment.image.tag and job.image.tag optional #234
Conversation
@d3adb5 validation successful` |
@slauger please update both readme and changelog! thanks for contribution |
@rasheedamir changelog and readme is updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably completely out of line since I'm not a repository maintainer, but I thought I'd leave a review anyway. Let me know your thoughts, everyone.
application/templates/cronjob.yaml
Outdated
{{- if $job.image.tag }} | ||
{{- if $job.image.digest }} | ||
image: "{{ $job.image.repository }}@{{ $job.image.digest }}" | ||
{{- else if $job.image.tag }} | ||
image: "{{ $job.image.repository }}:{{ $job.image.tag }}@{{ $job.image.digest }}" | ||
{{- else }} | ||
image: "{{ $job.image.repository }}:{{ $job.image.tag }}" | ||
{{- end }} | ||
{{- else if $job.image.digest }} | ||
image: "{{ $job.image.repository }}@{{ $job.image.digest }}" | ||
{{- else }} | ||
image: "{{ $job.image.repository }}" | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid repetition, here's a suggestion:
{{- $image := $job.image.repository }}
{{- with $job.image.tag }}{{ $image = print $image ":" . }}{{ end }}
{{- with $job.image.digest }}{{ $image = print $image "@" . }}{{ end }}
image: {{ $image }}
I do believe, however, that if an image repository isn't specified, we should have a templating error, for containers can't be without an image:
{{- $image := $job.image.repository }}
{{- if not $image }}{{ print "Undefined image at CronJob definition at: " $name | fail }}{{ end }}
{{- with $job.image.tag }}{{ $image = print $image ":" . }}{{ end }}
{{- with $job.image.digest }}{{ $image = print $image "@" . }}{{ end }}
image: {{ $image }}
If we go this route, there should be a unit test for it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be possible to remove the default for image.repository
via
{{ required "A valid value for .Values.repository.image is required!" .Values.image.repository }}
but since the default was already set to repository/image-name
i did not change this behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like generic default values like those could be refactored out to allow for these safeguards to be put in place. That's probably outside the scope of this pull request, however.
{{- if .Values.deployment.image.tag }} | ||
{{- if .Values.deployment.image.digest }} | ||
image: "{{ .Values.deployment.image.repository }}@{{ .Values.deployment.image.digest }}" | ||
{{- else if .Values.deployment.image.tag }} | ||
image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}@{{ .Values.deployment.image.digest }}" | ||
{{- else }} | ||
image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}" | ||
{{- end }} | ||
{{- else if .Values.deployment.image.digest }} | ||
image: "{{ .Values.deployment.image.repository }}@{{ .Values.deployment.image.digest }}" | ||
{{- else }} | ||
image: "{{ .Values.deployment.image.repository }}" | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other comment about lowering repetition on the CronJob template file.
application/templates/_helpers.tpl
Outdated
{{- if .Values.deployment.image.tag }} | ||
app.kubernetes.io/version: {{ include "application.version" . }} | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With an empty string as the default value for .Values.deployment.image.tag
, we could discard this if
statement, though we would end up with an empty value for a version label. How about leaving out this conditional and instead editing the application.version
template so that it:
- Tries to use the tag as it currently does, but failing that, it
- Tries to use the digest with a little bit of RegEx substitution magic, but if not provided either, it
- Simply says "latest", as is default behavior for container images?
How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the application version should not be mixed up with the image tag. The application version should always be a semantic version. Tags for containers does not not always have a semver. Currently i don't like the usage of the function.
But in general i think it would be a good idea to move the logic in a seperate function to reduce the code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The application version should always be a semantic version.
I'm not sure if I agree with this one. Helm does require chart versions to be semantic, but the versioning scheme for an application is an incredibly arbitrary choice, usually left to the core maintainers or company behind the project. Hence Helm will let appVersion
be just about anything in Chart.yaml
— in fact .Chart.AppVersion
is often used as the default value when an image tag isn't provided, but this is a generic chart and such a value can't be set during installation.
So that said, whatever logic is present in application.version
, now or in the future, this could be changed to a simple:
{{- if .Values.deployment.image.tag }} | |
app.kubernetes.io/version: {{ include "application.version" . }} | |
{{- end }} | |
{{- with include "application.version" . }} | |
app.kubernetes.io/version: {{ quote . }} | |
{{- end }} |
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, i see. But what if there is no tag defined? Maybe the tag is a good default for the label, but we could allow overriding the label - maybe with another Value, e.g. .Values.applicationVersion
?
Also there could be situations where the version of the application stays the same (e.g. the wordpress version) but the underlying base container receives an update (e.g. packages updates of the alpine/ubi container).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An appVersion
value sounds good to me. In the case of no such value and no tag being defined, however, we can just skip the label altogether as it makes no sense to set it, and hence the suggested with
being appropriate.
{{- end }} No newline at end of file | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace changes mess with blame information. Harmless as it is, I'd suggest removing this change from any commits that'll be merged.
So how shall we continue here? btw why do you maintain the |
@rasheedamir ah i see. On which slack workspace can i reach you? I'm already on the Kubernetes slack workspace for example. |
Please join here - https://slack.stakater.com/ and we can have discussions in #help-and-support channel Yeah i agree we should automate the CHANGELOG |
@slauger Do you mind if I push any commits to your branch? Also, there are conflicts now that other PRs have been merged. Let me know what you think of the changes I requested. |
Simplify the logic in determining the image string for containers in a CronJob or Deployment resource.
Add unit test to test assembly of the container image string when tag and digest are given or omitted.
Check whether the output of the 'application.version' partial template is empty instead of the image tag when deciding whether to add the Kubernetes recommended application version label. The partial template was adjusted to avoid crashes when applying the regexReplace function.
1518c6a
to
a6d0cbf
Compare
Stale review, plus became one of the PR authors.
I rebased @slauger's branch on master, added tests and did some minor refactoring. I'd appreciate a review since the code did change a little. It's ultimately up to you, @rasheedamir whether we go for another review round or merge this as is. Strange thing I noticed: the logs for the unittest check show 35 tests, but there are in fact 45 in the latest commit here. Wonder what's up with that. Feels like it's not actually running off the latest commit. :( EDIT: Looks like the unittest job is checking out |
@mustafaStakater can you plz do the final review of this? |
@d3adb5 the use of We might want to reference the pull request head ref in the unittest checkout action so latest code is gathered before executing the actual tests. |
LGTM |
Sorry, i was out of office for a few days. Thanks for taking care of this! ❤️ |
Hi,
i really like the idea of creating a generic chart which can be used for many use cases, but i have a small issue with the Chart.
Currently you use the the following code block for the image definition:
This means that currently
deployment.image.tag
is a required param. The current default value isv1.0.0
. This is a bit odd, because a image definition is also valid w/o a tag. For example, the following definitions are also valid and not all of them are currently supported by the chart:Also it's very common that you receive the image as complete "all-in-one" string from a CI/CD pipeline. Extracting just the digest or tag and hand it over to helm could be very frustrating and complex sometimes. So it would be great if you just set the image with the tag and digest as a single parameter.
Attached you will find a pull request which makes
deployment.image.tag
(andjob.image.tag
) optional and set the default value tonull
.Let me know what you think about this change.