Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify kubernetesVersion when run 'package verify'. #1296

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}