Skip to content

Instantly share code, notes, and snippets.

@johnsimcall
Last active October 23, 2024 20:51
Show Gist options
  • Save johnsimcall/2c08e268419020aa97ee4b5964d403b4 to your computer and use it in GitHub Desktop.
Save johnsimcall/2c08e268419020aa97ee4b5964d403b4 to your computer and use it in GitHub Desktop.
Report Virtual Machine memory requests

This is hacky because there are at least three different ways to set the VM's memory.

  1. .spec.template.spec.domain.memory.guest
  2. .spec.instancetype.name
  3. .spec.template.spec.domain.resources.requests.memory
oc get vm -A -o go-template='{{range .items}}{{.metadata.name}}{{"\t"}} {{.status.printableStatus}}{{"\t"}} {{.spec.template.spec.domain.memory.guest}} {{.spec.instancetype.name}}{{"\t"}} {{.spec.template.spec.domain.resources.requests.memory}}{{"\n"}}{{end}}'

rhel-9-amber-limpet-47          	 Running	 <no value>  u1.medium	 <no value>
test103                         	 Running	 <no value>  <no value>	 8Gi
centos-stream9-bronze-meerkat-50	 Stopped	 2Gi         <no value>	 <no value>
...
oc get virtualmachineclusterinstancetypes -o go-template='{{range .items}}{{.metadata.name}}{{"\t"}} {{.spec.memory.guest}} {{"\n"}}{{end}}'

cx1.2xlarge	 16Gi 
cx1.4xlarge	 32Gi 
...

Probably better to query the virt-launcher pods... Kudos to ChatGPT for helping me create this syntax. Prompt:

help me write a kubectl command that will list all pods using go-template output which includes the memory requests from the container called "compute"

oc get pods -A -l kubevirt.io/domain -o go-template='{{range .items}}{{range .spec.containers}}{{if eq .name "compute"}}{{.resources.requests.memory}}{{end}}{{end}} {{.status.phase}} {{.metadata.namespace}}/{{.metadata.name}}{{"\n"}}{{end}}'

8474Mi Running ansiblenetworking1/virt-launcher-test103-gpbs8
2302Mi Running jcall/virt-launcher-rhel9-lab-net-6r5h4
4565499905 Running project-app1/virt-launcher-fedora-app1-jzkwp
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment