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

🌱 Add sprig functions to ClusterClass templates #6131

Conversation

fabriziopandini
Copy link
Member

What this PR does / why we need it:
This PR adds sprig functions to ClusterClass templates

Which issue(s) this PR fixes:
Fixes #6091

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 15, 2022
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 15, 2022
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, very nice small change :)

I think you got all places. Essentially we have two "template" variables and for each of those we have a validation and a place where it's used during patching.

go.mod Show resolved Hide resolved
Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with the go.mod update.

I think we should open an issue for more comprehensive patching documentation as this gets more complex. A few examples of valid patches and the functions we're offering here (doesn't have to be exhaustive.) I'll take that as an issue if you'd like.

@fabriziopandini
Copy link
Member Author

I think we should open an issue for more comprehensive patching documentation as this gets more complex. A few examples of valid patches and the functions we're offering here (doesn't have to be exhaustive.) I'll take that as an issue if you'd like.

Some examples would be nice, but I would wait for providers to start using this so we can provide real use cases.

@sbueringer
Copy link
Member

Thx!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 16, 2022
Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@@ -587,6 +587,9 @@ constant default value which can be specified in the schema is not enough.
# If .vnetName is set, it is used. Otherwise, we will use `{{.builtin.cluster.name}}-vnet`.
template: "{{ if .vnetName }}{{.vnetName}}{{else}}{{.builtin.cluster.name}}-vnet{{end}}"
```
When writing templates, a subset of functions from [sprig](http://masterminds.github.io/sprig/) can be used to
write expressing like e.g. `{{ .name | upper }}`. Only functions that are guaranteed to evaluate to the same result
for a given input are allowed (e.g. `upper` or `max` can be used, while `now` or `randAlpha` can not be used).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document all the available functions in here?

Copy link
Member

@sbueringer sbueringer Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead refer to e.g. that documentation page: http://masterminds.github.io/sprig/

I would really prefer not duplicating parts of their docs (even if it's only a list of funcs) as it provides a lot of stuff.

Copy link
Member Author

@fabriziopandini fabriziopandini Feb 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are over 70 template functions in sprig, I don't think it is doable to document here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking or importing works, from a user experience having them in one place (even if generate) is much more useful when implementing a clusterclass

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 17, 2022
go.mod Outdated Show resolved Hide resolved
@fabriziopandini fabriziopandini force-pushed the clusterclass-templates-support-sprig branch from 98523a8 to 7d209df Compare February 18, 2022 19:51
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 18, 2022
@fabriziopandini fabriziopandini force-pushed the clusterclass-templates-support-sprig branch from 7d209df to 679df25 Compare February 18, 2022 21:04
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 18, 2022
@fabriziopandini fabriziopandini force-pushed the clusterclass-templates-support-sprig branch from 679df25 to d6f7534 Compare February 18, 2022 21:16
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 18, 2022
@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 21, 2022
Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 22, 2022
@k8s-ci-robot k8s-ci-robot merged commit 9cc429d into kubernetes-sigs:main Feb 22, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.2 milestone Feb 22, 2022
@fabriziopandini
Copy link
Member Author

As per #6091 (comment)
/cherry-pick release-1.1

@k8s-infra-cherrypick-robot

@fabriziopandini: #6131 failed to apply on top of branch "release-1.1":

Applying: Add sprig functions to ClusterClass templates
Using index info to reconstruct a base tree...
M	go.mod
M	test/go.mod
M	test/go.sum
Falling back to patching base and 3-way merge...
Auto-merging test/go.sum
Auto-merging test/go.mod
Auto-merging go.mod
CONFLICT (content): Merge conflict in go.mod
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Add sprig functions to ClusterClass templates
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

As per #6091 (comment)
/cherry-pick release-1.1

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sbueringer
Copy link
Member

Manual cherry-pick: #6191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable a richer set of go template functions for defining ClusterClass patches
7 participants