Closed guilhemmarchand closed 5 years ago
Can you verify there aren't any newlines getting appended to the uuid when it's initially generated/set? Where the toml parse error is on line 4, it seems like the value is taking two lines.
Reproducible with the following:
[global_tags]
env = "$ENV"
splunk_hec_token = "1234-1234-1234-1234
"
[agent]
Hi @glinton
Thanks, it is very suspicious and your explanation would make sense so I re-tested again, and unless I am really missing something here, I still see the same issue.
If I move from secrets to a simple configMap, then I have no issues at all, aka:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: kafka
name: global-config
data:
env: my-environment
splunk_hec_url: xxxxxxxxx.eu-west-2.compute.amazonaws.com:8088
splunk_hec_token: 205d43f1-2a31-4e60-a8b3-327eda49944a
Notes: With or without an extra line at the end of the yaml file, I see not changes at all
Then in my pod definition:
# meant to be applied using
# kubectl --namespace kafka patch statefulset zookeeper --patch "$(cat 02-patch-zookeeper-statefulset.yml )"
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: confluent-oss-cp-zookeeper
namespace: kafka
spec:
template:
spec:
containers:
- name: telegraf
image: docker.io/telegraf:latest
resources:
requests:
cpu: 10m
memory: 60Mi
limits:
memory: 120Mi
env:
- name: ENV
valueFrom:
configMapKeyRef:
name: global-config
key: env
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: SPLUNK_HEC_URL
valueFrom:
configMapKeyRef:
name: global-config
key: splunk_hec_url
- name: SPLUNK_HEC_TOKEN
valueFrom:
configMapKeyRef:
name: global-config
key: splunk_hec_token
volumeMounts:
- name: telegraf-config-zookeeper
mountPath: /etc/telegraf
volumes:
- name: telegraf-config-zookeeper
configMap:
name: telegraf-config-zookeeper
This works perfectly fine.
If I only switch my "splunk_hec_token" value in a secret:
apiVersion: v1
kind: Secret
metadata:
name: splunk-secrets
namespace: kafka
type: Opaque
data:
splunk_hec_token: MjA1ZDQzZjEtMmEzMS00ZTYwLWE4YjMtMzI3ZWRhNDk5NDRhCg==
Notes: With or without extra line at the end of the yaml, does not change anything
Then the pod will fail and I get the toml parsing issue.
I have triple checked and I can't find an explanation.
I think a build with some debug logging could help with understanding what is happening, @guilhemmarchand are you able to compile Telegraf if I show you what to change?
Hi @danielnelson
Sure thing yes, if I can I will be happy to help.
If you apply this patch then Telegraf will spit out the environment variables and each config file after env var replacement as they are parsed:
diff --git a/internal/config/config.go b/internal/config/config.go
index 469b80ad..596a1a17 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -785,12 +785,14 @@ func parseConfig(contents []byte) (*ast.Table, error) {
env_vars := envVarRe.FindAll(contents, -1)
for _, env_var := range env_vars {
env_val, ok := os.LookupEnv(strings.TrimPrefix(string(env_var), "$"))
+ fmt.Printf("%s=%s (set: %t)\n", env_var, env_val, ok)
if ok {
env_val = escapeEnv(env_val)
contents = bytes.Replace(contents, env_var, []byte(env_val), 1)
}
}
+ fmt.Println(string(contents))
return toml.Parse(contents)
}
Closing, but please let me know if you weren't able to debug this issue.
Relevant telegraf.conf:
System info:
Kubernetes deployment with latest Telegraf container version 1.9.1
Steps to reproduce:
Ex:
https://github.com/guilhemmarchand/splunk-guide-for-kafka-monitoring/tree/master/kubernetes-yaml-examples/kafka-brokers
Generate the base64 values:
Create and apply your secrets:
Create:
kubectl create -f ../../yaml_git_ignored/splunk_secrets.yml
ConfiMap:
https://github.com/guilhemmarchand/splunk-guide-for-kafka-monitoring/blob/master/kubernetes-yaml-examples/kafka-brokers/01-telegraf-config-kafka-brokers.yml
example:
Pod definition:
https://github.com/guilhemmarchand/splunk-guide-for-kafka-monitoring/blob/master/kubernetes-yaml-examples/kafka-brokers/04-patch-kafka-brokers-statefulset.yml
Expected behavior:
The container should start normally and be able to use the values from the secrets.
Actual behavior:
The container will fail to start due to a toml parsing error that happens ONLY with the uuid value stored in my example within the environment variable $SPLUNK_HEC_TOKEN.
The environment variables are available in the container as they should:
Using the $SPLUNK_HEC_URL in my example is not an issue, but as soon as I try to use the uuid stored in the $SPLUNK_HEC_TOKEN, this results in a tolm parsing error.
What is VERY strange is that if I re-export the environment variable:
And then apply the configuration in a temp copy of telegraf.conf, this will work correctly.
This issue is ONLY happening at container startup when the environment variable is defined automatically by Kubernetes AND when the environment variable contains a uuid value.
This can be reproduced by just loading the variable in the
[global_tags]
THIS WORKS OK:
MANUAL RUN:
THIS FAILS:
MANUAL START:
THIS WORKS IF VARIABLE IS MANUALLY RE-EXPORTED:
Additional info: