Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 33069fb

Browse files
committed
feat: add example of tekton
Add example of Tekton Task and Tekton Pipeline to run the tool inside it. Jira-Url: https://issues.redhat.com/browse/CNV-21703 Signed-off-by: Ben Oukhanov <[email protected]>
1 parent 0ac4fa6 commit 33069fb

File tree

3 files changed

+284
-49
lines changed

3 files changed

+284
-49
lines changed

README.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,6 @@ Deploy `kubevirt-disk-uploader` within the same namespace as the Virtual Machine
2424
kubectl apply -f kubevirt-disk-uploader.yaml -n $VM_NAMESPACE
2525
```
2626

27-
## Example
28-
29-
1. Enable VMExport:
30-
31-
```
32-
kubectl apply -f examples/enable-vmexport.yaml
33-
```
34-
35-
2. Create a new example Virtual Machine:
36-
37-
```
38-
kubectl apply -f examples/example-vm.yaml
39-
```
40-
41-
3. Create a new KubeVirt Disk Uploader:
42-
43-
```
44-
kubectl apply -f kubevirt-disk-uploader.yaml
45-
```
46-
47-
4. See the logs of KubeVirt Disk Uploader:
48-
49-
```
50-
kubectl logs kubevirt-disk-uploader
51-
Extracts disk and uploads it to a container registry...
52-
Applying VirutalMachineExport object to expose Virutal Machine data...
53-
virtualmachineexport.export.kubevirt.io/example-vm created
54-
Downloading disk image disk.img.gz from example-vm Virutal Machine...
55-
waiting for VM Export example-vm status to be ready...
56-
Downloading file: 472.09 MiB [==>________________] 5.13 MiB
57-
...
58-
Donwload completed successfully.
59-
Converting raw disk image to qcow2 format...
60-
20969472+0 records in
61-
20969472+0 records out
62-
10736369664 bytes (11 GB, 10 GiB) copied, 45.9953 s, 233 MB/s
63-
./tmp/disk.qcow2
64-
Building and uploading new container image with exported disk image...
65-
2023/11/28 16:55:37 Image built successfully
66-
2023/11/28 17:12:41 Image pushed successfully
67-
Succesfully extracted disk image and uploaded it in a new container image to container registry.
68-
```
69-
70-
5. Run the new container disk in a new Virtual Machine:
71-
72-
```
73-
kubectl apply -f examples/example-vm-exported.yaml
74-
```
75-
7627
## KubeVirt Documentation
7728

7829
Read more about the used API at [KubeVirt Export API](https://kubevirt.io/user-guide/operations/export_api).

examples/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Examples
2+
3+
### Manual Example
4+
5+
1. Enable VMExport in KubeVirt Custom Resource (CR):
6+
7+
```
8+
kubectl apply -f examples/enable-vmexport.yaml
9+
```
10+
11+
2. Deploy a new example Virtual Machine (VM):
12+
13+
```
14+
kubectl apply -f examples/example-vm.yaml
15+
```
16+
17+
3. Deploy KubeVirt Disk Uploader:
18+
19+
```
20+
kubectl apply -f kubevirt-disk-uploader.yaml
21+
```
22+
23+
4. Deploy exported Virtual Machine (VM):
24+
25+
```
26+
kubectl apply -f examples/example-vm-exported.yaml
27+
```
28+
29+
### Tekton Pipeline Example
30+
31+
Deploy example pipeline:
32+
33+
```
34+
kubectl apply -f examples/kubevirt-disk-uploader-tekton.yaml
35+
```
36+
37+
This pipeline will deploy a new Virutal Machine (VM), disk uploader, and then the exported Virutal Machine (VM).
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
---
2+
apiVersion: tekton.dev/v1beta1
3+
kind: Task
4+
metadata:
5+
name: example-vm-task
6+
spec:
7+
steps:
8+
- name: deploy-example-vm
9+
image: bitnami/kubectl
10+
script: |
11+
#!/bin/bash
12+
cat <<EOF | kubectl apply -f -
13+
apiVersion: kubevirt.io/v1
14+
kind: VirtualMachine
15+
metadata:
16+
labels:
17+
kubevirt.io/vm: example-vm-datavolume-tekton
18+
name: example-vm-tekton
19+
spec:
20+
dataVolumeTemplates:
21+
- metadata:
22+
creationTimestamp: null
23+
name: example-dv-tekton
24+
annotations:
25+
# ContainerDisk will be imported without starting the
26+
# Virtual Machine (VM). Otherwise, VM should be started
27+
# to import the ContainerDisk.
28+
cdi.kubevirt.io/storage.bind.immediate.requested: "true"
29+
cdi.kubevirt.io/storage.deleteAfterCompletion: "false"
30+
spec:
31+
storage:
32+
accessModes:
33+
- ReadWriteOnce
34+
resources:
35+
requests:
36+
storage: 5Gi
37+
source:
38+
registry:
39+
url: docker://quay.io/containerdisks/fedora:38
40+
running: false
41+
template:
42+
metadata:
43+
labels:
44+
kubevirt.io/vm: example-vm-datavolume-tekton
45+
spec:
46+
domain:
47+
devices:
48+
disks:
49+
- disk:
50+
bus: virtio
51+
name: datavolumedisk
52+
resources:
53+
requests:
54+
memory: 2Gi
55+
terminationGracePeriodSeconds: 0
56+
volumes:
57+
- dataVolume:
58+
name: example-dv-tekton
59+
name: datavolumedisk
60+
EOF
61+
---
62+
apiVersion: tekton.dev/v1beta1
63+
kind: Task
64+
metadata:
65+
name: example-vm-exported-task
66+
spec:
67+
steps:
68+
- name: deploy-example-vm-exported
69+
image: bitnami/kubectl
70+
script: |
71+
#!/bin/bash
72+
cat <<EOF | kubectl apply -f -
73+
apiVersion: kubevirt.io/v1
74+
kind: VirtualMachine
75+
metadata:
76+
creationTimestamp: null
77+
name: example-vm-exported-tekton
78+
spec:
79+
runStrategy: Always
80+
template:
81+
metadata:
82+
creationTimestamp: null
83+
spec:
84+
domain:
85+
devices:
86+
disks:
87+
- disk:
88+
bus: virtio
89+
name: containerdisk
90+
rng: {}
91+
features:
92+
acpi: {}
93+
smm:
94+
enabled: true
95+
firmware:
96+
bootloader:
97+
efi:
98+
secureBoot: true
99+
resources:
100+
requests:
101+
memory: 1Gi
102+
terminationGracePeriodSeconds: 180
103+
volumes:
104+
- containerDisk:
105+
image: quay.io/boukhano/example-vm-exported:latest
106+
name: containerdisk
107+
EOF
108+
---
109+
apiVersion: v1
110+
kind: ServiceAccount
111+
metadata:
112+
name: kubevirt-disk-uploader-tekton
113+
---
114+
apiVersion: rbac.authorization.k8s.io/v1
115+
kind: Role
116+
metadata:
117+
name: kubevirt-disk-uploader-tekton
118+
rules:
119+
- apiGroups: ["kubevirt.io"]
120+
resources: ["virtualmachines"]
121+
verbs: ["get", "create", "patch"]
122+
- apiGroups: ["export.kubevirt.io"]
123+
resources: ["virtualmachineexports"]
124+
verbs: ["get", "create"]
125+
- apiGroups: [""]
126+
resources: ["secrets"]
127+
verbs: ["get", "create"]
128+
---
129+
apiVersion: rbac.authorization.k8s.io/v1
130+
kind: RoleBinding
131+
metadata:
132+
name: kubevirt-disk-uploader-tekton
133+
subjects:
134+
- kind: ServiceAccount
135+
name: kubevirt-disk-uploader-tekton
136+
roleRef:
137+
kind: Role
138+
name: kubevirt-disk-uploader-tekton
139+
apiGroup: rbac.authorization.k8s.io
140+
---
141+
apiVersion: v1
142+
kind: Secret
143+
metadata:
144+
name: kubevirt-disk-uploader-credentials-tekton
145+
type: Opaque
146+
data:
147+
registryUsername: ""
148+
registryPassword: ""
149+
registryHostname: ""
150+
---
151+
apiVersion: tekton.dev/v1beta1
152+
kind: Task
153+
metadata:
154+
name: kubevirt-disk-uploader-task
155+
spec:
156+
params:
157+
- name: VM_NAME
158+
description: The name of the virtual machine
159+
type: string
160+
- name: EXPORTED_IMAGE
161+
description: The name of the exported image
162+
type: string
163+
- name: DISK_IMAGE
164+
description: The name of the disk image
165+
type: string
166+
steps:
167+
- name: kubevirt-disk-uploader-step
168+
image: quay.io/boukhano/kubevirt-disk-uploader:latest
169+
env:
170+
- name: REGISTRY_USERNAME
171+
valueFrom:
172+
secretKeyRef:
173+
name: kubevirt-disk-uploader-credentials-tekton
174+
key: registryUsername
175+
- name: REGISTRY_PASSWORD
176+
valueFrom:
177+
secretKeyRef:
178+
name: kubevirt-disk-uploader-credentials-tekton
179+
key: registryPassword
180+
- name: REGISTRY_HOST
181+
valueFrom:
182+
secretKeyRef:
183+
name: kubevirt-disk-uploader-credentials-tekton
184+
key: registryHostname
185+
command: ["/usr/local/bin/run-uploader.sh"]
186+
args:
187+
- $(params.VM_NAME)
188+
- $(params.EXPORTED_IMAGE)
189+
- $(params.DISK_IMAGE)
190+
resources:
191+
requests:
192+
memory: "3Gi"
193+
limits:
194+
memory: "5Gi"
195+
---
196+
apiVersion: tekton.dev/v1beta1
197+
kind: Pipeline
198+
metadata:
199+
name: kubevirt-disk-uploader-pipeline
200+
spec:
201+
params:
202+
- name: VM_NAME
203+
description: "Name of the virtual machine"
204+
type: string
205+
- name: EXPORTED_IMAGE
206+
description: "Name of the exported image"
207+
type: string
208+
- name: DISK_IMAGE
209+
description: "Name of the disk image"
210+
type: string
211+
tasks:
212+
- name: deploy-example-vm
213+
taskRef:
214+
name: example-vm-task
215+
- name: kubevirt-disk-uploader
216+
taskRef:
217+
name: kubevirt-disk-uploader-task
218+
runAfter:
219+
- deploy-example-vm
220+
params:
221+
- name: VM_NAME
222+
value: "$(params.VM_NAME)"
223+
- name: EXPORTED_IMAGE
224+
value: "$(params.EXPORTED_IMAGE)"
225+
- name: DISK_IMAGE
226+
value: "$(params.DISK_IMAGE)"
227+
- name: deploy-example-vm-exported
228+
taskRef:
229+
name: example-vm-exported-task
230+
runAfter:
231+
- kubevirt-disk-uploader
232+
---
233+
apiVersion: tekton.dev/v1beta1
234+
kind: PipelineRun
235+
metadata:
236+
name: kubevirt-disk-uploader-pipeline-run
237+
spec:
238+
pipelineRef:
239+
name: kubevirt-disk-uploader-pipeline
240+
params:
241+
- name: VM_NAME
242+
value: example-vm
243+
- name: EXPORTED_IMAGE
244+
value: example-vm-exported:latest
245+
- name: DISK_IMAGE
246+
value: disk.img.gz
247+
serviceAccountName: kubevirt-disk-uploader-tekton

0 commit comments

Comments
 (0)