From 78631591d8b882ec5ebb44f61efd13042cd63d91 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 17 Jun 2019 12:15:12 -0600 Subject: [PATCH] update labeller to include skaffoldVersion function --- pkg/skaffold/runner/labeller.go | 23 +++++++++++++---------- pkg/skaffold/runner/labeller_test.go | 11 ++++------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/skaffold/runner/labeller.go b/pkg/skaffold/runner/labeller.go index 0d983c1bef3..a82e39280c7 100644 --- a/pkg/skaffold/runner/labeller.go +++ b/pkg/skaffold/runner/labeller.go @@ -23,9 +23,9 @@ import ( ) const ( - K8ManagedByLabel = "app.kubernetes.io/managed-by" - UnknownVersion = "unknown" - Empty = "" + K8ManagedByLabelKey = "app.kubernetes.io/managed-by" + UnknownVersion = "unknown" + Empty = "" ) // DefaultLabeller adds K9 style managed-by label @@ -37,21 +37,24 @@ func NewLabeller(verStr string) *DefaultLabeller { if verStr == Empty { verStr = version.Get().Version } + if verStr == Empty { + verStr = UnknownVersion + } return &DefaultLabeller{ version: verStr, } } func (d *DefaultLabeller) Labels() map[string]string { - version := d.version - if version == Empty { - version = UnknownVersion - } return map[string]string{ - K8ManagedByLabel: fmt.Sprintf("skaffold-%s", version), + K8ManagedByLabelKey: d.skaffoldVersion(), } } -func (d *DefaultLabeller) K8sMangedByLabel() string { - return fmt.Sprintf("%s=skaffold-%s", K8ManagedByLabel, d.version) +func (d *DefaultLabeller) K8sManagedByLabelKeyValueString() string { + return fmt.Sprintf("%s=%s", K8ManagedByLabelKey, d.skaffoldVersion()) +} + +func (d *DefaultLabeller) skaffoldVersion() string { + return fmt.Sprintf("skaffold-%s", d.version) } diff --git a/pkg/skaffold/runner/labeller_test.go b/pkg/skaffold/runner/labeller_test.go index 0d1283cf658..262e689d60b 100644 --- a/pkg/skaffold/runner/labeller_test.go +++ b/pkg/skaffold/runner/labeller_test.go @@ -17,7 +17,6 @@ limitations under the License. package runner import ( - "fmt" "testing" "github.com/GoogleContainerTools/skaffold/testutil" @@ -36,14 +35,12 @@ func TestDefaultLabeller(t *testing.T) { }, { description: "empty version should add postfix unknown", - expected: fmt.Sprintf("skaffold-unknown"), + expected: "skaffold-unknown", }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - l := &DefaultLabeller{ - version: test.version, - } + l := NewLabeller(test.version) labels := l.Labels() expected := map[string]string{"app.kubernetes.io/managed-by": test.expected} @@ -52,12 +49,12 @@ func TestDefaultLabeller(t *testing.T) { } } -func TestK8sMangedByLabel(t *testing.T) { +func TestK8sManagedByLabelKeyValueString(t *testing.T) { defaultLabeller := &DefaultLabeller{ version: "version", } expected := "app.kubernetes.io/managed-by=skaffold-version" - actual := defaultLabeller.K8sMangedByLabel() + actual := defaultLabeller.K8sManagedByLabelKeyValueString() if actual != expected { t.Fatalf("actual label not equal to expected label. Actual: \n %s \n Expected: \n %s", actual, expected) }