Skip to content

Commit

Permalink
Merge pull request #679 from ksimon1/fix-quantity-ptr
Browse files Browse the repository at this point in the history
fix: fix wrong parsing of vm.spec.template.spec.domain.memory.guest in validator
  • Loading branch information
kubevirt-bot authored Sep 1, 2023
2 parents 72c7fba + b134be4 commit 8976a5f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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

0 comments on commit 8976a5f

Please sign in to comment.