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

fix(helm): change how the configMap for the gateway is generated #14575

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jarmd
Copy link

@jarmd jarmd commented Oct 22, 2024

What this PR does / why we need it:

This PR updates the helm template file for [configmap-gateway.yaml] and the default values.yaml file
When you try to change the default configuration of:

gateway:
  nginxConfig:
    file: |
      A full nginx configuration file

The helm template errors out with the following error:

Error: YAML parse error on loki/templates/gateway/configmap-gateway.yaml: error converting YAML to JSON: yaml: line 14: did not find expected comment or line break

It has been tested to do the extra configuration in several way like:

  file: |-
  file: |
  file: >-

But it all keeps errors out.

With this update we have tested the following scenarios with code snippets for the GW deployment:

  • Scenario 1:
    The user uses the default helm values

    loki:
    schemaConfig:
      configs:
        - from: 2022-09-28
          store: boltdb-shipper
          object_store: azure
          schema: v11
          index:
            prefix: loki_index_
            period: 24h
          chunks:
            prefix: loki_chunk_
            period: 24h
    storage:
      bucketNames:
        chunks: FIXME
        ruler: FIXME
        admin: FIXM
    
  • Scenario 2
    The user has as bad practice copied the entire default values to their configuration using the old values file default config:

    loki:
      schemaConfig:
        configs:
          - from: 2022-09-28
            store: boltdb-shipper
            object_store: azure
            schema: v11
            index:
              prefix: loki_index_
              period: 24h
            chunks:
              prefix: loki_chunk_
              period: 24h
      storage:
        bucketNames:
          chunks: FIXME
          ruler: FIXME
          admin: FIXME
    gateway:
      nginxConfig:
        file: |
          {{- include "loki.nginxFile" . | indent 2 -}}
  • Scenario 3
    The user has their own customized nginx configuration

    loki:
      schemaConfig:
        configs:
          - from: 2022-09-28
            store: boltdb-shipper
            object_store: azure
            schema: v11
            index:
              prefix: loki_index_
              period: 24h
            chunks:
              prefix: loki_chunk_
              period: 24h
      storage:
        bucketNames:
          chunks: FIXME
          ruler: FIXME
          admin: FIXME
    gateway:
      nginxConfig:
        file: |-
          worker_processes  5;  ## Default: 1
          error_log  /dev/stderr;
          pid        /tmp/nginx.pid;
          worker_rlimit_nofile 8192; 

Note: The loki-distributed helm chart uses the same approach for the template of the gateway configmap:
https://github.com/grafana/helm-charts/blob/main/charts/loki-distributed/templates/gateway/configmap-gateway.yaml#L10

Which issue(s) this PR fixes:
Fixes #
N/A

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added (N/A)
  • Tests updated (N/A)
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md (N/A)
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@jarmd jarmd requested a review from a team as a code owner October 22, 2024 13:46
@CLAassistant
Copy link

CLAassistant commented Oct 22, 2024

CLA assistant check
All committers have signed the CLA.

This comment has been minimized.

This comment has been minimized.

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.

It looks like this results in a change to the rendered configmap (see the results of the diff CI job), any idea why that's the case? On it's surface it looks like this is a backwards compatible change, so I'm fine with it as long as we can explain that difference in the rendered manifests.

@jarmd
Copy link
Author

jarmd commented Oct 24, 2024

It looks like this results in a change to the rendered configmap (see the results of the diff CI job), any idea why that's the case? On it's surface it looks like this is a backwards compatible change, so I'm fine with it as long as we can explain that difference in the rendered manifests.

Hi @trevorwhitney
Due to the change to nindent from indent in the configmap-gateway.yaml the manifest changes.
To illustrate why the change to nindent from indent I will be using the the following custom file configuration:

    file: |-
      # My comment
      worker_processes  5;  ## Default: 1
      error_log  /dev/stderr;
      pid        /tmp/nginx.pid;
      worker_rlimit_nofile 8192;

Since my first line here is a comment I can illustrate what is happening since the comment is valid code in both yaml and in the configmap:

With indent 4:

data:
  nginx.conf: | # My comment
    worker_processes  5;  ## Default: 1
    error_log  /dev/stderr;
    pid        /tmp/nginx.pid;
    worker_rlimit_nofile 8192;

You can see that the comment is added to the same line as the nginx.conf: | in the ConfigMap

When using nindent 4:

data:
  nginx.conf: |
    # My comment
    worker_processes  5;  ## Default: 1
    error_log  /dev/stderr;
    pid        /tmp/nginx.pid;
    worker_rlimit_nofile 8192;

If the first line in the configuration is not a #comment this will error out when using indent 4 when using custom file configuration as above.

Error: YAML parse error on loki/templates/gateway/configmap-gateway.yaml: error converting YAML to JSON: yaml: line 14: did not find expected comment or line break

I hope this explains it well enough :)

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Nov 7, 2024

Kubernetes Manifest Diff Summary

Scenario: default-single-binary-values (Added: 0, Modified: 2, Removed: 0)

Summary:

  • Added: 0

  • Modified: 2

  • Removed: 0

Added Files

No added files

Modified Files

loki/templates/gateway/configmap-gateway.yaml
*** /home/runner/work/loki/loki/output/base/default-single-binary-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:05.625939515 +0000
--- /home/runner/work/loki/loki/output/pr/default-single-binary-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:08.421931952 +0000
***************
*** 13,19 ****
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: | 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
--- 13,20 ----
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: |
! 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
loki/templates/gateway/deployment-gateway-nginx.yaml
*** /home/runner/work/loki/loki/output/base/default-single-binary-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:05.629939503 +0000
--- /home/runner/work/loki/loki/output/pr/default-single-binary-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:08.421931952 +0000
***************
*** 25,31 ****
 template:
 metadata:
 annotations:
! checksum/config: 3dbb80416c97a064cb67bdff77651e9aaf2147a4203dcf817a86a4281ae529a7
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name
--- 25,31 ----
 template:
 metadata:
 annotations:
! checksum/config: 5c6a0c0f55c1f1f53bcf5b8e2b17153d536bed0b09bb1d66d31d2fbf664a021c
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name

Removed Files

No removed files

Scenario: default-values (Added: 0, Modified: 2, Removed: 0)

Summary:

  • Added: 0

  • Modified: 2

  • Removed: 0

Added Files

No added files

Modified Files

loki/templates/gateway/configmap-gateway.yaml
*** /home/runner/work/loki/loki/output/base/default-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:05.721939255 +0000
--- /home/runner/work/loki/loki/output/pr/default-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:08.517931693 +0000
***************
*** 13,19 ****
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: | 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
--- 13,20 ----
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: |
! 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
loki/templates/gateway/deployment-gateway-nginx.yaml
*** /home/runner/work/loki/loki/output/base/default-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:05.721939255 +0000
--- /home/runner/work/loki/loki/output/pr/default-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:08.517931693 +0000
***************
*** 25,31 ****
 template:
 metadata:
 annotations:
! checksum/config: b42ca6b4a926bc67707b4bb02223e29e6a691983ba80c3efb237f4f6b060bc8f
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name
--- 25,31 ----
 template:
 metadata:
 annotations:
! checksum/config: 1faa240238fd567bea695d863b1e3cf66c931ab208e27b08774e77449a774deb
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name

Removed Files

No removed files

Scenario: ingress-values (Added: 0, Modified: 2, Removed: 0)

Summary:

  • Added: 0

  • Modified: 2

  • Removed: 0

Added Files

No added files

Modified Files

loki/templates/gateway/configmap-gateway.yaml
*** /home/runner/work/loki/loki/output/base/ingress-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:05.817938995 +0000
--- /home/runner/work/loki/loki/output/pr/ingress-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:08.613931433 +0000
***************
*** 13,19 ****
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: | 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
--- 13,20 ----
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: |
! 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
loki/templates/gateway/deployment-gateway-nginx.yaml
*** /home/runner/work/loki/loki/output/base/ingress-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:05.821938985 +0000
--- /home/runner/work/loki/loki/output/pr/ingress-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:08.613931433 +0000
***************
*** 25,31 ****
 template:
 metadata:
 annotations:
! checksum/config: b42ca6b4a926bc67707b4bb02223e29e6a691983ba80c3efb237f4f6b060bc8f
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name
--- 25,31 ----
 template:
 metadata:
 annotations:
! checksum/config: 1faa240238fd567bea695d863b1e3cf66c931ab208e27b08774e77449a774deb
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name

Removed Files

No removed files

Scenario: legacy-monitoring-values (Added: 0, Modified: 2, Removed: 0)

Summary:

  • Added: 0

  • Modified: 2

  • Removed: 0

Added Files

No added files

Modified Files

loki/templates/gateway/configmap-gateway.yaml
*** /home/runner/work/loki/loki/output/base/legacy-monitoring-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:05.921938714 +0000
--- /home/runner/work/loki/loki/output/pr/legacy-monitoring-values/loki/templates/gateway/configmap-gateway.yaml	2024-11-07 06:41:08.717931152 +0000
***************
*** 13,19 ****
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: | 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
--- 13,20 ----
 app.kubernetes.io/managed-by: Helm
 app.kubernetes.io/component: gateway
 data:
! nginx.conf: |
! 
 worker_processes 5; ## Default: 1
 error_log /dev/stderr;
 pid /tmp/nginx.pid;
loki/templates/gateway/deployment-gateway-nginx.yaml
*** /home/runner/work/loki/loki/output/base/legacy-monitoring-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:05.925938703 +0000
--- /home/runner/work/loki/loki/output/pr/legacy-monitoring-values/loki/templates/gateway/deployment-gateway-nginx.yaml	2024-11-07 06:41:08.717931152 +0000
***************
*** 25,31 ****
 template:
 metadata:
 annotations:
! checksum/config: b42ca6b4a926bc67707b4bb02223e29e6a691983ba80c3efb237f4f6b060bc8f
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name
--- 25,31 ----
 template:
 metadata:
 annotations:
! checksum/config: 1faa240238fd567bea695d863b1e3cf66c931ab208e27b08774e77449a774deb
 labels:
 app.kubernetes.io/name: loki
 app.kubernetes.io/instance: loki-test-chart-name

Removed Files

No removed files

Scenario: simple-scalable-aws-kube-irsa-values (Added: 0, Modified: 0, Removed: 0)

Summary:

  • Added: 0

  • Modified: 0

  • Removed: 0

Added Files

No added files

Modified Files

No modified files

Removed Files

No removed files

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.

3 participants