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

instancetype: Add basic expand-spec docs #779

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
202 changes: 202 additions & 0 deletions docs/user_workloads/instancetypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,208 @@ $ kubectl get vmi/vm-cirros-csmall -o json | jq .spec.domain.cpu
}
```

## expand-spec

The VM `expand-spec` subresource API and `virtctl expand` subcommand allow users to view an existing or yet-to-be defined VM with any referenced instance types or preferences expanded within the core spec of the VM.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add an example how to expand a yet-to-be defined VM too?


For example, given the following simple VM using an instance type we can use the API or `virtctl expand` command to obtain an expanded copy of the VM, using `diff` to highlight the differences between the original and expanded VM:

```yaml
$ kubectl apply -f - <<EOF
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: cirros
spec:
instancetype:
name: u1.micro
runStrategy: Always
template:
metadata:
creationTimestamp: null
spec:
domain:
devices:
interfaces:
- masquerade: {}
name: default
machine:
resources: {}
networks:
- name: default
pod: {}
volumes:
- containerDisk:
image: registry:5000/kubevirt/cirros-container-disk-demo:devel
name: cirros
EOF
```

### virtctl expand

```yaml
$ virtctl expand --vm cirros
[..]
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
[..]
name: cirros
[..]
spec:
runStrategy: Always
template:
metadata:
creationTimestamp: null
spec:
architecture: amd64
domain:
cpu:
cores: 1
sockets: 1
threads: 1
devices:
interfaces:
- masquerade: {}
name: default
machine:
type: q35
memory:
guest: 1Gi
resources: {}
networks:
- name: default
pod: {}
volumes:
- containerDisk:
image: registry:5000/kubevirt/cirros-container-disk-demo:devel
name: cirros
[..]
$ diff -u <(kubectl get vm/cirros -o yaml | yq .spec) <(virtctl expand --vm cirros -o yaml | yq .spec)
--- /dev/fd/63 2024-03-25 13:37:27.948090870 +0000
+++ /dev/fd/62 2024-03-25 13:37:27.948090870 +0000
@@ -1,7 +1,3 @@
-instancetype:
- kind: virtualmachineclusterinstancetype
- name: u1.micro
- revisionName: cirros-u1.micro-1b23a27b-a7f2-4d69-8b3d-ee609a99d4a3-1
runStrategy: Always
template:
metadata:
@@ -9,12 +5,18 @@
spec:
architecture: amd64
domain:
+ cpu:
+ cores: 1
+ sockets: 1
+ threads: 1
devices:
interfaces:
- masquerade: {}
name: default
machine:
type: q35
+ memory:
+ guest: 1Gi
resources: {}
networks:
- name: default
```

### subresources.kubevirt.io expand-spec

```json
$ kubectl proxy --port=8080 &
[..]
$ curl http://localhost:8080/apis/subresources.kubevirt.io/v1/namespaces/default/virtualmachines/cirros/expand-spec | jq -S .spec
{
"runStrategy": "Always",
"template": {
"metadata": {
"creationTimestamp": null
},
"spec": {
"architecture": "amd64",
"domain": {
"cpu": {
"cores": 1,
"sockets": 1,
"threads": 1
},
"devices": {
"interfaces": [
{
"masquerade": {},
"name": "default"
}
]
},
"machine": {
"type": "q35"
},
"memory": {
"guest": "1Gi"
},
"resources": {}
},
"networks": [
{
"name": "default",
"pod": {}
}
],
"volumes": [
{
"containerDisk": {
"image": "registry:5000/kubevirt/cirros-container-disk-demo:devel"
},
"name": "cirros"
}
]
}
}
}
$ diff -u <(kubectl get vms/cirros -o json | jq .spec) <(curl http://localhost:8080/apis/subresources.kubevirt.io/v1/namespaces/default/virtualmachines/cirros/expand-spec | jq -S .spec)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4505 0 4505 0 0 919k 0 --:--:-- --:--:-- --:--:-- 1099k
--- /dev/fd/63 2024-03-25 14:10:28.355834087 +0000
+++ /dev/fd/62 2024-03-25 14:10:28.355834087 +0000
@@ -1,9 +1,4 @@
{
- "instancetype": {
- "kind": "virtualmachineclusterinstancetype",
- "name": "u1.micro",
- "revisionName": "cirros-u1.micro-1b23a27b-a7f2-4d69-8b3d-ee609a99d4a3-1"
- },
"runStrategy": "Always",
"template": {
"metadata": {
@@ -12,6 +7,11 @@
"spec": {
"architecture": "amd64",
"domain": {
+ "cpu": {
+ "cores": 1,
+ "sockets": 1,
+ "threads": 1
+ },
"devices": {
"interfaces": [
{
@@ -23,6 +23,9 @@
"machine": {
"type": "q35"
},
+ "memory": {
+ "guest": "1Gi"
+ },
"resources": {}
},
"networks": [
```

## inferFromVolume

The `inferFromVolume` attribute of both the `InstancetypeMatcher` and `PreferenceMatcher` allows a user to request that defaults are inferred from a volume. When requested, KubeVirt will look for the following labels on the underlying `PVC`, `DataSource` or `DataVolume` to determine the default name and kind:
Expand Down