Repository navigation
feat(helm): Add --node-selectors, --set and --output flags to helm init - #2557
Conversation
| func parseNodeSelectors(labels string) map[string]string { | ||
| kv := strings.Split(labels, ",") | ||
| nodeSelectors := map[string]string{} | ||
| nodeSelectors["beta.kubernetes.io/os"] = "linux" |
There was a problem hiding this comment.
This looks like a sensible way to do it. Have it default to linux and if the user specifies another one, it will be overwritten.
|
Waiting to label until this is out of WIP. Ping one of us @jascott1 when this is ready for review |
|
Reviewed 2 of 4 files at r3. cmd/helm/init.go, line 124 at r3 (raw file):
How about "on which node tiller lands?" cmd/helm/init.go, line 124 at r3 (raw file):
The name implies that the flag accepts several selectors. How does one separate each selector? What's the syntax? cmd/helm/init.go, line 125 at r3 (raw file):
Instead of using a string here for the flag, consider defining a new type that implements type outputFormat string
func (f outputFormat) String() string {
return string(f)
}
func (outputFormat) Type() string {
return "format"
}
const (
fmtJSON outputFormat = "json"
fmtYAML = "yaml"
)
func (f *outputFormat) Set(s string) error {
for _, of := range []outputFormat{fmtJSON, fmtYAML} {
if s == string(of) {
*f = of
return nil
}
}
return fmt.Errorf("unknown output format %q", s)
}With that, you can use cmd/helm/init.go, line 192 at r3 (raw file):
Remove blank line. cmd/helm/init.go, line 204 at r3 (raw file):
It looks like you could avoid this conversion to a string by using cmd/helm/installer/options.go, line 76 at r3 (raw file):
I noticed that here we capitalize the word "Tiller," but in the flag documentation we write in lowercase as "tiller." I think it should be capitalized throughout. cmd/helm/installer/options.go, line 79 at r3 (raw file):
Capitalize the format as "JSON." cmd/helm/installer/options.go, line 108 at r3 (raw file):
Do we expect the map to contain the same number of entries as m := make(map[string]interface{}, len(opts.Values))cmd/helm/installer/options.go, line 110 at r3 (raw file):
Instead: if err := strvals.ParseInto(skv,m); err != nil {
return nil, err
}Comments from Reviewable |
|
Thanks @seh. Im still working on it and will check out your suggestions asap. |
|
All flags are functioning now including |
|
Review status: 1 of 5 files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. cmd/helm/init.go, line 124 at r3 (raw file): Previously, seh (Steven E. Harris) wrote…
technically I changed it to "node on which tiller is installed" cmd/helm/init.go, line 125 at r3 (raw file): Previously, seh (Steven E. Harris) wrote…
Will check into this next commit cmd/helm/init.go, line 204 at r3 (raw file): Previously, seh (Steven E. Harris) wrote…
Will check into this next commit cmd/helm/installer/options.go, line 76 at r3 (raw file): Previously, seh (Steven E. Harris) wrote…
Capitalized Tiller in options.go cmd/helm/installer/options.go, line 108 at r3 (raw file): Previously, seh (Steven E. Harris) wrote…
No this is dynamic Comments from Reviewable |
|
Review status: 0 of 5 files reviewed at latest revision, 9 unresolved discussions. cmd/helm/init.go, line 125 at r3 (raw file): Previously, jascott1 (Justin Scott) wrote…
I like it and concede its more proper but im not sure its worth it for simple string check. Are we doing this for consistency for flags of this type? Comments from Reviewable |
|
Review status: 0 of 5 files reviewed at latest revision, 9 unresolved discussions. cmd/helm/init.go, line 204 at r3 (raw file): Previously, jascott1 (Justin Scott) wrote…
nice! looks way cooler taboot. Comments from Reviewable |
|
Reviewed 2 of 3 files at r5. cmd/helm/init.go, line 125 at r3 (raw file): Previously, jascott1 (Justin Scott) wrote…
The idea is that cobra can then detect the mismatch as a flag parsing failure, and stop the program at that stage, in the same way that if you asked for an integer and got "pdq" as a command-line flag value, cobra would reject that value before you ever saw it. It gets more worth the investment when you plan to use the flag type many times. Here, we only have one use at the moment, but maybe there are other places in Helm that will allow the user to specify this same kind of output format. cmd/helm/init.go, line 204 at r3 (raw file): Previously, jascott1 (Justin Scott) wrote…
It occurred to after writing last night that the original code winds up copying the JSON bytes three times: once to convert the byte vector to a string, once to concatenate the JSON string to the metadata prefix, and once more to write the combined string to the destination. We can't eliminate the last transfer, but the first two are unnecessary. cmd/helm/init.go, line 205 at r5 (raw file):
I was expecting a statement like this: _, err := i.out.Write(jsonb[1:])
return errcmd/helm/installer/options.go, line 47 at r5 (raw file):
It's not your focus here, but I'll note that most of these field documentation lines are punctuated, but some are not (such as the "Output" one you added below. Consider unifying them. Comments from Reviewable |
996dc3c to
f7348e0
Compare
|
Review status: 0 of 6 files reviewed at latest revision, 3 unresolved discussions. cmd/helm/init.go, line 125 at r3 (raw file): Previously, seh (Steven E. Harris) wrote…
Thanks for the explanation. I implemented your changes. cmd/helm/init.go, line 204 at r3 (raw file): Previously, seh (Steven E. Harris) wrote…
Please take a look at the new revision and let me know. I also added json.Indent. cmd/helm/init.go, line 205 at r5 (raw file): Previously, seh (Steven E. Harris) wrote…
Its been refactored in a different way. Please let me know what you think. cmd/helm/installer/options.go, line 47 at r5 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. Comments from Reviewable |
|
|
||
| // parseNodeSelectors takes a comma delimited list of key=values pairs and returns a map | ||
| func parseNodeSelectors(labels string) map[string]string { | ||
| func parseNodeSelectors(labels string, m map[string]string) map[string]string { |
There was a problem hiding this comment.
-
This function got strange with this change. It now mutates a supplied map in place, and returns that same map, though the signature can't promise that the returned map is the same as the map supplied as an argument. A caller might wonder whether he needs the return value. A caller might wonder whether his input argument is safe against mutation.
What if you had
parseNodeSelectorscreate and return a fresh map, eliminating this confusion, and then add your "os=linux" selector into the map returned from the call ingenerateDeployment?
There was a problem hiding this comment.
@seh User needs to be able to override that default selector. Are you suggesting that anything that needs to be mutated needs to be passed as a pointer?
There was a problem hiding this comment.
No, I wasn't suggesting that. If you want that function to mutate in place, then don't return a map as well. That eliminates the confusion. With that signature change, I'd consider renaming it to parseNodeSelectorsInto.
There was a problem hiding this comment.
By the way, maps are (effectively) pointers. I recalled that article too late to include it earlier.
There was a problem hiding this comment.
I renamed and updated to not return map. Thanks for the help!
|
Review status: 0 of 6 files reviewed at latest revision, 5 unresolved discussions. cmd/helm/init.go, line 202 at r6 (raw file):
Unfortunately, that conversion to cmd/helm/init.go, line 206 at r6 (raw file):
It would be better to use Here's a Playground sample that shows avoiding a few lurking copies. It's a shame that there's no Comments from Reviewable |
|
Review status: 0 of 6 files reviewed at latest revision, 4 unresolved discussions. cmd/helm/init.go, line 206 at r6 (raw file): Previously, seh (Steven E. Harris) wrote…
I altered it with your suggestions, thanks. cmd/helm/installer/install.go, line 132 at r6 (raw file): Previously, jascott1 (Justin Scott) wrote…
Done. Comments from Reviewable |
|
Review status: 0 of 6 files reviewed at latest revision, 3 unresolved discussions. cmd/helm/init.go, line 209 at r7 (raw file):
cmd/helm/installer/install.go, line 139 at r7 (raw file):
Error messages should not used capitalized first words so that they can be concatenated more easily.
Also, consider using the "%q" verb to quote the offending label string. docs/helm/helm_init.md, line 41 at r7 (raw file):
I think I noted this elsewhere, but our flags are inconsistent in capitalizing the word "tiller." Note that "--set" capitalizes it, but "--canary," "--client-only," "--net-host," "--node-selectors," "--output," "--tiller-image," "--tiller-tls," "--tiller-tls-cert," "--tiller-tls-key," "--tiller-tls-verify," and "--upgrade" do not. Oh, wait, there are more: "--host," and "--tiller-namespace." Comments from Reviewable |
|
Review status: 0 of 6 files reviewed at latest revision, 3 unresolved discussions. cmd/helm/init.go, line 209 at r7 (raw file): Previously, seh (Steven E. Harris) wrote…
Good call. cmd/helm/installer/install.go, line 139 at r7 (raw file): Previously, seh (Steven E. Harris) wrote…
Good stuff. Thanks! docs/helm/helm_init.md, line 41 at r7 (raw file): Previously, seh (Steven E. Harris) wrote…
I will defer that to another atomic commit for that purpose unless you think its important now. Comments from Reviewable |
|
Review status: 0 of 6 files reviewed at latest revision, 2 unresolved discussions. docs/helm/helm_init.md, line 41 at r7 (raw file): Previously, jascott1 (Justin Scott) wrote…
I started another PR for this. I noticed that "tiller" in many if not most of the other commands' usage strings are not capitalized. Im planning to gauge merit based on feedback from #2601 Comments from Reviewable |
|
Reviewed 1 of 3 files at r4, 3 of 5 files at r6, 2 of 2 files at r8. cmd/helm/init.go, line 196 at r8 (raw file):
Consider using the alternate cmd/helm/init_test.go, line 323 at r8 (raw file):
cmd/helm/init_test.go, line 324 at r8 (raw file):
cmd/helm/init_test.go, line 355 at r8 (raw file):
Remove blank line. cmd/helm/installer/install.go, line 115 at r8 (raw file):
I suspect that we can't change this signature at this point because this function is exported, but if you returned a func deploymentManifest(opts *Options) ([]byte, error) {
obj, err := deployment(opts)
if err != nil {
return "", err
}
buf, err := yaml.Marshal(obj)
return buf, err
}
func DeploymentManifest(opts *Options) (string, error) {
b, err := deploymentManifest(opts)
return string(b), err
}If you're concerned that func DeploymentManifest(opts *Options) (string, error) {
b, err := deploymentManifest(opts)
if err != nil {
return "", err
}
return string(b), nil
}cmd/helm/installer/install_test.go, line 447 at r8 (raw file):
You could use subtests here ( cmd/helm/installer/install_test.go, line 457 at r8 (raw file):
Since the sentence is punctuated, capitalize the first word. cmd/helm/installer/install_test.go, line 457 at r8 (raw file):
s/tls/TLS/ cmd/helm/installer/install_test.go, line 457 at r8 (raw file):
s/reflect/reflects/ or s/variable/variables/, depending on whether there is more than one variable. Comments from Reviewable |
|
Review status: 4 of 6 files reviewed at latest revision, 9 unresolved discussions. cmd/helm/init.go, line 196 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Deferred this as noted in other comment. cmd/helm/init_test.go, line 323 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/init_test.go, line 324 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/init_test.go, line 355 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/installer/install.go, line 115 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Since this only affects the one shot cmd/helm/installer/install_test.go, line 447 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
In this case I prefer following existing convention in the test file. cmd/helm/installer/install_test.go, line 457 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Removed line as it was stray from copy of existing test. Thanks for noticing it. cmd/helm/installer/install_test.go, line 457 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Removed comment. cmd/helm/installer/install_test.go, line 457 at r8 (raw file): Previously, seh (Steven E. Harris) wrote…
Removed stray comment. Comments from Reviewable |
|
Thank you for your persistence. You suffered through me learning how to use Reviewable, which is quite complicated, but I think provides for good accountability through these iterative reviews.
Reviewed 2 of 2 files at r9. Comments from Reviewable |
|
@seh Thanks so much for all the insights! Its also my first time really working with Reviewable as well and so far I like it. |
|
I fixed them. Thanks for the excellent reviews as always! Review status: 3 of 6 files reviewed at latest revision, 9 unresolved discussions. cmd/helm/installer/install.go, line 262 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/installer/install_test.go, line 424 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Removed the comment as we removed the default node selector entirely. cmd/helm/installer/install_test.go, line 457 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/installer/install_test.go, line 461 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Sure why not ;) cmd/helm/installer/install_test.go, line 521 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/installer/options.go, line 76 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/installer/options.go, line 79 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. cmd/helm/installer/options.go, line 82 at r14 (raw file): Previously, seh (Steven E. Harris) wrote…
Done. Comments from Reviewable |
|
Reviewed 3 of 3 files at r15. Comments from Reviewable |
|
Woot! Review status: all files reviewed at latest revision, 1 unresolved discussion. Comments from Reviewable |
|
@technosophos can we get a milestone for this one? |
|
@jascott1 I'm going to put this in 2.7 for now |
|
Would be great if the documentation for this would include an example of how to set a node affinity, and how to set a toleration. 👍 |
|
@jascott1 What is the status on this one? Will it be ready for 2.7? |
|
@thomastaylor312 I will rebase today and should be good to go. I will also add some examples @egeland |
thomastaylor312
left a comment
There was a problem hiding this comment.
One super tiny constant missing a type and an optional nit then this is good to go
| return err | ||
| } | ||
| if _, err := fmt.Fprintln(w, "kind:", kind); err != nil { | ||
| const tm = `{"apiVersion":"extensions/v1beta1","kind":"Deployment",` |
There was a problem hiding this comment.
Nit: This should probably be moved out from being declared in a case statement or make it not a const. It feels a little out of place there since it is a constant getting redeclared each time
There was a problem hiding this comment.
Thanks for catch! Fixed.
|
|
||
| const ( | ||
| fmtJSON OutputFormat = "json" | ||
| fmtYAML = "yaml" |
There was a problem hiding this comment.
I think this needs to have a type of OutputFormat as well
There was a problem hiding this comment.
Not sure what I was thinking there either. Fixed.
|
Had an idea for this. @jascott1 plz ping me tomorrow about it. |
107306c to
6abe222
Compare
|
@thomastaylor312 I changed the |
This feature enables users to specify more control over where Tiller pod lands by allowing "node-selectors" to be specified. Alternatively, the "--output" flag will skip install and dump Tiller's raw Deployment manifest to stdout so user may alter it as they see fit (probably with a JSON manipulation tool like jq). Closes helm#2299
|
Approved pending CI |
This implements #2299.