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

Add K8sManagedBy function to labeller #2270

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/skaffold/runner/labeller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ func (d *DefaultLabeller) Labels() map[string]string {
K8ManagedByLabel: fmt.Sprintf("skaffold-%s", version),
}
}

func (d *DefaultLabeller) K8sMangedByLabel() string {
return fmt.Sprintf("%s=skaffold-%s", K8ManagedByLabel, d.version)
Copy link
Contributor

Choose a reason for hiding this comment

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

This took me a while to understand - can we rename/refactor some things to make it clearer?

  • K8ManagedByLabel -> K8sManagedByLabelKey
  • K8sMangedByLabel() -> K8sManagedByLabelKeyValueString()
  • fmt.Sprintf("skaffold-%s", version) -> skaffoldVersion() and use that in K8sManagedByLabelKeyValueString()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for sure, done!

}
11 changes: 11 additions & 0 deletions pkg/skaffold/runner/labeller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ func TestDefaultLabeller(t *testing.T) {
})
}
}

func TestK8sMangedByLabel(t *testing.T) {
defaultLabeller := &DefaultLabeller{
version: "version",
}
expected := "app.kubernetes.io/managed-by=skaffold-version"
actual := defaultLabeller.K8sMangedByLabel()
if actual != expected {
t.Fatalf("actual label not equal to expected label. Actual: \n %s \n Expected: \n %s", actual, expected)
}
}
2 changes: 2 additions & 0 deletions pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type SkaffoldRunner struct {
cache *cache.Cache
runCtx *runcontext.RunContext
labellers []deploy.Labeller
defaultLabeller *DefaultLabeller
builds []build.Artifact
hasBuilt bool
hasDeployed bool
Expand Down Expand Up @@ -118,6 +119,7 @@ func NewForConfig(opts *config.SkaffoldOptions, cfg *latest.SkaffoldConfig) (*Sk
Syncer: kubectl.NewSyncer(runCtx.Namespaces),
Watcher: watch.NewWatcher(trigger),
labellers: labellers,
defaultLabeller: defaultLabeller,
imageList: kubernetes.NewImageList(),
cache: artifactCache,
runCtx: runCtx,
Expand Down