Skip to content

Commit

Permalink
Verify kubernetesVersion when run 'package verify'.
Browse files Browse the repository at this point in the history
  • Loading branch information
harryge00 committed Jan 21, 2020
1 parent e737ccd commit 542eb03
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/kudoctl/cmd/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/verifier"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/verifier/task"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/verifier/template"
"github.com/kudobuilder/kudo/pkg/version"
)

var verifiers = []verifier.PackageVerifier{
DuplicateVerifier{},
InvalidCharVerifier{";,"},
K8sVersionVerifier{},
task.ReferenceVerifier{},
template.ParametersVerifier{},
template.ReferenceVerifier{},
Expand Down Expand Up @@ -61,3 +63,21 @@ func (v InvalidCharVerifier) Verify(pf *packages.Files) verifier.Result {

return res
}

// K8sVersionVerifier verifies the kubernetesVersion of operator.yaml
type K8sVersionVerifier struct{}

func (K8sVersionVerifier) Verify(pf *packages.Files) verifier.Result {
res := verifier.NewResult()
if pf.Operator == nil {
res.AddErrors("Operator not defined.")
return res
}
_, err := version.New(pf.Operator.KubernetesVersion)
if err != nil {
res.AddErrors(fmt.Sprintf("Unable to parse operators kubernetes version: %v", err))
return res
}

return res
}
33 changes: 33 additions & 0 deletions pkg/kudoctl/cmd/verify/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,36 @@ func packageFileForParams(params []v1beta1.Parameter) *packages.Files {
Params: &p,
}
}

func TestK8sVersionVerifier(t *testing.T) {
tests := []struct {
name string
operatorFile *packages.OperatorFile
expectedWarnings []string
expectedErrors []string
}{
{"no warning or error", &packages.OperatorFile{
APIVersion: packages.APIVersion,
Name: "kafka",
KubernetesVersion: "1.15",
}, []string{}, []string{}},
{"no warning or error", &packages.OperatorFile{
APIVersion: packages.APIVersion,
Name: "kafka",
KubernetesVersion: "",
}, []string{}, []string{"Unable to parse operators kubernetes version: Invalid Semantic Version"}},
}

verifier := K8sVersionVerifier{}
for _, tt := range tests {
res := verifier.Verify(packageFileForOperator(tt.operatorFile))
assert.Equal(t, tt.expectedWarnings, res.Warnings, tt.name)
assert.Equal(t, tt.expectedErrors, res.Errors, tt.name)
}
}

func packageFileForOperator(op *packages.OperatorFile) *packages.Files {
return &packages.Files{
Operator: op,
}
}

0 comments on commit 542eb03

Please sign in to comment.