Skip to content

Commit

Permalink
chore(vd): add comments, fix typos
Browse files Browse the repository at this point in the history
Signed-off-by: Isteb4k <[email protected]>
Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k committed Jun 25, 2024
1 parent 035882b commit baa6d93
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crds/clustervirtualimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ spec:
status:
description: Status of the condition, one of True, False, Unknown.
type: string
enum: [ "True", "False", "Unknown" ]
enum: ["True", "False", "Unknown"]
type:
description: Type of condition.
type: string
Expand Down
2 changes: 1 addition & 1 deletion crds/virtualdisk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ spec:
status:
description: Status of the condition, one of True, False, Unknown.
type: string
enum: [ "True", "False", "Unknown" ]
enum: ["True", "False", "Unknown"]
type:
description: Type of condition.
type: string
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualI

cvi.Status.Phase = virtv2.ImageReady

// Unprotect upload time supplements to delete them later.
err = ds.uploaderService.Unprotect(ctx, pod, svc, ing)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type DeletionHandler struct {
sources *source.Sources
}

func NewDeletionHandlerHandler(sources *source.Sources) *DeletionHandler {
func NewDeletionHandler(sources *source.Sources) *DeletionHandler {
return &DeletionHandler{
sources: sources,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (ds BlankDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (boo
condition.Message = ""
}

// Protect Ready Disk and underlying PVC and PV.
err = ds.diskService.Protect(ctx, vd, nil, pvc, pv)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ func (ds HTTPDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (bool
condition.Message = ""
}

// Protect Ready Disk and underlying PVC and PV.
err = ds.diskService.Protect(ctx, vd, nil, pvc, pv)
if err != nil {
return false, err
}

// 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 @@ -96,6 +96,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk)
condition.Message = ""
}

// Protect Ready Disk and underlying PVC and PV.
err = ds.diskService.Protect(ctx, vd, nil, pvc, pv)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (
condition.Message = ""
}

// Protect Ready Disk and underlying PVC and PV.
err = ds.diskService.Protect(ctx, vd, nil, pvc, pv)
if err != nil {
return false, err
}

// 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 @@ -119,11 +119,13 @@ func (ds UploadDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (bo
condition.Message = ""
}

// Protect Ready Disk and underlying PVC and PV.
err = ds.diskService.Protect(ctx, vd, nil, pvc, pv)
if err != nil {
return false, err
}

// Unprotect upload time supplements to delete them later.
err = ds.uploaderService.Unprotect(ctx, pod, svc, ing)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewController(
internal.NewDatasourceReadyHandler(blank, sources),
internal.NewLifeCycleHandler(blank, sources, mgr.GetClient()),
internal.NewResizingHandler(disk),
internal.NewDeletionHandlerHandler(sources),
internal.NewDeletionHandler(sources),
internal.NewAttacheeHandler(mgr.GetClient()),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func (v *Validator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Obj
ready, _ := service.GetCondition(cvicondition.ReadyType, newVD.Status.Conditions)
if newVD.Status.Phase == virtv2.DiskReady || newVD.Status.Phase == virtv2.DiskLost || ready.Status == metav1.ConditionTrue {
if !reflect.DeepEqual(oldVD.Spec.DataSource, newVD.Spec.DataSource) {
return nil, fmt.Errorf("VirtualDisk is in a Ready state: data source cannot be changed")
return nil, fmt.Errorf("VirtualDisk has already been created: data source cannot be changed after disk is created")
}

if !reflect.DeepEqual(oldVD.Spec.PersistentVolumeClaim.StorageClass, newVD.Spec.PersistentVolumeClaim.StorageClass) {
return nil, fmt.Errorf("VirtualDisk is in a Ready state: storge class cannot be changed")
return nil, fmt.Errorf("VirtualDisk has already been created: storage class cannot be changed after disk is created")
}
}

Expand Down

0 comments on commit baa6d93

Please sign in to comment.