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

Templating Helm Values in fleet.yaml #1164

Closed
manno opened this issue Dec 8, 2022 · 6 comments
Closed

Templating Helm Values in fleet.yaml #1164

manno opened this issue Dec 8, 2022 · 6 comments

Comments

@manno
Copy link
Member

manno commented Dec 8, 2022

Additional QA

The feature was implemented in multiple PRs, so I'll add the QA info here.

Problem

There are two ways to modify deployments per target cluster: target customizations and cluster label replacement.

Creating target customizations to overwrite the helm values at the root can be tedious for a large number of clusters.

Adding the value of a cluster label to the helm.values section of fleet.yaml is not flexible, e.g. it's not possible to prefix the result. The amount of data stored in a label value is limited.

Solution

The helm values section in fleet.yaml is now a template. Go and sprig template functions can be used to produce values for helm templates.

Additionally, values from the cluster resource (spec.templateValues) are passed into the template to produce cluster dependent helm values.

Note, this is limited to helm-type bundles, manifests and kustomize bundles don't use the helm values section.
And helm.valuesFrom is not templated, the configmap, secrets are on downstream clusters, the templating happens before creating the bundle deployment on the upstream cluster.
However, any helm.valuesFiles are in the bundle and their values will be templated.

The fleet.yaml has to be valid YAML, so not all templating constructs one knows from, for example, helm will work. In a helm templates/ folder, it's possible to generate YAML with with and range. In fleet.yaml this will only work in multi-line strings.

Writing valid templating code is the users responsibility, templates with errors won't produce new bundledeployments.

Testing

Engineering Testing

Manual Testing

  • Add labels and templateValues to a fleet cluster resource.
  • Deploy with a fleet.yaml that has a 'helm.values' section with templating instructions to use the values from the cluster resource.
  • Should work in root values and in overwritten values from a target customization.

Example: https://github.com/rancher/fleet-examples/blob/test-cluster-values/single-cluster/helm-cluster-values/fleet.yaml
Documentation: https://fleet.rancher.io/next/gitrepo-structure#reference

Automated Testing

QA Testing Considerations

It's not necessary to test all possible template functions and advanced templating use cases. It's expected that users mostly use templating to set default strings and modify/prefix string values.

Regressions Considerations

Cluster label replacement (using the replacement string global.fleet.clusterLabels.LABELNAME) should still work.

@manno
Copy link
Member Author

manno commented Jan 26, 2023

This will not be backported to 0.5.2 due to time constraints.

@olblak
Copy link
Member

olblak commented Jan 26, 2023

Assigning this issue to the milestone 2023-Q1-v2.7x as the team won't have the time before

@olblak
Copy link
Member

olblak commented Feb 8, 2023

Is related to https://jira.suse.com/browse/SURE-5326

@kkaempf
Copy link
Collaborator

kkaempf commented Feb 8, 2023

Is related to https://jira.suse.com/browse/SURE-5326

And SURE-4263

@kkaempf kkaempf added the JIRA Must shout label Feb 8, 2023
@sowmyav27
Copy link

Since there is Automated tests around this, QA will pick this up for validations, in the end (lower priority)

@MSpencer87
Copy link

Verified on Fleet 102.0.0+up0.6.0-rc.5

Template functions can be used to produce values for helm template strings and modify/prefix string values.

Steps to reproduce:

  1. Bring up HA Rancher setup on 2.6.4 with a downstream cluster, confirm fleet verison 0.3.9
  2. Fork the fleet-examples repo https://github.com/rancher/fleet-examples and create a new branch from single-cluster/helm-cluster-value and/or single-cluster/hel-template-values for testing
  3. Navigate to Continuous Delivery via UI, select Git Reops and then select Create
  4. Edit the fleet.yaml to remove ${ uuidv4 } from namespace: ${ .ClusterNamespace }
  5. Enter a name, the forked repository URL and the name of the test branch. Add proper path /single-cluster/test-branch-name and select Create
  6. Adding this repo will fail to deploy with error
Template: sleeper-chart/templates/deployment.yaml:34:47: executing "sleeper-chart/templates/deployment.yaml" at <.Values.hostnames>: range can't iterate over ${ list "one" "two" "three" | uniq | toJson }

Steps to validate:

  1. Bring up HA Rancher setup on 2.7.2-rc8 with a downstream cluster, confirm fleet verison 102.0.0+up0.6.0-rc.5
  2. Fork the fleet-examples repo https://github.com/rancher/fleet-examples and create a new branch from single-cluster/helm-cluster-value and/or single-cluster/helm-template-values for testing
  3. Edit the fleet.yaml to remove ${ uuidv4 } from namespace: ${ .ClusterNamespace }
  4. Navigate to Continuous Delivery via UI, select Git Reops and then select Create
  5. Enter a name, the forked repository URL and the name of the test branch. Add path /single-cluster/test-branch-name and select Create
  6. Confrm test chart depoloyment is successful inside the downstream cluster
  7. Confirm git repo reaches Active state with Clusters Ready 1/1
  8. Confrim bundle is created with no errors and reaches Active state

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

No branches or pull requests

5 participants