Skip to content

Commit

Permalink
feat(vi): apply new controller design
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Lopatin <[email protected]>
  • Loading branch information
Isteb4k authored and LopatinDmitr committed Jun 25, 2024
1 parent ba12e49 commit 6e32105
Show file tree
Hide file tree
Showing 32 changed files with 1,752 additions and 1,626 deletions.
3 changes: 2 additions & 1 deletion api/core/v1alpha2/finalizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha2

const (
FinalizerClusterVirtualImageProtection = "virtualization.deckhouse.io/cvi-protection"
FinalizerVirtualImageProtection = "virtualization.deckhouse.io/vi-protection"
FinalizerVirtualDiskProtection = "virtualization.deckhouse.io/vd-protection"
FinalizerPodProtection = "virtualization.deckhouse.io/pod-protection"
FinalizerServiceProtection = "virtualization.deckhouse.io/svc-protection"
Expand All @@ -37,7 +38,7 @@ const (

FinalizerCVICleanup = "virtualization.deckhouse.io/cvi-cleanup"
FinalizerVDCleanup = "virtualization.deckhouse.io/vd-cleanup"
FinalizerVMICleanup = "virtualization.deckhouse.io/vi-cleanup"
FinalizerVICleanup = "virtualization.deckhouse.io/vi-cleanup"
FinalizerVMCleanup = "virtualization.deckhouse.io/vm-cleanup"
FinalizerIPAddressClaimCleanup = "virtualization.deckhouse.io/vmip-cleanup"
FinalizerIPAddressLeaseCleanup = "virtualization.deckhouse.io/vmipl-cleanup"
Expand Down
5 changes: 0 additions & 5 deletions api/core/v1alpha2/image_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const (
ImageProvisioning ImagePhase = "Provisioning"
ImageReady ImagePhase = "Ready"
ImageFailed ImagePhase = "Failed"
ImagePVCLost ImagePhase = "PVCLost"
ImageUnknown ImagePhase = "Unknown"
ImageTerminating ImagePhase = "Terminating"
)

Expand All @@ -40,9 +38,6 @@ type ImageStatus struct {
Phase ImagePhase `json:"phase,omitempty"`
Progress string `json:"progress,omitempty"`
UploadCommand string `json:"uploadCommand,omitempty"`
// TODO remove.
FailureReason string `json:"failureReason,omitempty"`
FailureMessage string `json:"failureMessage,omitempty"`
}

type StatusSpeed struct {
Expand Down
42 changes: 42 additions & 0 deletions api/core/v1alpha2/vicondition/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vicondition

type Type = string

const (
DatasourceReadyType Type = "DatasourceReady"
ReadyType Type = "Ready"
)

type (
DatasourceReadyReason = string
ReadyReason = string
)

const (
DatasourceReadyReason_DatasourceReady DatasourceReadyReason = "DatasourceReady"
DatasourceReadyReason_ContainerRegistrySecretNotFound DatasourceReadyReason = "ContainerRegistrySecretNotFound"
DatasourceReadyReason_ImageNotReady DatasourceReadyReason = "ImageNotReady"
DatasourceReadyReason_ClusterImageNotReady DatasourceReadyReason = "ClusterImageNotReady"

ReadyReason_WaitForUserUpload ReadyReason = "WaitForUserUpload"
ReadyReason_Provisioning ReadyReason = "Provisioning"
ReadyReason_ProvisioningNotStarted ReadyReason = "ProvisioningNotStarted"
ReadyReason_ProvisioningFailed ReadyReason = "ProvisioningFailed"
ReadyReason_Ready ReadyReason = "Ready"
)
4 changes: 3 additions & 1 deletion api/core/v1alpha2/virtual_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ type VirtualImageSpec struct {
}

type VirtualImageStatus struct {
ImageStatus `json:",inline"`
ImageStatus `json:",inline"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

type VirtualImageDataSource struct {
Expand Down
20 changes: 15 additions & 5 deletions crds/doc-ru-virtualimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ spec:
description: ""
sha256:
description: ""
insecureSkipVerify:
description: |
Отключить проверку TLS-сертификата (небезопасно и не должно использоваться в производственных средах).
url:
description: |
URL с образом. Поддерживаются следующие типы образов:
Expand Down Expand Up @@ -92,9 +89,22 @@ spec:
* `ContainerRegistry` — использовать container registry (DVCR). В этом случае образы будут загружаться в контейнер, а затем в DVCR (поставляется с модулем виртуализации).
status:
properties:
attachedToVirtualMachines:
conditions:
description: |
Список виртуальных машин, использующих этот образ
Последние доступные наблюдения текущего состояния объекта.
properties:
type:
description: Тип состояния.
status:
description: Статус состояния (одно из True, False, Unknown).
message:
description: Cообщение c деталями последнего перехода состояния.
reason:
description: Краткая причина последнего перехода состояния.
lastProbeTime:
description: Время последней проверки состояния.
lastTransitionTime:
description: Время последнего перехода состояния из одного статуса в другой.
cdrom:
description: |
Является ли образ форматом, который должен быть смонтирован как cdrom, например iso и т. д.
Expand Down
69 changes: 41 additions & 28 deletions crds/virtualimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ spec:
description: The CA chain in base64 format to verify the url.
example: |
YWFhCg==
insecureSkipVerify:
type: boolean
default: false
description: |
If a CA chain isn't provided, this option can be used to turn off TLS certificate checks.
As noted, it is insecure and shouldn't be used in production environments.
checksum:
type: object
description: |
Expand Down Expand Up @@ -198,6 +192,41 @@ spec:
status:
type: object
properties:
conditions:
type: array
description: |
The latest available observations of an object's current state.
items:
type: object
properties:
type:
type: string
description: Type of condition.
status:
type: string
description: Status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- "Unknown"
reason:
type: string
description: Reason for the condition's last transition.
message:
type: string
description: |
Human readable message indicating details about last transition.
lastProbeTime:
type: string
description: Last time the condition was checked.
format: date-time
lastTransitionTime:
type: string
description: Last time the condition transit from one status to another.
format: date-time
required:
- type
- status
downloadSpeed:
type: object
description: |
Expand Down Expand Up @@ -273,9 +302,8 @@ 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 @@ -284,8 +312,7 @@ spec:
"WaitForUserUpload",
"Ready",
"Failed",
"ImageLost",
"Unknown",
"Terminating",
]
progress:
type: string
Expand All @@ -295,24 +322,10 @@ spec:
type: string
description: |
Command for uploading a image for the 'Upload' type.
failureReason:
type: string
description: |
A brief description of the cause of the error.
failureMessage:
type: string
description: |
Detailed description of the error.
attachedToVirtualMachines:
type: array
observedGeneration:
type: integer
description: |
A list of `VirtualMachines` that use the disk
example: [{ name: "VM100" }, { name: "VM200" }]
items:
type: object
properties:
name:
type: string
Represents the .metadata.generation that the status was set based upon.
additionalPrinterColumns:
- name: Phase
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"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/vi"
"github.com/deckhouse/virtualization-controller/pkg/controller/vm"
"github.com/deckhouse/virtualization-controller/pkg/controller/vmop"
virtv2alpha1 "github.com/deckhouse/virtualization/api/core/v1alpha2"
Expand Down Expand Up @@ -187,7 +188,7 @@ func main() {
os.Exit(1)
}

if _, err := controller.NewVMIController(ctx, mgr, log, importerImage, uploaderImage, dvcrSettings); err != nil {
if _, err := vi.NewController(ctx, mgr, log, importerImage, uploaderImage, dvcrSettings); err != nil {
log.Error(err, "")
os.Exit(1)
}
Expand Down
66 changes: 0 additions & 66 deletions images/virtualization-artifact/pkg/common/vmi/util.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"

common "github.com/deckhouse/virtualization-controller/pkg/common"
Expand Down Expand Up @@ -388,3 +389,8 @@ type PodNamer interface {
func FindPod(ctx context.Context, client client.Client, name PodNamer) (*corev1.Pod, error) {
return helper.FetchObject(ctx, name.ImporterPod(), client, &corev1.Pod{})
}

func DeletePod(ctx context.Context, clientset kubernetes.Interface, name PodNamer) error {
key := name.ImporterPod()
return clientset.CoreV1().Pods(key.Namespace).Delete(ctx, key.Name, metav1.DeleteOptions{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ func (i *Ingress) Create(ctx context.Context, client client.Client) (*netv1.Ingr
return ing, nil
}

func CleanupIngress(ctx context.Context, client client.Client, ing *netv1.Ingress) error {
if ing == nil {
return nil
}

return helper.CleanupObject(ctx, client, ing)
}

func (i *Ingress) makeSpec() *netv1.Ingress {
pathTypeExact := netv1.PathTypeExact
path := i.generatePath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ func (p *Pod) Create(ctx context.Context, client client.Client) (*corev1.Pod, er
return pod, nil
}

func CleanupPod(ctx context.Context, client client.Client, pod *corev1.Pod) error {
if pod == nil {
return nil
}

return helper.CleanupObject(ctx, client, pod)
}

func (p *Pod) makeSpec() *corev1.Pod {
pod := &corev1.Pod{
TypeMeta: metav1.TypeMeta{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ func (s *Service) Create(ctx context.Context, client client.Client) (*corev1.Ser
return service, nil
}

func CleanupService(ctx context.Context, client client.Client, service *corev1.Service) error {
if service == nil {
return nil
}

return helper.CleanupObject(ctx, client, service)
}

func (s *Service) makeSpec() *corev1.Service {
service := &corev1.Service{
TypeMeta: metav1.TypeMeta{
Expand Down
Loading

0 comments on commit 6e32105

Please sign in to comment.