Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

adding component selection for diff#592

Merged
bryanl merged 2 commits intoksonnet:masterfrom
bryanl:581-diff-component
Jun 12, 2018
Merged

adding component selection for diff#592
bryanl merged 2 commits intoksonnet:masterfrom
bryanl:581-diff-component

Conversation

@bryanl
Copy link
Member

@bryanl bryanl commented Jun 7, 2018

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

Fixes #581

Signed-off-by: bryanl bryanliles@gmail.com

@bryanl bryanl requested review from shomron and underrun June 7, 2018 00:54
@coveralls
Copy link

coveralls commented Jun 7, 2018

Pull Request Test Coverage Report for Build 972

  • 166 of 214 (77.57%) changed or added relevant lines in 15 files are covered.
  • 12 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.08%) to 69.838%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/component/jsonnet.go 2 3 66.67%
pkg/component/manager.go 4 5 80.0%
pkg/component/yaml.go 2 3 66.67%
pkg/component/locator.go 4 5 80.0%
pkg/cluster/show.go 26 28 92.86%
pkg/component/create.go 10 12 83.33%
pkg/actions/import.go 3 5 60.0%
pkg/diff/diff.go 15 18 83.33%
pkg/actions/diff.go 6 10 60.0%
pkg/component/module.go 47 51 92.16%
Files with Coverage Reduction New Missed Lines %
pkg/component/create.go 12 64.1%
Totals Coverage Status
Change from base Build 961: 0.08%
Covered Lines: 9720
Relevant Lines: 13918

💛 - Coveralls

@bryanl bryanl force-pushed the 581-diff-component branch from 9dd8d4a to 5ce5696 Compare June 7, 2018 12:00
bryanl added a commit to bryanl/ksonnet-lib that referenced this pull request Jun 7, 2018
Support:

* `.`
* `dot.name`
* `__leading`

In support of ksonnet/ksonnet#592

Signed-off-by: bryanl <bryanliles@gmail.com>
bryanl added a commit to bryanl/ksonnet-lib that referenced this pull request Jun 7, 2018
Support:

* `.`
* `dot.name`
* `__leading`
* `9p`

In support of ksonnet/ksonnet#592

Signed-off-by: bryanl <bryanliles@gmail.com>
bryanl added a commit to ksonnet/ksonnet-lib that referenced this pull request Jun 7, 2018
Support:

* `.`
* `dot.name`
* `__leading`
* `9p`

In support of ksonnet/ksonnet#592

Signed-off-by: bryanl <bryanliles@gmail.com>
@bryanl bryanl force-pushed the 581-diff-component branch 2 times, most recently from 70ea4c9 to 1628276 Compare June 8, 2018 11:43
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
@bryanl bryanl force-pushed the 581-diff-component branch from 1628276 to 1935184 Compare June 8, 2018 17:41
@bryanl bryanl requested a review from a team June 8, 2018 21:50
}
case strings.HasPrefix(t, "-"):
diffRemoveColor.Fprintln(&buf, t)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

line above this doesn't do _, err = like previous case - missed this?

componentParams := params.Params{}

var moduleName string
switch i.module {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why keep this a switch when there's only one case? is a default-only switch a common golang idiom?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. Because 0 values are useful in Go. It's the same thing as:
var moduleName
if i.module != "" && i.module != "/" {
  moduleName = i.module
}
  1. 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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

How do we avoid collisions with prototype parameters?

Copy link
Collaborator

Choose a reason for hiding this comment

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

flagModule?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this possible?

Copy link
Collaborator

Choose a reason for hiding this comment

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

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

flagModule?

Latest()

if len(components) > 0 {
selector := fmt.Sprintf("%s in (%s)", clustermetadata.LabelComponent, strings.Join(components, ","))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should consider adding escaping/validation to the components if they can break the selector.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will this hold up this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could call GroupVersionKind() once per object.

@@ -167,7 +167,7 @@ func isValidName(name string) bool {
}

func namespaceComponent(name string) (string, string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comments appreciated :)

}

if j.module == "/" {
if j.module == "/" || j.module == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

When is a root module "/" vs ""?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is / correct here, or should it be filepath.Separator?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it is /


"github.com/ksonnet/ksonnet/pkg/util/k8s"
"github.com/ksonnet/ksonnet/pkg/util/strings"
gostrings "strings"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm going to say stdlib should win the contest of which package doesn't get aliased.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? I don't think there is a hard and fast rule.

Copy link
Collaborator

Choose a reason for hiding this comment

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

General familiarity and principal of least surprise. But this is a matter of preference, and only a suggestion :)

Copy link
Collaborator

@shomron shomron left a comment

Choose a reason for hiding this comment

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

No blockers. Thanks for putting this together!

@bryanl bryanl merged commit 4a2c2cd into ksonnet:master Jun 12, 2018
@bryanl bryanl deleted the 581-diff-component branch June 12, 2018 00:41
@redbaron
Copy link
Contributor

@bryanl , this change doesn't take into account that not all resources can have .metadata.labels, for instance List do not have it, opened #891

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants