Skip to content

Commit

Permalink
update labeller to include skaffoldVersion function
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Jun 17, 2019
1 parent 622fdd5 commit 7863159
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
23 changes: 13 additions & 10 deletions pkg/skaffold/runner/labeller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
11 changes: 4 additions & 7 deletions pkg/skaffold/runner/labeller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package runner

import (
"fmt"
"testing"

"github.com/GoogleContainerTools/skaffold/testutil"
Expand All @@ -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}
Expand All @@ -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)
}
Expand Down

0 comments on commit 7863159

Please sign in to comment.