Skip to content

Commit

Permalink
ACM-14471: Collect additional VM properties (#310)
Browse files Browse the repository at this point in the history
* Collect additional VM properties

Signed-off-by: Jorge Padilla <[email protected]>

* Add tests

Signed-off-by: Jorge Padilla <[email protected]>

* commit missing test data file

Signed-off-by: Jorge Padilla <[email protected]>

* lowercase file name

Signed-off-by: Jorge Padilla <[email protected]>

---------

Signed-off-by: Jorge Padilla <[email protected]>
  • Loading branch information
jlpadilla authored Sep 26, 2024
1 parent 589a218 commit f3ec310
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func TestReconcilerComplete(t *testing.T) {
// Checks the count of nodes and edges based on the JSON files in pkg/test-data
// Update counts when the test data is changed
// We don't create Nodes for kind = Event
const Nodes = 40
const Nodes = 41
const Edges = 51
if len(com.Edges) != Edges || com.TotalEdges != Edges || len(com.Nodes) != Nodes || com.TotalNodes != Nodes {
ns := tr.NodeStore{
Expand Down
11 changes: 11 additions & 0 deletions pkg/transforms/genericResourceConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ var defaultTransformConfig = map[string]ResourceConfig{
{Name: "degraded", JSONPath: `{.status.conditions[?(@.type=="Degraded")].status}`},
},
},
"DataVolume.cdi.kubevirt.io": {
properties: []ExtractProperty{
{Name: "size", JSONPath: `{.spec.storage.resources.requests.storage}`},
{Name: "storageClassName", JSONPath: `{.spec.storage.storageClassName}`},
},
},
"VirtualMachine.kubevirt.io": {
properties: []ExtractProperty{
{Name: "cpu", JSONPath: `{.spec.template.spec.domain.cpu.cores}`},
{Name: "memory", JSONPath: `{.spec.template.spec.domain.memory.guest}`},
{Name: "status", JSONPath: `{.status.printableStatus}`},
{Name: "ready", JSONPath: `{.status.conditions[?(@.type=='Ready')].status}`},
},
Expand All @@ -64,6 +72,9 @@ var defaultTransformConfig = map[string]ResourceConfig{
properties: []ExtractProperty{
{Name: "node", JSONPath: `{.status.nodeName}`},
{Name: "ipaddress", JSONPath: `{.status.interfaces[0].ipAddress}`},
{Name: "phase", JSONPath: `{.status.phase}`},
{Name: "ready", JSONPath: `{.status.conditions[?(@.type=='Ready')].status}`},
{Name: "liveMigratable", JSONPath: `{.status.conditions[?(@.type=='LiveMigratable')].status}`},
},
},
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/transforms/genericResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func Test_genericResourceFromConfigVM(t *testing.T) {
// Verify properties defined in the transform config
AssertEqual("display", node.Properties["status"], "Running", t)
AssertEqual("phase", node.Properties["ready"], "True", t)
AssertEqual("cpu", node.Properties["cpu"], int64(1), t)
AssertEqual("memory", node.Properties["memory"], "2Gi", t)

}

Expand All @@ -115,5 +117,23 @@ func Test_genericResourceFromConfigVMI(t *testing.T) {
// Verify properties defined in the transform config
AssertEqual("node", node.Properties["node"], "sno-0-0", t)
AssertEqual("ipaddress", node.Properties["ipaddress"], "10.128.1.193", t)
AssertEqual("phase", node.Properties["phase"], "Running", t)
AssertEqual("ready", node.Properties["ready"], "True", t)
AssertEqual("liveMigratable", node.Properties["liveMigratable"], "False", t)
}

func Test_genericResourceFromConfigDataVolume(t *testing.T) {
var r unstructured.Unstructured
UnmarshalFile("datavolume.json", &r, t)
node := GenericResourceBuilder(&r).BuildNode()

// Verify common properties
AssertEqual("name", node.Properties["name"], "centos7-gray-owl-35", t)
AssertEqual("kind", node.Properties["kind"], "DataVolume", t)
AssertEqual("namespace", node.Properties["namespace"], "openshift-cnv", t)
AssertEqual("created", node.Properties["created"], "2024-09-09T20:00:42Z", t)

// Verify properties defined in the transform config
AssertEqual("size", node.Properties["size"], "20Gi", t)
AssertEqual("storageClassName", node.Properties["storageClassName"], nil, t)
}
71 changes: 71 additions & 0 deletions test-data/datavolume.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"apiVersion": "cdi.kubevirt.io/v1beta1",
"kind": "DataVolume",
"metadata": {
"annotations": {
"cdi.kubevirt.io/storage.usePopulator": "false"
},
"creationTimestamp": "2024-09-09T20:00:42Z",
"generation": 1,
"labels": {
"kubevirt.io/created-by": "42634581-0cc1-4aa9-bec6-69f59049e2d3"
},
"name": "centos7-gray-owl-35",
"namespace": "openshift-cnv",
"ownerReferences": [
{
"apiVersion": "kubevirt.io/v1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "VirtualMachine",
"name": "centos7-gray-owl-35",
"uid": "42634581-0cc1-4aa9-bec6-69f59049e2d3"
}
],
"resourceVersion": "1483926",
"uid": "341376a4-58da-4e5e-bb0d-7ff6a5eb3ef1"
},
"spec": {
"source": {
"registry": {
"url": "docker://quay.io/containerdisks/centos:7-2009"
}
},
"storage": {
"resources": {
"requests": {
"storage": "20Gi"
}
}
}
},
"status": {
"claimName": "centos7-gray-owl-35",
"conditions": [
{
"lastHeartbeatTime": "2024-09-09T20:00:44Z",
"lastTransitionTime": "2024-09-09T20:00:44Z",
"message": "PVC centos7-gray-owl-35 Bound",
"reason": "Bound",
"status": "True",
"type": "Bound"
},
{
"lastHeartbeatTime": "2024-09-09T20:01:07Z",
"lastTransitionTime": "2024-09-09T20:01:07Z",
"status": "True",
"type": "Ready"
},
{
"lastHeartbeatTime": "2024-09-09T20:01:05Z",
"lastTransitionTime": "2024-09-09T20:01:05Z",
"message": "Import Complete",
"reason": "Completed",
"status": "False",
"type": "Running"
}
],
"phase": "Succeeded",
"progress": "100.0%"
}
}

0 comments on commit f3ec310

Please sign in to comment.