Skip to content

[backport v2.13] Unable to use lookup in Fleet-managed Helm template #4379

@rancherbot

Description

@rancherbot

This is a backport issue for #1851, automatically created via GitHub Actions workflow initiated by @0xavi0

Original issue body:

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

If I create a Fleet Bundle with an embedded Helm chart, and one of the templates in that Helm chart uses Helm's lookup feature, it does not work. The lookup function returns nothing, and the template does not render as expected.

Expected Behavior

Fleet Bundles with Helm charts that use lookup should function as expected.

Steps To Reproduce

Create a simple Helm bundle:

$ cat Chart.yaml
apiVersion: v2
name: lookup-test
version: 1.0.0

$ cat fleet.yaml
helm:
  chart: .

$ cat templates/config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: config-test
  namespace: kube-system
data:
  lookup-output: {{ len (lookup "v1" "Pods" "kube-system" "").items }}

When deployed to a cluster, the expected ConfigMap should have a number (the count of Pods in kube-system) as the value in lookup-output. But instead we get an error from Fleet indicating that it was unable to parse the template:

    message: 'ErrApplied(10) [Bundle lookup-test-test: template: test/templates/config.yaml:7:20:
      executing "test/templates/config.yaml" at <len (lookup "v1" "Pods"
      "kube-system" "").items>: error calling len: len of nil pointer]'

The fact that it complains of a nil pointer is important -- that means that the lookup function either returned an empty dict, or a nil pointer itself. If it had executed properly, even if there were no resources matching the query, items would have been an empty list, and len would have returned 0.

Environment

- Architecture: amd64
- Fleet Version: 0.7.0
- Cluster:
  - Provider: RKE
  - Options:
  - Kubernetes Version: 1.26

Logs

No response

Anything else?

No response

Metadata

Metadata

Labels

Type

No type

Projects

Status

🆕 New

Relationships

None yet

Development

No branches or pull requests

Issue actions