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

Helm: ensure valid label values when version has digest #8260

Merged
merged 1 commit into from
Jan 25, 2023

Conversation

sathieu
Copy link
Contributor

@sathieu sathieu commented Jan 24, 2023

What this PR does / why we need it:

Fix this:

$ helm install loki grafana/loki \
  --set loki.image.tag=2.7.1@sha256:d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb61606b42a8d41a557
ServiceAccount "loki" is invalid: [
  metadata.labels: Invalid value: "2.7.1@sha256:d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb61606b42a8d41a557": must be no more than 63 characters,
  metadata.labels: Invalid value: "2.7.1@sha256:d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb61606b42a8d41a557": 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])?')
],
Service "loki" is invalid: [
  metadata.labels: Invalid value: "2.7.1@sha256:d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb61606b42a8d41a557": must be no more than 63 characters,
  metadata.labels: Invalid value: "2.7.1@sha256:d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb61606b42a8d41a557": 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])?')
],
[...]

To ensure it is allowed, and leads to:

      app.kubernetes.io/version: "2.7.1-sha256-d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb616"

See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

(see also https://gitlab.com/kubitus-project/kubitus-installer/-/jobs/3649809256)

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/upgrading/_index.md

@sathieu sathieu requested a review from a team as a code owner January 24, 2023 16:00
@CLAassistant
Copy link

CLAassistant commented Jan 24, 2023

CLA assistant check
All committers have signed the CLA.

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

Thanks for bringing this up, nice find. 2 small questions regarding the implementation, but +1 to moving forward with this.

@@ -80,7 +80,7 @@ Common labels
helm.sh/chart: {{ include "loki.chart" . }}
{{ include "loki.selectorLabels" . }}
{{- if or (.Chart.AppVersion) (.Values.loki.image.tag) }}
app.kubernetes.io/version: {{ .Values.loki.image.tag | default .Chart.AppVersion | quote }}
app.kubernetes.io/version: {{ (regexReplaceAllLiteral "@.*" (.Values.loki.image.tag | default .Chart.AppVersion) "") | quote }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

2 questions.

  1. should we replace it with a : instead of nothing so there's still a visible separator
  2. we probably also want to enforce it's truncated to 63 characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review @trevorwhitney.

As : is not allowed, I've replaced it with -. I've moved this to a new defined template "loki.validLabelValue". Back to you 🏓!

loki.image.tag=2.7.1@sha256:d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb61606b42a8d41a55
leads to:

  app.kubernetes.io/version: "2.7.1-sha256-d69f377ecfdbb3f72086a180dcd7c2f02c795cf1867bbeb616"

See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
@sathieu sathieu changed the title Helm: drop digest from version digest Helm: ensure valid label values when version has digest Jan 25, 2023
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the contribution!

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

Successfully merging this pull request may close these issues.

4 participants