Skip to content

Commit

Permalink
Adding warning message for non-supported version of kind config file. (
Browse files Browse the repository at this point in the history
…#232)

Signed-off-by: Ken Sipe <[email protected]>
  • Loading branch information
kensipe authored Oct 19, 2020
1 parent f052443 commit d273e14
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (h *Harness) RunKIND() (*rest.Config, error) {
if h.TestSuite.KINDConfig != "" {
h.T.Logf("Loading KIND config from %s", h.TestSuite.KINDConfig)
var err error
kindCfg, err = loadKindConfig(h.TestSuite.KINDConfig)
kindCfg, err = h.loadKindConfig(h.TestSuite.KINDConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -583,7 +583,7 @@ func (h *Harness) Report() {
}
}

func loadKindConfig(path string) (*kindConfig.Cluster, error) {
func (h *Harness) loadKindConfig(path string) (*kindConfig.Cluster, error) {
raw, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
Expand All @@ -597,6 +597,8 @@ func loadKindConfig(path string) (*kindConfig.Cluster, error) {
if err := decoder.Decode(cluster); err != nil {
return nil, err
}

if !IsMinVersion(cluster.APIVersion) {
h.T.Logf("Warning: %q in %s is not a supported version.\n", cluster.APIVersion, path)
}
return cluster, nil
}
8 changes: 8 additions & 0 deletions pkg/test/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"k8s.io/apimachinery/pkg/version"
"sigs.k8s.io/kind/pkg/apis/config/v1alpha4"
"sigs.k8s.io/kind/pkg/cluster"
"sigs.k8s.io/kind/pkg/cluster/nodes"
Expand Down Expand Up @@ -106,3 +107,10 @@ func loadContainer(docker testutils.DockerClient, node nodes.Node, container str

return nil
}

// IsMinVersion checks if pass ver is the min required kind version
func IsMinVersion(ver string) bool {
minVersion := "kind.sigs.k8s.io/v1alpha4"
comp := version.CompareKubeAwareVersionStrings(minVersion, ver)
return comp != -1
}
45 changes: 45 additions & 0 deletions pkg/test/kind_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package test

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCheckVersion(t *testing.T) {

tests := []struct {
name string
ver string
expected bool
}{
{
name: `current version`,
ver: "kind.sigs.k8s.io/v1alpha4",
expected: true,
},
{
name: `early version`,
ver: "kind.sigs.k8s.io/v1alpha3",
expected: false,
},
{
name: `newer version`,
ver: "kind.sigs.k8s.io/v1beta1",
expected: true,
},
{
name: `wrong group`,
ver: "foo/v1alpha4",
expected: false,
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
result := IsMinVersion(tt.ver)
assert.Equal(t, tt.expected, result)
})
}
}

0 comments on commit d273e14

Please sign in to comment.