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

Lookup function not working #12418

Closed
mivalsten opened this issue Sep 23, 2023 · 7 comments
Closed

Lookup function not working #12418

mivalsten opened this issue Sep 23, 2023 · 7 comments

Comments

@mivalsten
Copy link

Output of helm version:

version.BuildInfo{Version:"v3.12.1", GitCommit:"f32a527a060157990e2aa86bf45010dfb3cc8b8d", GitTreeState:"clean", GoVersion:"go1.20.4"}

Output of kubectl version:

WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.2", GitCommit:"7f6f68fdabc4df88cfea2dcf9a19b2b830f1e647", GitTreeState:"clean", BuildDate:"2023-05-17T14:20:07Z", GoVersion:"go1.20.4", Compiler:"gc", Platform:"windows/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.4", GitCommit:"fa3d7990104d7c1f16943a67f11b154b71f6a132", GitTreeState:"clean", BuildDate:"2023-07-21T14:07:10Z", GoVersion:"go1.20.6", Compiler:"gc", Platform:"linux/arm64"}

Cloud Provider/Platform (AKS, GKE, Minikube etc.):
Microk8s

Hi All!

For some reason, my lookup function does not work properly. Here is my chart:

_helpers.tpl

{{- define "password" -}}
{{- $len := 24 | int -}}
{{- $obj := (lookup "v1" "secret" .Namespace "gig3r-secret").data -}}
{{- if $obj }}
{{- index $obj "DB_PASSWORD" -}}
{{- else -}}
{{- randAlphaNum $len | b64enc -}}
{{- end -}}
{{- end }}

secrets.yaml

---
apiVersion: v1
kind: Secret
metadata:
  name: gig3r-secret
type: Opaque
data:
  DB_PASSWORD: "{{ include "gig3r.database.password" (dict "Namespace" .Release.Namespace ) }}"
  debug: "{{ (lookup "v1" "Secret" .Release.Namespace "gig3r-secret") | toJson }}"

kubectl get secret gig3r-secret -n test returns:

NAME           TYPE     DATA   AGE
gig3r-secret   Opaque   1      21h

I deploy this with below command: (sorry for windows escapes)

helm upgrade --install `
  gig3r-test `
  ../chart/gig3r `
  --wait `
  --atomic `
  --namespace=test `
  --create-namespace `
  --dry-run --debug

And the result is this:

MANIFEST:
---
# Source: gig3r/templates/secrets.yaml
apiVersion: v1
kind: Secret
metadata:
  name: gig3r-secret
type: Opaque
data:
  DB_PASSWORD: "SGRMWEZ4RlZCeGdublY1Y0xsaDE3VjUw"
  debug: "{}"

Every time I run, DB_PASSWORD is different, even though there is a secret/gig3r-secret in namespace test with key DB_PASSWORD. And as you can see from data.debug, lookup returns empty object. Is this a bug or am I doing something wrong?

@Ithrael
Copy link
Contributor

Ithrael commented Sep 23, 2023

helm upgrade --install `
  gig3r-test `
  ../chart/gig3r `
  --wait `
  --atomic `
  --namespace=test `
  --create-namespace `
  --dry-run --debug

remove dry-run
https://helm.sh/docs/chart_template_guide/functions_and_pipelines/
image

@mivalsten
Copy link
Author

@Ithrael thank you, it works. I based my assumption that lookup should work with --dry-run on this entry.
image

What is then the difference between helm template and helm install --dry-run?

@Ithrael
Copy link
Contributor

Ithrael commented Sep 25, 2023

I believe they are essentially the same, because helm template will invoke the runInstall function , which is the core function in the helm install process. Then helm template will set dry-run value to true before invoking runInstall.

@lindhe
Copy link
Contributor

lindhe commented Nov 11, 2023

Works with helm template --dry-run=server, though!

@Kerry-G
Copy link

Kerry-G commented Nov 16, 2023

helm upgrade --install `
  gig3r-test `
  ../chart/gig3r `
  --wait `
  --atomic `
  --namespace=test `
  --create-namespace `
  --dry-run --debug

remove dry-run https://helm.sh/docs/chart_template_guide/functions_and_pipelines/ image

This documentation is not true anymore, so I created a PR on the helm doc's repo.

@gjenkins8
Copy link
Contributor

Thanks @Kerry-G (docs update looks to have been missed from #9426 )

Copy link

This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

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

No branches or pull requests

5 participants