Skip to content

Commit

Permalink
Add version as unknown if version.Get().Version is empty (#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 authored and balopat committed May 9, 2019
1 parent fdc0d37 commit 3e21e73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 8 additions & 2 deletions pkg/skaffold/runner/labeller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

const (
K8ManagedByLabel = "app.kubernetes.io/managed-by"
UnknownVersion = "unknown"
Empty = ""
)

// DefaultLabeller adds K9 style managed-by label
Expand All @@ -32,7 +34,7 @@ type DefaultLabeller struct {
}

func NewLabeller(verStr string) *DefaultLabeller {
if verStr == "" {
if verStr == Empty {
verStr = version.Get().Version
}
return &DefaultLabeller{
Expand All @@ -41,7 +43,11 @@ func NewLabeller(verStr string) *DefaultLabeller {
}

func (d *DefaultLabeller) Labels() map[string]string {
version := d.version
if version == Empty {
version = UnknownVersion
}
return map[string]string{
K8ManagedByLabel: fmt.Sprintf("skaffold-%s", d.version),
K8ManagedByLabel: fmt.Sprintf("skaffold-%s", version),
}
}
7 changes: 3 additions & 4 deletions pkg/skaffold/runner/labeller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import (
"fmt"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/version"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestDEfaultLabeller(t *testing.T) {
func TestDefaultLabeller(t *testing.T) {
var tests = []struct {
description string
version string
Expand All @@ -36,8 +35,8 @@ func TestDEfaultLabeller(t *testing.T) {
expected: "skaffold-1.0",
},
{
description: "no version",
expected: fmt.Sprintf("skaffold-%s", version.Get().Version),
description: "empty version should add postfix unknown",
expected: fmt.Sprintf("skaffold-unknown"),
},
}

Expand Down

0 comments on commit 3e21e73

Please sign in to comment.