adding component selection for diff#592
Conversation
Pull Request Test Coverage Report for Build 972
💛 - Coveralls |
9dd8d4a to
5ce5696
Compare
Support: * `.` * `dot.name` * `__leading` In support of ksonnet/ksonnet#592 Signed-off-by: bryanl <bryanliles@gmail.com>
Support: * `.` * `dot.name` * `__leading` * `9p` In support of ksonnet/ksonnet#592 Signed-off-by: bryanl <bryanliles@gmail.com>
Support: * `.` * `dot.name` * `__leading` * `9p` In support of ksonnet/ksonnet#592 Signed-off-by: bryanl <bryanliles@gmail.com>
70ea4c9 to
1628276
Compare
This change adds components for diffs. You can now run: ``` ks diff local:default remote:default -c <component name> ``` To diff a component in a module, specify the component with a module name. e.g component (for a module in the root component) or nested.component (for a module in nested/ under components) In addition, module support throughout the ks was updated * Modules allow ksonnet users to separate their configurations under components. * Modules are dot separated paths that correlate to their location on the file system. e.g module a is in /app/components/a * Modules can be deeply nested. e.g components in /app/components/nested/deeply would be in module nested.deeply * Modules are now added as a label to kubernetes resources in `ksonnet.io/component`. This will allow the user to determine which component created a resource Signed-off-by: bryanl bryanliles@gmail.com
1628276 to
1935184
Compare
| } | ||
| case strings.HasPrefix(t, "-"): | ||
| diffRemoveColor.Fprintln(&buf, t) | ||
| if err != nil { |
There was a problem hiding this comment.
line above this doesn't do _, err = like previous case - missed this?
| componentParams := params.Params{} | ||
|
|
||
| var moduleName string | ||
| switch i.module { |
There was a problem hiding this comment.
why keep this a switch when there's only one case? is a default-only switch a common golang idiom?
There was a problem hiding this comment.
- Because 0 values are useful in Go. It's the same thing as:
var moduleName
if i.module != "" && i.module != "/" {
moduleName = i.module
}- It's not a default only switch. There is a case statement in there too.
Signed-off-by: bryanl <bryanliles@gmail.com>
| func bindPrototypeParams(p *prototype.Prototype) *pflag.FlagSet { | ||
| fs := pflag.NewFlagSet("preview", pflag.ContinueOnError) | ||
|
|
||
| fs.String("module", "", "Component module") |
There was a problem hiding this comment.
How do we avoid collisions with prototype parameters?
There was a problem hiding this comment.
We could detect the collision and alert the user.
| return errors.Errorf("Command has too many arguments (takes a prototype name and a component name)") | ||
| } | ||
|
|
||
| moduleName, err := flags.GetString("module") |
| Latest() | ||
|
|
||
| if len(components) > 0 { | ||
| selector := fmt.Sprintf("%s in (%s)", clustermetadata.LabelComponent, strings.Join(components, ",")) |
There was a problem hiding this comment.
We should consider adding escaping/validation to the components if they can break the selector.
There was a problem hiding this comment.
Will this hold up this PR?
There was a problem hiding this comment.
Doesn't have to. I can open an issue to harden this.
| objects := make([]*unstructured.Unstructured, len(apiObjects)) | ||
| for i := range apiObjects { | ||
| obj := apiObjects[i] | ||
| objects[i] = obj.DeepCopy() |
There was a problem hiding this comment.
Do we need a deep copy just for sorting below?
Could simplify to:
objects := make([]*unstructured.Unstructured, len(apiObjects))
copy(objects, apiObjects)
sortByKind(objects)
| o1 := apiObjects[i] | ||
| o2 := apiObjects[j] | ||
|
|
||
| if o1.GroupVersionKind().Kind < o2.GroupVersionKind().Kind { |
There was a problem hiding this comment.
We could call GroupVersionKind() once per object.
| @@ -167,7 +167,7 @@ func isValidName(name string) bool { | |||
| } | |||
|
|
|||
| func namespaceComponent(name string) (string, string) { | |||
| } | ||
|
|
||
| if j.module == "/" { | ||
| if j.module == "/" || j.module == "" { |
There was a problem hiding this comment.
When is a root module "/" vs ""?
There was a problem hiding this comment.
Is / correct here, or should it be filepath.Separator?
|
|
||
| "github.com/ksonnet/ksonnet/pkg/util/k8s" | ||
| "github.com/ksonnet/ksonnet/pkg/util/strings" | ||
| gostrings "strings" |
There was a problem hiding this comment.
I'm going to say stdlib should win the contest of which package doesn't get aliased.
There was a problem hiding this comment.
Why? I don't think there is a hard and fast rule.
There was a problem hiding this comment.
General familiarity and principal of least surprise. But this is a matter of preference, and only a suggestion :)
shomron
left a comment
There was a problem hiding this comment.
No blockers. Thanks for putting this together!
This change adds components for diffs. You can now run:
To diff a component in a module, specify the component with a module name. e.g component (for a module in the root component) or nested.component (for a module in nested/ under components)
In addition, module support throughout the ks was updated
ksonnet.io/component. This will allow the user to determine which component created a resourceFixes #581
Signed-off-by: bryanl bryanliles@gmail.com