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

tiltfile: helm builtin #994

Merged
merged 18 commits into from
Jan 14, 2019
Merged

Conversation

jazzdan
Copy link
Contributor

@jazzdan jazzdan commented Jan 11, 2019

No description provided.

@jazzdan jazzdan requested review from dbentley and nicks January 11, 2019 18:20
@@ -5,3 +5,10 @@ RUN go get -u github.com/kisielk/errcheck
RUN go get -u github.com/google/wire/cmd/wire

RUN go get -u sigs.k8s.io/kustomize

USER root
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this a cool thing to do?

Copy link
Member

Choose a reason for hiding this comment

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

ya

@@ -15,6 +15,12 @@ import (
"github.com/windmilleng/tilt/internal/model"
)

// TODO(dmiller) this needs to add all of the files in the directory as 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.

Should we have a add_dir_as_dependencies function? Or is this a sign that we shouldn't be trying to implement this in Starlark, and should implement it in Go so that we can walk that chart directory and record dependencies?

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 we need to have lots of thoughts about dependencies, and shouldn't block this change on that.

Are you sure that's the right way to get deps from helm? I don't know enough about it to know how else it could have deps. What does skaffold do?

Copy link
Contributor

@dbentley dbentley left a comment

Choose a reason for hiding this comment

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

It would help me to review the user experience with the docs that describe this.

@jazzdan
Copy link
Contributor Author

jazzdan commented Jan 11, 2019

@dbentley will do after lunch. In the meantime here is a test if it helps.

Copy link
Member

@nicks nicks left a comment

Choose a reason for hiding this comment

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

cool!

// TODO(dmiller) this needs to add all of the files in the directory as dependencies
const helmFunc = `
def helm(path):
return local("helm template " + path)
Copy link
Member

Choose a reason for hiding this comment

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

do we also need a way to mark the path as read, so it registers as a config file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah see TODO, and @dbentley's comment.

r = addBuiltin(r, readFileN, s.skylarkReadFile)

// TODO(dmiller) this really only needs to be done once, on startup
r, err := starlark.ExecFile(thread, "helm.builtin", helmFunc, r)
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 use a dummy thread here? i don't see a good reason to pass in an external thread, do you?

Copy link
Member

Choose a reason for hiding this comment

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

also probably don't need to re-exec this every time we exec a new tiltfile

f.setupHelm()

f.file("Tiltfile", `
yml = helm('helm')
Copy link
Member

Choose a reason for hiding this comment

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

can you also add a test that this works with git_repo('.').path('helm')?

@jazzdan jazzdan force-pushed the dmiller/ch1230/add-helm-primitive-to-tiltfile branch from 3b37186 to f87c12e Compare January 11, 2019 19:56
@jazzdan
Copy link
Contributor Author

jazzdan commented Jan 11, 2019

@dbentley added docs

@@ -18,6 +18,9 @@ k8s_yaml(['foo.yaml', 'bar.yaml'])
# run kustomize to generate yaml
k8s_yaml(kustomize('config_dir'))

# run helm to generate yaml
k8s_yaml(helm('chart_dir'))

# run a custom command to generate yaml
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 move local (the general case) above the specific cases (helm and kustomize), and then maybe a comment like "we also handle common tools to generate yaml"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah totally

@jazzdan jazzdan force-pushed the dmiller/ch1230/add-helm-primitive-to-tiltfile branch from 0890a65 to 472146a Compare January 11, 2019 21:27
@@ -34,9 +34,6 @@ func Load(ctx context.Context, filename string, matching map[string]bool) (manif
tfRoot, _ := filepath.Split(absFilename)

s := newTiltfileState(ctx, absFilename, tfRoot)
defer func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't seem to do anything, but maybe it has something to do with named returns that I'm not understanding?

Copy link
Member

Choose a reason for hiding this comment

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

seems to work ok for me
https://play.golang.org/p/N2e7s_wsABh

can you give a specific example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but we're returning s.configFiles so I don't understand why this is necessary? "It doesn't do anything" was a poor choice of words. It seems superfluous.

Copy link
Member

Choose a reason for hiding this comment

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

if there's an error, i think this function needs to return non-nil? i can write a test for it to double-check the behavior if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhh I think I get it now. Okay I'll add it back.

@jazzdan
Copy link
Contributor Author

jazzdan commented Jan 11, 2019

fyi @nicks I replaced the python implementation with a Go implementation to make tracking dependencies easier. It was a good experiment and we'll need to support things like this in the future for when people write Tilt libraries but I decided it wasn't worth the effort for now.

- run: echo 'export PATH="/usr/local/opt/go@1.10/bin:$PATH"' >> $BASH_ENV
key: homebrew_cache_v8
- run: echo 'export PATH="/usr/local/opt/go@1.11/bin:$PATH"' >> $BASH_ENV
- run: curl --silent --show-error --location --fail --retry 3 --output /tmp/helm.tar.gz https://storage.googleapis.com/kubernetes-helm/helm-v2.12.1-darwin-amd64.tar.gz &&
Copy link
Member

Choose a reason for hiding this comment

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

can you add a comment on why you're not using homebrew here? this seems very brittle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, can do. Basically it looks like homebrew isn't being updated any more, it has a much older verison of helm that actually causes the tests to fail in a minor way (just a capitalization difference).

return nil, fmt.Errorf("Argument 0 (path): %v", err)
}

cmd := fmt.Sprintf("helm template %s", path)
Copy link
Member

Choose a reason for hiding this comment

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

this is going to have major escaping problems because you're passing a thing directly to shell here. can you express this as an argv, i.e., []string{"helm", "template", path}

if err != nil {
return fmt.Errorf("error accessing path (%s): %v", path, err)
}
if !info.IsDir() {
Copy link
Member

Choose a reason for hiding this comment

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

maybe use IsReg() to avoid catching tempfile symlinks and sockets?


deps := []string{}

err = filepath.Walk(localPath.path, func(path string, info os.FileInfo, err error) error {
Copy link
Member

Choose a reason for hiding this comment

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

i feel like our watcher library has much more efficient ways of watching directories so that we don't need to do a Walk. Where is this falling down?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep this is a good point, let's just add the whole directory as a "configFile". Seems to work just fine.

@jazzdan jazzdan force-pushed the dmiller/ch1230/add-helm-primitive-to-tiltfile branch from 3640923 to 3f4b0ae Compare January 11, 2019 23:08
@jazzdan jazzdan merged commit fbf167b into master Jan 14, 2019
@nicks nicks deleted the dmiller/ch1230/add-helm-primitive-to-tiltfile branch March 31, 2021 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants