Skip to content

refactor: #14 - improve image property#18

Open
jeanbaptisterevel wants to merge 2 commits into
Djaytan:mainfrom
jeanbaptisterevel:feat/improve-image-property
Open

refactor: #14 - improve image property#18
jeanbaptisterevel wants to merge 2 commits into
Djaytan:mainfrom
jeanbaptisterevel:feat/improve-image-property

Conversation

@jeanbaptisterevel
Copy link
Copy Markdown
Contributor

@jeanbaptisterevel jeanbaptisterevel commented Jul 15, 2025

Improves the image property in the values.yml file

Closes #14

@jeanbaptisterevel jeanbaptisterevel changed the title refactor: improve image property refactor: #14 - improve image property Jul 15, 2025
@jeanbaptisterevel jeanbaptisterevel force-pushed the feat/improve-image-property branch from a4e909f to 499d44a Compare July 15, 2025 11:02
Comment thread src/templates/_image.tpl
Builds a full OCI image reference from the given image object.

Usage:
{{ include "papermc-server.image" (dict "image" .Values.container.image) }}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Too complicated usage.

The include must be as simple as {{ include "papermc-server.image" . }}.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

  • I realize that your implementation rely on the root context instead of a sub one.

{{ $image := .Values.container.image -}}

Definitively, you have something to do on this front for the reconciliation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yes you're right, my bad.
I was having fun using the tool to see what was possible before simplifying the template usage, and I forgot to update the documentation.
The correct usage is {{ include "papermc-server.image" . }}, this is what I used in the deployment manifest...

Comment thread src/templates/_image.tpl
{{ include "papermc-server.image" (dict "image" .Values.container.image) }}

If digest is "none", returns: <registry>/<name>:<tag>
Otherwise returns: <registry>/<name>@<digest>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Tag is required even when specifying digest.
At least, it works when having both the tag and digest defined.

Comment thread src/templates/_image.tpl
Otherwise returns: <registry>/<name>@<digest>
*/}}
{{ define "papermc-server.image" -}}
{{ $image := .Values.container.image -}}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Improve readability by leveraging indentations.

Comment thread src/templates/_image.tpl
*/}}
{{ define "papermc-server.image" -}}
{{ $image := .Values.container.image -}}
{{ $registry := $image.registry | default "docker.io" -}}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I feel like it would be a better to deal to directly specify the default values at values.yaml level.

This way, we separate the implementation from the default values.

Comment thread src/templates/_image.tpl
{{ $registry := $image.registry | default "docker.io" -}}
{{ $name := $image.name | default "djaytan/papermc-server" -}}
{{ $tag := $image.tag | default "latest" -}}
{{ $digest := $image.digest | default "none" -}}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

That's weird to have as default none.

Having an undefined variable is fine and a good way to state a variable as "undefined".

Comment thread src/values.schema.json
"name": {
"type": "string",
"description": "Optional name override for the server. Defaults to the Helm release name if not set."
"description": "Custom name for the server instance. If not set, the Helm release name will be used by default."
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not "Custom name", "Name" is enough even the property can be customized.

Comment thread src/values.schema.json
"name": {
"type": "string",
"description": "Optional name override for the server. Defaults to the Helm release name if not set."
"description": "Custom name for the server instance. If not set, the Helm release name will be used by default."
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Favor the default field of JSON Schema when possible.

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.

More fine-grained customization of the OCI image reference

2 participants