Skip to content

Commit

Permalink
fix validation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw7 committed Oct 18, 2024
1 parent 38dc6b7 commit cdca128
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 6 additions & 3 deletions pkg/image/validation/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ func validateNetwork(k8s *image.Kubernetes) []FailedValidation {
var failures []FailedValidation

if k8s.Network.APIVIP == "" {
failures = append(failures, FailedValidation{
UserMessage: "The 'apiVIP' field is required in the 'network' section when defining entries under 'nodes'.",
})
if len(k8s.Nodes) >= 1 {
failures = append(failures, FailedValidation{
UserMessage: "The 'apiVIP' field is required in the 'network' section when defining entries under 'nodes'.",
})
return failures
}

return failures
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/image/validation/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,22 @@ func TestValidateNetwork(t *testing.T) {
K8s image.Kubernetes
ExpectedFailedMessages []string
}{
`no network defined`: {
`no network defined, no nodes defined`: {
K8s: image.Kubernetes{
Network: image.Network{},
},
},
`no network defined, nodes defined`: {
K8s: image.Kubernetes{
Network: image.Network{},
Nodes: []image.Node{
{
Hostname: "node1",
Type: "server",
Initialiser: false,
},
},
},
ExpectedFailedMessages: []string{
"The 'apiVIP' field is required in the 'network' section when defining entries under 'nodes'.",
},
Expand Down

0 comments on commit cdca128

Please sign in to comment.