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

[release-v0.18] fix: fix wrong parsing of vm.spec.template.spec.domain.memory.guest in validator #680

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
9 changes: 8 additions & 1 deletion internal/template-validator/validation/path/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ func (r *Results) AsInt64() ([]int64, error) {
continue
}
}
return nil, fmt.Errorf("mismatching type: %v, not int or resource.Quantity", res[j].Type().Name())
if quantityObj, ok := obj.(*resource.Quantity); ok {
v, ok := quantityObj.AsInt64()
if ok {
ret = append(ret, v)
continue
}
}
return nil, fmt.Errorf("mismatching type: %v, not int or resource.Quantity", res[j].Type())
}
}
return ret, nil
Expand Down
16 changes: 16 additions & 0 deletions internal/template-validator/validation/path/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ var _ = Describe("Path", func() {
Expect(vals[0]).To(BeNumerically(">", 1024))
})

It("Should provide integer result for quantity pointer object", func() {
s := "jsonpath::.spec.domain.memory.guest"
p, err := New(s)
Expect(p).To(Not(BeNil()))
Expect(err).ToNot(HaveOccurred())

results, err := p.Find(vmCirros)
Expect(err).ToNot(HaveOccurred())
Expect(results.Len()).To(BeNumerically(">=", 1))

vals, err := results.AsInt64()
Expect(err).ToNot(HaveOccurred())
Expect(vals).To(HaveLen(1))
Expect(vals[0]).To(BeNumerically(">", 2147483647), "value is lower than 2Gi")
})

It("Should provide some string results", func() {
s := "jsonpath::.spec.domain.machine.type"
p, err := New(s)
Expand Down
3 changes: 3 additions & 0 deletions internal/template-validator/validation/test-utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test_utils

import (
"bytes"

"k8s.io/apimachinery/pkg/util/yaml"

kubevirt "kubevirt.io/api/core/v1"
Expand Down Expand Up @@ -34,6 +35,8 @@ spec:
name: cloudinitdisk
machine:
type: "q35"
memory:
guest: 2Gi
resources:
requests:
memory: 128M
Expand Down
Loading