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

Incomplete multiline environment variables #597

Closed
dan-santana opened this Issue Apr 16, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@dan-santana

dan-santana commented Apr 16, 2018

Bug:

It seems that multiline environment variables aren't captured correctly on by Telepresence when swapping deployments. I'm currently using the following command:

telepresence --swap-deployment my-app --expose 8000:80 --run <any_command>

For example, when running a shell on a deployment with the configuration below, echo $SAMPLE only gives me following broken JSON:

{
    "a": "b",
    "c": "d",
    "really long key": "really long value",

Configuration (Helm):

sample.json:

{
    "a": "b",
    "c": "d",
    "really long key": "really long value",
    "multiline key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nmQENBFrVHZEBCACuD163edXBofnt8qNyluDufnIp0PucPZmK0lUuaJT/xi5RRki+\ntakVww0LGwPn6mcTI2Tgb2cEIvwk7yyXC5yPOPdWchUCxhfeadIgytDPOm3g51zG\nh/Ob1VH067nZlL1qJ7We4ZP0NGpT+MSVDYwGFROMoliRLe5bqz3SZgCI+GgXiHDU\nNbvkxAHE6Z5ZxkzAjBnJDmOf9kdnIHZvuBAVylHUorjTLN2jxJOQYFx7nqwbaOsA\n6i/5W4/CYm2NwPb09I4H2Hi8qQQ1PN5WV+Ky3PngE6yZTMRk34b1aV5VLJPf3yoi\nfqaqjX9xIetMvg6DZP0FiPqC66DESaEz1rv5ABEBAAG0EHRlc3RAZXhhbXBsZS5j\nb22JARwEEAECAAYFAlrVHZEACgkQ1A1oULTM9GYCigf9EWVBQwsG6LxmjhZ5bFyx\n8WT3H86tUhMgvmPGZEV/jl7VUG69DcGb2mhevN8F3mM/V+6njREwCmF9qKbY5HJj\npgG46Rsm6UrbZVH23CRnHFsQ7M0inyZ1CrhCyMETZYHpKOs7lIdAHH1q9F8fTIW6\n9KTnSe0LQpiV5tNxg2EJzCNYpvyvTOA0mGbi+XbjQJDGKr1xqfMYBr79Os9N/dGe\ncWrpBoHLAzB07ZC5CxdXo7Z21i+cTlTM/2c4tE9dLth3Yzzw9fqXyRqlrG1K8Bmz\n8LKhIHctewW9a6M7JTp48p7fRZiCir7N9Zj0hq6zry8+FHnkZIvFNOHFcbUrfS2Y\n2g==\n=rNSt\n-----END PGP PUBLIC KEY BLOCK-----",
    "one last key": "this last value"
}

templates/secrets.yaml:

apiVersion: v1
kind: Secret
metadata:
  name: {{ template "app.fullname" . }}
  labels:
    app: {{ template "app.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
type: Opaque
data:
  sample: {{ .Files.Get "sample.json" | b64enc | quote }}

templates/deployment.yaml:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "app.fullname" . }}
  labels:
    app: {{ template "app.name" . }}
    chart: {{ template "app.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "app.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "app.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /health/ping/
              port: http
          readinessProbe:
            httpGet:
              path: /health/
              port: http
          resources:
{{ toYaml .Values.resources | indent 12 }}
          env:
            - name: SAMPLE
              valueFrom:
                secretKeyRef:
                  name: {{ template "app.fullname" . }}
                  key: sample
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}

Workaround:

In template/secrets.yaml, replace...

sample: {{ .Files.Get "sample.json" | b64enc | quote }}

... with:

sample: {{ .Files.Get "sample.json" | replace "\n" "" | b64enc | quote }}

Note that this workaround is only valid in this specific case (as JSON parsers doesn't care much about newlines), but probably won't be for many others where lines can't be joined.

@ark3

This comment has been minimized.

Contributor

ark3 commented Apr 17, 2018

Thanks for the bug report and the workaround.

Note to self: I think this is breaking because of the = characters in the value.

@ark3 ark3 added the bug label Apr 17, 2018

@ark3

This comment has been minimized.

Contributor

ark3 commented Apr 25, 2018

Work on this along with #608.

@ark3 ark3 self-assigned this Apr 26, 2018

@ark3 ark3 closed this in c47a95a May 11, 2018

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