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 Logstash templating issue in Helm chart #8087

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

naemono
Copy link
Contributor

@naemono naemono commented Oct 8, 2024

Fixes #8000

This change fixes a bug in the helm templating of Logstash and does not add .spec.pipelines when .spec.pipelinesRef is also defined. In addition this adds a test to ensure that the field pipelines is missing in spec when pipelinesRef is also defined.

Add test case.

Signed-off-by: Michael Montgomery <mmontg1@gmail.com>
@botelastic botelastic bot added the triage label Oct 8, 2024
@pebrc pebrc added the >bug Something isn't working label Oct 9, 2024
@botelastic botelastic bot removed the triage label Oct 9, 2024
@botelastic botelastic bot removed the triage label Oct 9, 2024
pipelines: {{ toYaml .Values.pipelines | nindent 4 }}
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Imagine if the user sets both pipelines and pipelinesRef fields, then only pipelinesRef will be rendered without error. What do you think about adding a validation to prevent setting both fields?
Nit: also group pipeline related bits together.

diff --git a/deploy/eck-stack/charts/eck-logstash/templates/logstash.yaml b/deploy/eck-stack/charts/eck-logstash/templates/logstash.yaml
index 3c4deb1bc..162ec317a 100644
--- a/deploy/eck-stack/charts/eck-logstash/templates/logstash.yaml
+++ b/deploy/eck-stack/charts/eck-logstash/templates/logstash.yaml
@@ -31,10 +31,6 @@ spec:
   configRef:
     {{- toYaml . | nindent 4 }}
   {{- end }}
-  {{- with .Values.pipelinesRef }}
-  pipelinesRef:
-    {{- toYaml . | nindent 4 }}
-  {{- end }}
   {{- with .Values.podTemplate }}
   podTemplate:
     {{- toYaml . | nindent 4 }}
@@ -43,8 +39,14 @@ spec:
   monitoring:
     {{- toYaml . | nindent 4 }}
   {{- end }}
-
-  {{- if not (.Values.pipelinesRef)  }}
+  {{- if and .Values.pipelines .Values.pipelinesRef }}
+  {{- fail "pipelines and pipelinesRef are mutually exclusive!" }}
+  {{- end }}
+  {{- with .Values.pipelinesRef }}
+  pipelinesRef:
+    {{- toYaml . | nindent 4 }}
+  {{- end }}
+  {{- if .Values.pipelines  }}
   pipelines: {{ toYaml .Values.pipelines | nindent 4 }}
   {{- end }}
   volumeClaimTemplates: {{ toYaml .Values.volumeClaimTemplates | nindent 4 }}
diff --git a/deploy/eck-stack/charts/eck-logstash/values.yaml b/deploy/eck-stack/charts/eck-logstash/values.yaml
index a2d1d289a..e68694852 100644
--- a/deploy/eck-stack/charts/eck-logstash/values.yaml
+++ b/deploy/eck-stack/charts/eck-logstash/values.yaml
@@ -78,11 +78,11 @@ monitoring: {}
   #     namespace: observability
 
 # The Logstash pipelines, the ECK equivalent to pipelines.yml
+# NOTE: The `pipelines` and `pipelinesRef` fields are mutually exclusive. Only one of them should be defined at a time, as using both may cause conflicts.
 # ref: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-logstash-configuration.html#k8s-logstash-pipelines
 #
 pipelines: []
-
-pipelinesRef: {}
+# pipelinesRef:
 #  secretRef:
 #    secretName: ''

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 @thbkrkr , this makes a lot of sense. Upon further looking at the documentation in the values file, I'm noticing some other issues I'm going to double check/fix:

This doesn't appear to be correct, according to the documentation:

-pipelinesRef: {}
-#  secretRef:
-#    secretName: ''

It should be:

# pipelinesRef:
#   secretName: ''

Also, do we have the same situation for config and configRef? I believe we do. I'm going to double check that as well, as those seem to be mutually exclusive also.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well seen, yes pipelinesRef. secretRef is not valid

and config / configRef are also mutually exclusive.

msg := "Specify at most one of [`config`, `configRef`], not both"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok @thbkrkr , the values file has been updated, the template will now fail on this as well, and there are 2x tests to ensure this functionality. Ready for next set of 👀 when you can. Thanks!

Add notes to values file to be more clear about mutually exclusive
options.
Add tests for mutual exclusion fails.

Signed-off-by: Michael Montgomery <mmontg1@gmail.com>
@naemono naemono requested a review from thbkrkr October 9, 2024 14:11
Copy link
Contributor

@thbkrkr thbkrkr left a comment

Choose a reason for hiding this comment

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

Good improvements! ✨

@naemono naemono merged commit 74cf3d0 into elastic:main Oct 9, 2024
5 checks passed
@naemono naemono deleted the fix-helm-logstash-templating branch October 9, 2024 19:05
@rhr323 rhr323 changed the title Fix logstash templating issue. Fix logstash templating issue in Helm chart Nov 6, 2024
@rhr323 rhr323 changed the title Fix logstash templating issue in Helm chart Fix Logstash templating issue in Helm chart Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Something isn't working v2.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect templating of Logstash object when using pipelinesRef parameter
3 participants