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

Toolbox template #3287

Merged
merged 2 commits into from
Sep 10, 2017
Merged

Conversation

gambol99
Copy link
Contributor

@gambol99 gambol99 commented Aug 26, 2017

Extending the current implementation of toolbox template to include multiple files and snippets. Note, I've removed the requirements for defaults as I think people should be forced to specifically pass them

  • allowing the users to use a snippets directory for reusable templates
  • allows the users to specify multiple templates files via multiple --template , use a directory or both
  • allows the users to specify multiple configuration files via multiple --values , use a directory or both
  • adding a safety check to ensure templates don't reference an unknown values
  • fixing the vetting issues to the method YamlToJson -> YAMLToJSON
  • as usual anything a saw on the journey which doesn't comply with go-vet got changed

Examples of a snippet

hooks:
  - name: some_service.service
    manifest: |
      {{ include "some_service.service" . | indent 6 }}

We currently use something similar to template our cluster and instances group documents, handling the differences between prod, ci and ephemeral

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 26, 2017
@gambol99
Copy link
Contributor Author

cc @mad01

@gambol99
Copy link
Contributor Author

/retest

Copy link
Contributor

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

Questions for you

pkg/util/file.go Outdated
)

// isDirectory checks if a path points to a directory
func isDirectory(path string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have any code like this or in or dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just taken a look at the util package in kubernetes but i can't anything that stands out .. I'll try again though

pkg/util/file.go Outdated
}

// ExpandFiles is responsible for resolving any references to directories
func ExpandFiles(path string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is some code in kubectl that we should probably reuse. I can check tomorrow.

@justinsb thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

@@ -0,0 +1,130 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we cut and actual package name for this? Maybe templater, you pick a name. Util pkg name drives me nuts.

}

// templateFuncsMap returns a map if the template functions for this template
func (r *Renderer) templateFuncsMap(tm *template.Template) template.FuncMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder if we should use a library for this. What is helm using?

Copy link
Contributor

Choose a reason for hiding this comment

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

@chrislovecnm Helm is based on text/template to be able to use gotemplate i guess. The helm templating code is going a bit more then just what the text/template package gives and were not that portable. i guess with some effort the helm templating can be a package but that is not without effort.

Copy link
Contributor

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

A couple of nit picks. Looks good overall. Wonder if we should use a lib like what helm uses for stuff like join and indent.

for _, x := range options.configPath {
list, err := putil.ExpandFiles(utils.ExpandPath(x))
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Fmt error please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed! .. and fixed

list, err := putil.ExpandFiles(utils.ExpandPath(x))
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Fmt? Helps me trace where the erro was returned

@mad01
Copy link
Contributor

mad01 commented Aug 28, 2017

@chrislovecnm @gambol99 for joins helm uses sprig might be a good idea to use the same to be able to have the same features as in helm

@gambol99
Copy link
Contributor Author

gambol99 commented Aug 28, 2017

the sprig library is a good shout so i've updated to using that ... One question though how are managing the vendor directory? .. or you just copying in code? ... or i'm i missing something completely (admittedly i'm only familiar with godeps and glide) @chrislovecnm @justinsb

@chrislovecnm
Copy link
Contributor

There are docs on how to vendor with the sub modules, you will probably want to do just a PR to add the vendoring. The docs are under dev folder in docs.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 28, 2017
@gambol99
Copy link
Contributor Author

any other issues on this one? ...

@chrislovecnm
Copy link
Contributor

@gambol99 sorry to be picky, but can we break the vendoring into a separate PR, and get that in first? Then we can get this code in. That is the workflow that we have followed in the past for new deps.

Thanks

@justinsb
Copy link
Member

I previously looked at this and meant to apply lgtm - sorry for delay. I was able to follow the deps so I don't think these need to be split up...

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 31, 2017
@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 31, 2017
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@gambol99
Copy link
Contributor Author

/test pull-kops-e2e-kubernetes-aws

@chrislovecnm
Copy link
Contributor

You may need another rebase to be e2e to pass. @justinsb I cannot remember when you put in the fix in kops that fixed e2e.

@k8s-github-robot
Copy link

/lgtm cancel //PR changed after LGTM, removing LGTM. @gambol99 @justinsb

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 2, 2017
@gambol99
Copy link
Contributor Author

gambol99 commented Sep 3, 2017

/test pull-kops-e2e-kubernetes-aws

@chrislovecnm
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 4, 2017
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@chrislovecnm
Copy link
Contributor

Some more examples would be awesome, we should probably look at getting this out of toolbox ;)

@k8s-github-robot
Copy link

/lgtm cancel //PR changed after LGTM, removing LGTM. @chrislovecnm @gambol99 @justinsb

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 4, 2017
@gambol99 gambol99 closed this Sep 6, 2017
@gambol99 gambol99 reopened this Sep 6, 2017
@chrislovecnm
Copy link
Contributor

@gambol99 sorry for the nit pick, but can you squash into appropriate chunks of work. I would like to have the vendoring commit moved to the first commit if you can. After that let's get it in ... I want to try it :)

Extending the current implementation of toolbox template to include multiple files and snippets. Note, i've removed the requirements for defaults as I think people should be forced to specifically pass them.

- fixing the vetting iseues to the method YamlToJson -> YAMLToJSON
- adding a safety check to ensure templates don't reference an unknown value
- extending the unit test to ensure the above works on main and snippets
- include the ability to specify multiple configuration files, useful for common.yaml and prod.yaml etc

Requested Changes - Toolbox Templating

Added the requested changes

- moved the templater into it's own package rather than using base util
- moved to using the sprig library for additional template function
- @note: i couldn't find a native way in sprig to do snippets, also the i've overloaded the indent as it appears to do the indent on all lines rather than on the newline, meaning i'd have to shift my first line back by the indent to get it to work, which seems ugly
Adding the dependecies for the templating
@gambol99
Copy link
Contributor Author

gambol99 commented Sep 8, 2017

/test pull-kops-e2e-kubernetes-aws

1 similar comment
@gambol99
Copy link
Contributor Author

gambol99 commented Sep 8, 2017

/test pull-kops-e2e-kubernetes-aws

@chrislovecnm
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 10, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrislovecnm, gambol99, justinsb

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

Needs approval from an approver in each of these OWNERS Files:
  • OWNERS [chrislovecnm,justinsb]

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@chrislovecnm
Copy link
Contributor

@k8s-bot go bot go

@gambol99 we will need release notes please

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 721ba52 into kubernetes:master Sep 10, 2017
@chrislovecnm
Copy link
Contributor

Holy crap batman - it merged

@gambol99 gambol99 deleted the toolbox_template branch February 21, 2019 23:08
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants