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

feat(vd): apply new controller design #123

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
39 changes: 20 additions & 19 deletions crds/clustervirtualimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,36 @@ spec:
type: object
properties:
conditions:
type: array
description: |
Hold the state information of the `ClusterVirtualImage`.
The latest available observations of an object's current state.
type: array
items:
type: object
properties:
type:
type: string
status:
lastProbeTime:
description: Last time the condition was checked.
format: date-time
type: string
reason:
lastTransitionTime:
description: Last time the condition transit from one status to another.
format: date-time
type: string
message:
description: Human readable message indicating details about last transition.
type: string
lastProbeTime:
reason:
description: (brief) reason for the condition's last transition.
type: string
format: date-time
nullable: true
lastTransitionTime:
status:
description: Status of the condition, one of True, False, Unknown.
type: string
enum: ["True", "False", "Unknown"]
type:
description: Type of condition.
type: string
format: date-time
nullable: true
required:
- type
- status
- type
downloadSpeed:
type: object
description: |
Expand Down Expand Up @@ -287,9 +292,7 @@ spec:
* Provisioning - The process of resource creation (copying/downloading/building the image) is in progress.
* WaitForUserUpload - Waiting for the user to upload the image. The endpoint to upload the image is specified in `.status.uploadCommand`.
* Ready - The resource is created and ready to use.
* Failed - There was a problem when creating a resource, details can be seen in `.status.failureReason` and `.status.failureMessage`.
* NotReady - It is not possible to get information about the child image because of inability to connect to DVCR. The resource cannot be used.
* ImageLost - The child image of the resource is missing. The resource cannot be used.
* Failed - There was a problem when creating a resource.
* Terminating - The process of resource deletion is in progress.
enum:
[
Expand All @@ -298,9 +301,7 @@ spec:
"WaitForUserUpload",
"Ready",
"Failed",
"ImageLost",
"Terminating",
"Unknown",
]
progress:
type: string
Expand All @@ -313,7 +314,7 @@ spec:
observedGeneration:
type: integer
description: |
Represents the .metadata.generation that the status was set based upon.
The generation last processed by the controller.
additionalPrinterColumns:
- name: Phase
type: string
Expand Down
23 changes: 18 additions & 5 deletions crds/doc-ru-clustervirtualimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,22 @@ spec:
properties:
conditions:
description: |
Содержит информацию о состоянии `ClusterVirtualImage`.
Последнее подтвержденное состояние данного ресурса.
items:
properties:
lastProbeTime:
description: Время проверки условия.
lastTransitionTime:
description: Время перехода условия из одного состояния в другое.
message:
description: Удобочитаемое сообщение с подробной информацией о последнем переходе.
reason:
description: Краткая причина последнего перехода состояния.
status:
description: |
Статус условия. Возможные значения: `True`, `False`, `Unknown`.
type:
description: Тип условия.
cdrom:
description: |
Является ли образ форматом, который должен быть смонтирован как cdrom, например iso и т. д.
Expand Down Expand Up @@ -128,9 +143,7 @@ spec:
* Provisioning - Идет процесс создания ресурса (копирование/загрузка/создание образа).
* WaitForUserUpload - Ожидание загрузки образа пользователем. Путь для загрузки образа указывается в `.status.uploadCommand`.
* Ready - Ресурс создан и готов к использованию.
* Failed - При создании ресурса возникла проблема, подробности можно увидеть в `.status.failureReason` и `.status.failureMessage`.
* NotReady - Невозможно получить информацию о дочернем образе из-за невозможности подключения к DVCR. Ресурс не может быть использован.
* ImageLost - Дочернее образ ресурса отсутствует. Ресурс не может быть использован.
* Failed - При создании ресурса возникла проблема.
* Terminating - Ресурс находится в процессе удаления.
progress:
description: |
Expand Down Expand Up @@ -160,4 +173,4 @@ spec:
Команда для загрузки образа для типа 'Upload'.
observedGeneration:
description: |
Представляет .metadata.generation, на основе которого был установлен статус.
Поколение ресурса, которое в последний раз обрабатывалось контроллером.
21 changes: 18 additions & 3 deletions crds/doc-ru-virtualdisk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,22 @@ spec:
properties:
conditions:
description: |
Содержит информацию о состоянии `VirtualDisk`.
Последнее подтвержденное состояние данного ресурса.
items:
properties:
lastProbeTime:
description: Время проверки условия.
lastTransitionTime:
description: Время перехода условия из одного состояния в другое.
message:
description: Удобочитаемое сообщение с подробной информацией о последнем переходе.
reason:
description: Краткая причина последнего перехода состояния.
status:
description: |
Статус условия. Возможные значения: `True`, `False`, `Unknown`.
type:
description: Тип условия.
attachedToVirtualMachines:
description: |
Список виртуальных машин, использующих этот диск
Expand Down Expand Up @@ -125,7 +140,7 @@ spec:
* Provisioning — идет процесс создания ресурса (копирование/загрузка/создание образа).
* WaitForUserUpload — ожидание загрузки образа пользователем. Путь для загрузки образа указывается в `.status.uploadCommand`.
* Ready — ресурс создан и готов к использованию.
* Failed — при создании ресурса возникла проблема, подробности можно увидеть в `.status.failureReason` и `.status.failureMessage`.
* Failed — при создании ресурса возникла проблема.
* PVCLost — дочерний PVC ресурса отсутствует. Ресурс не может быть использован.
* Terminating - Ресурс находится в процессе удаления.
progress:
Expand All @@ -141,4 +156,4 @@ spec:
Команда для загрузки образа для типа 'Upload'.
observedGeneration:
description: |
Представляет .metadata.generation, на основе которого был установлен статус.
Поколение ресурса, которое в последний раз обрабатывалось контроллером.
34 changes: 19 additions & 15 deletions crds/virtualdisk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,31 +193,36 @@ spec:
type: object
properties:
conditions:
type: array
description: |
Hold the state information of the `ClusterVirtualImage`.
The latest available observations of an object's current state.
type: array
items:
type: object
properties:
type:
type: string
status:
lastProbeTime:
description: Last time the condition was checked.
format: date-time
type: string
reason:
lastTransitionTime:
description: Last time the condition transit from one status to another.
format: date-time
type: string
message:
description: Human readable message indicating details about last transition.
type: string
lastProbeTime:
reason:
description: (brief) reason for the condition's last transition.
type: string
format: date-time
nullable: true
lastTransitionTime:
status:
description: Status of the condition, one of True, False, Unknown.
type: string
enum: ["True", "False", "Unknown"]
type:
description: Type of condition.
type: string
format: date-time
nullable: true
required:
- type
- status
- type
downloadSpeed:
type: object
description: |
Expand Down Expand Up @@ -271,7 +276,6 @@ spec:
"Ready",
"Failed",
"PVCLost",
"Unknown",
"Terminating",
]
progress:
Expand All @@ -295,7 +299,7 @@ spec:
observedGeneration:
type: integer
description: |
Represents the .metadata.generation that the status was set based upon.
The generation last processed by the controller.
additionalPrinterColumns:
- name: Phase
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/controller/cpu"
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi"
"github.com/deckhouse/virtualization-controller/pkg/controller/ipam"
"github.com/deckhouse/virtualization-controller/pkg/controller/vd"
"github.com/deckhouse/virtualization-controller/pkg/controller/vmop"
virtv2alpha1 "github.com/deckhouse/virtualization/api/core/v1alpha2"
)
Expand Down Expand Up @@ -179,6 +180,11 @@ func main() {
os.Exit(1)
}

if _, err = vd.NewController(ctx, mgr, log, importerImage, uploaderImage, dvcrSettings); err != nil {
log.Error(err, "")
os.Exit(1)
}

if _, err := controller.NewVMIController(ctx, mgr, log, importerImage, uploaderImage, dvcrSettings); err != nil {
log.Error(err, "")
os.Exit(1)
Expand Down
12 changes: 12 additions & 0 deletions images/virtualization-artifact/pkg/common/percent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ func Test_ScalePercent(t *testing.T) {
high float64
expect string
}{
{
"70%",
0.0,
100.0,
"70.0%",
},
{
"0%",
50.0,
100.0,
"50.0%",
},
{
"100.0%",
0.0,
Expand Down
70 changes: 0 additions & 70 deletions images/virtualization-artifact/pkg/common/vmd/util.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (

const (
CVIShortName = "cvi"
VDShortName = "vd"

// AnnAPIGroup is the APIGroup for virtualization-controller.
AnnAPIGroup = "virt.deckhouse.io"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -72,15 +71,15 @@ func (h DatasourceReadyHandler) Handle(ctx context.Context, cvi *virtv2.ClusterV
case errors.Is(err, source.ErrSecretNotFound):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.DatasourceReadyReason_ContainerRegistrySecretNotFound
condition.Message = strings.ToTitle(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
case errors.As(err, &source.ImageNotReadyError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.DatasourceReadyReason_ImageNotReady
condition.Message = strings.ToTitle(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
case errors.As(err, &source.ClusterImageNotReadyError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.DatasourceReadyReason_ClusterImageNotReady
condition.Message = strings.ToTitle(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
}

return reconcile.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma

cvi.Status.Phase = virtv2.ImageReady

// Unprotect import time supplements to delete them later.
err = ds.importerService.Unprotect(ctx, pod)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu

cvi.Status.Phase = virtv2.ImageReady

// Unprotect import time supplements to delete them later.
err = ds.importerService.Unprotect(ctx, pod)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua

cvi.Status.Phase = virtv2.ImageReady

// Unprotect import time supplements to delete them later.
err = ds.importerService.Unprotect(ctx, pod)
if err != nil {
return false, err
Expand Down
Loading