Skip to content

Commit e496da0

Browse files
authored
feat(vd): apply new controller design
Signed-off-by: Isteb4k <[email protected]>
1 parent 9e21de8 commit e496da0

36 files changed

+3645
-118
lines changed

crds/clustervirtualimage.yaml

+20-19
Original file line numberDiff line numberDiff line change
@@ -188,31 +188,36 @@ spec:
188188
type: object
189189
properties:
190190
conditions:
191-
type: array
192191
description: |
193-
Hold the state information of the `ClusterVirtualImage`.
192+
The latest available observations of an object's current state.
193+
type: array
194194
items:
195195
type: object
196196
properties:
197-
type:
198-
type: string
199-
status:
197+
lastProbeTime:
198+
description: Last time the condition was checked.
199+
format: date-time
200200
type: string
201-
reason:
201+
lastTransitionTime:
202+
description: Last time the condition transit from one status to another.
203+
format: date-time
202204
type: string
203205
message:
206+
description: Human readable message indicating details about last transition.
204207
type: string
205-
lastProbeTime:
208+
reason:
209+
description: (brief) reason for the condition's last transition.
206210
type: string
207-
format: date-time
208-
nullable: true
209-
lastTransitionTime:
211+
status:
212+
description: Status of the condition, one of True, False, Unknown.
213+
type: string
214+
enum: ["True", "False", "Unknown"]
215+
type:
216+
description: Type of condition.
210217
type: string
211-
format: date-time
212-
nullable: true
213218
required:
214-
- type
215219
- status
220+
- type
216221
downloadSpeed:
217222
type: object
218223
description: |
@@ -287,9 +292,7 @@ spec:
287292
* Provisioning - The process of resource creation (copying/downloading/building the image) is in progress.
288293
* WaitForUserUpload - Waiting for the user to upload the image. The endpoint to upload the image is specified in `.status.uploadCommand`.
289294
* Ready - The resource is created and ready to use.
290-
* Failed - There was a problem when creating a resource, details can be seen in `.status.failureReason` and `.status.failureMessage`.
291-
* NotReady - It is not possible to get information about the child image because of inability to connect to DVCR. The resource cannot be used.
292-
* ImageLost - The child image of the resource is missing. The resource cannot be used.
295+
* Failed - There was a problem when creating a resource.
293296
* Terminating - The process of resource deletion is in progress.
294297
enum:
295298
[
@@ -298,9 +301,7 @@ spec:
298301
"WaitForUserUpload",
299302
"Ready",
300303
"Failed",
301-
"ImageLost",
302304
"Terminating",
303-
"Unknown",
304305
]
305306
progress:
306307
type: string
@@ -313,7 +314,7 @@ spec:
313314
observedGeneration:
314315
type: integer
315316
description: |
316-
Represents the .metadata.generation that the status was set based upon.
317+
The generation last processed by the controller.
317318
additionalPrinterColumns:
318319
- name: Phase
319320
type: string

crds/doc-ru-clustervirtualimage.yaml

+18-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,22 @@ spec:
9797
properties:
9898
conditions:
9999
description: |
100-
Содержит информацию о состоянии `ClusterVirtualImage`.
100+
Последнее подтвержденное состояние данного ресурса.
101+
items:
102+
properties:
103+
lastProbeTime:
104+
description: Время проверки условия.
105+
lastTransitionTime:
106+
description: Время перехода условия из одного состояния в другое.
107+
message:
108+
description: Удобочитаемое сообщение с подробной информацией о последнем переходе.
109+
reason:
110+
description: Краткая причина последнего перехода состояния.
111+
status:
112+
description: |
113+
Статус условия. Возможные значения: `True`, `False`, `Unknown`.
114+
type:
115+
description: Тип условия.
101116
cdrom:
102117
description: |
103118
Является ли образ форматом, который должен быть смонтирован как cdrom, например iso и т. д.
@@ -128,9 +143,7 @@ spec:
128143
* Provisioning - Идет процесс создания ресурса (копирование/загрузка/создание образа).
129144
* WaitForUserUpload - Ожидание загрузки образа пользователем. Путь для загрузки образа указывается в `.status.uploadCommand`.
130145
* Ready - Ресурс создан и готов к использованию.
131-
* Failed - При создании ресурса возникла проблема, подробности можно увидеть в `.status.failureReason` и `.status.failureMessage`.
132-
* NotReady - Невозможно получить информацию о дочернем образе из-за невозможности подключения к DVCR. Ресурс не может быть использован.
133-
* ImageLost - Дочернее образ ресурса отсутствует. Ресурс не может быть использован.
146+
* Failed - При создании ресурса возникла проблема.
134147
* Terminating - Ресурс находится в процессе удаления.
135148
progress:
136149
description: |
@@ -160,4 +173,4 @@ spec:
160173
Команда для загрузки образа для типа 'Upload'.
161174
observedGeneration:
162175
description: |
163-
Представляет .metadata.generation, на основе которого был установлен статус.
176+
Поколение ресурса, которое в последний раз обрабатывалось контроллером.

crds/doc-ru-virtualdisk.yaml

+18-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,22 @@ spec:
9494
properties:
9595
conditions:
9696
description: |
97-
Содержит информацию о состоянии `VirtualDisk`.
97+
Последнее подтвержденное состояние данного ресурса.
98+
items:
99+
properties:
100+
lastProbeTime:
101+
description: Время проверки условия.
102+
lastTransitionTime:
103+
description: Время перехода условия из одного состояния в другое.
104+
message:
105+
description: Удобочитаемое сообщение с подробной информацией о последнем переходе.
106+
reason:
107+
description: Краткая причина последнего перехода состояния.
108+
status:
109+
description: |
110+
Статус условия. Возможные значения: `True`, `False`, `Unknown`.
111+
type:
112+
description: Тип условия.
98113
attachedToVirtualMachines:
99114
description: |
100115
Список виртуальных машин, использующих этот диск
@@ -125,7 +140,7 @@ spec:
125140
* Provisioning — идет процесс создания ресурса (копирование/загрузка/создание образа).
126141
* WaitForUserUpload — ожидание загрузки образа пользователем. Путь для загрузки образа указывается в `.status.uploadCommand`.
127142
* Ready — ресурс создан и готов к использованию.
128-
* Failed — при создании ресурса возникла проблема, подробности можно увидеть в `.status.failureReason` и `.status.failureMessage`.
143+
* Failed — при создании ресурса возникла проблема.
129144
* PVCLost — дочерний PVC ресурса отсутствует. Ресурс не может быть использован.
130145
* Terminating - Ресурс находится в процессе удаления.
131146
progress:
@@ -141,4 +156,4 @@ spec:
141156
Команда для загрузки образа для типа 'Upload'.
142157
observedGeneration:
143158
description: |
144-
Представляет .metadata.generation, на основе которого был установлен статус.
159+
Поколение ресурса, которое в последний раз обрабатывалось контроллером.

crds/virtualdisk.yaml

+19-15
Original file line numberDiff line numberDiff line change
@@ -193,31 +193,36 @@ spec:
193193
type: object
194194
properties:
195195
conditions:
196-
type: array
197196
description: |
198-
Hold the state information of the `ClusterVirtualImage`.
197+
The latest available observations of an object's current state.
198+
type: array
199199
items:
200200
type: object
201201
properties:
202-
type:
203-
type: string
204-
status:
202+
lastProbeTime:
203+
description: Last time the condition was checked.
204+
format: date-time
205205
type: string
206-
reason:
206+
lastTransitionTime:
207+
description: Last time the condition transit from one status to another.
208+
format: date-time
207209
type: string
208210
message:
211+
description: Human readable message indicating details about last transition.
209212
type: string
210-
lastProbeTime:
213+
reason:
214+
description: (brief) reason for the condition's last transition.
211215
type: string
212-
format: date-time
213-
nullable: true
214-
lastTransitionTime:
216+
status:
217+
description: Status of the condition, one of True, False, Unknown.
218+
type: string
219+
enum: ["True", "False", "Unknown"]
220+
type:
221+
description: Type of condition.
215222
type: string
216-
format: date-time
217-
nullable: true
218223
required:
219-
- type
220224
- status
225+
- type
221226
downloadSpeed:
222227
type: object
223228
description: |
@@ -271,7 +276,6 @@ spec:
271276
"Ready",
272277
"Failed",
273278
"PVCLost",
274-
"Unknown",
275279
"Terminating",
276280
]
277281
progress:
@@ -295,7 +299,7 @@ spec:
295299
observedGeneration:
296300
type: integer
297301
description: |
298-
Represents the .metadata.generation that the status was set based upon.
302+
The generation last processed by the controller.
299303
additionalPrinterColumns:
300304
- name: Phase
301305
type: string

images/virtualization-artifact/cmd/virtualization-controller/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/deckhouse/virtualization-controller/pkg/controller/cpu"
4444
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi"
4545
"github.com/deckhouse/virtualization-controller/pkg/controller/ipam"
46+
"github.com/deckhouse/virtualization-controller/pkg/controller/vd"
4647
"github.com/deckhouse/virtualization-controller/pkg/controller/vmop"
4748
virtv2alpha1 "github.com/deckhouse/virtualization/api/core/v1alpha2"
4849
)
@@ -179,6 +180,11 @@ func main() {
179180
os.Exit(1)
180181
}
181182

183+
if _, err = vd.NewController(ctx, mgr, log, importerImage, uploaderImage, dvcrSettings); err != nil {
184+
log.Error(err, "")
185+
os.Exit(1)
186+
}
187+
182188
if _, err := controller.NewVMIController(ctx, mgr, log, importerImage, uploaderImage, dvcrSettings); err != nil {
183189
log.Error(err, "")
184190
os.Exit(1)

images/virtualization-artifact/pkg/common/percent_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ func Test_ScalePercent(t *testing.T) {
2828
high float64
2929
expect string
3030
}{
31+
{
32+
"70%",
33+
0.0,
34+
100.0,
35+
"70.0%",
36+
},
37+
{
38+
"0%",
39+
50.0,
40+
100.0,
41+
"50.0%",
42+
},
3143
{
3244
"100.0%",
3345
0.0,

images/virtualization-artifact/pkg/common/vmd/util.go

-70
This file was deleted.

images/virtualization-artifact/pkg/controller/common/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343

4444
const (
4545
CVIShortName = "cvi"
46+
VDShortName = "vd"
4647

4748
// AnnAPIGroup is the APIGroup for virtualization-controller.
4849
AnnAPIGroup = "virt.deckhouse.io"

images/virtualization-artifact/pkg/controller/cvi/internal/datasource_ready.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"strings"
2423

2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -72,15 +71,15 @@ func (h DatasourceReadyHandler) Handle(ctx context.Context, cvi *virtv2.ClusterV
7271
case errors.Is(err, source.ErrSecretNotFound):
7372
condition.Status = metav1.ConditionFalse
7473
condition.Reason = cvicondition.DatasourceReadyReason_ContainerRegistrySecretNotFound
75-
condition.Message = strings.ToTitle(err.Error())
74+
condition.Message = service.CapitalizeFirstLetter(err.Error())
7675
case errors.As(err, &source.ImageNotReadyError{}):
7776
condition.Status = metav1.ConditionFalse
7877
condition.Reason = cvicondition.DatasourceReadyReason_ImageNotReady
79-
condition.Message = strings.ToTitle(err.Error())
78+
condition.Message = service.CapitalizeFirstLetter(err.Error())
8079
case errors.As(err, &source.ClusterImageNotReadyError{}):
8180
condition.Status = metav1.ConditionFalse
8281
condition.Reason = cvicondition.DatasourceReadyReason_ClusterImageNotReady
83-
condition.Message = strings.ToTitle(err.Error())
82+
condition.Message = service.CapitalizeFirstLetter(err.Error())
8483
}
8584

8685
return reconcile.Result{}, err

images/virtualization-artifact/pkg/controller/cvi/internal/source/http.go

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
7878

7979
cvi.Status.Phase = virtv2.ImageReady
8080

81+
// Unprotect import time supplements to delete them later.
8182
err = ds.importerService.Unprotect(ctx, pod)
8283
if err != nil {
8384
return false, err

images/virtualization-artifact/pkg/controller/cvi/internal/source/object_ref.go

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
8484

8585
cvi.Status.Phase = virtv2.ImageReady
8686

87+
// Unprotect import time supplements to delete them later.
8788
err = ds.importerService.Unprotect(ctx, pod)
8889
if err != nil {
8990
return false, err

images/virtualization-artifact/pkg/controller/cvi/internal/source/registry.go

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
8686

8787
cvi.Status.Phase = virtv2.ImageReady
8888

89+
// Unprotect import time supplements to delete them later.
8990
err = ds.importerService.Unprotect(ctx, pod)
9091
if err != nil {
9192
return false, err

0 commit comments

Comments
 (0)