Skip to content

Commit

Permalink
Merge branch 'feat/api/vd-vi-wait-in-pending-until-sc-ready' into tes…
Browse files Browse the repository at this point in the history
…t/api/tests-for-vd-vi-lifecycle-and-storageclassready-handlers
  • Loading branch information
eofff authored Nov 12, 2024
2 parents 785bd23 + 8a06876 commit 7384273
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/core/v1alpha2/vicondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const (
Lost ReadyReason = "PVCLost"

// StorageClassReady indicates that the chosen StorageClass exists.
StorageClassReady StorageClassReadyReason = "StorageClassReady"
// StorageClassNotFound indicates that the chosen StorageClass not found.
StorageClassReady StorageClassReadyReason = "StorageClassReady"
StorageClassNotFound StorageClassReadyReason = "StorageClassNotFound"
// DVCRTypeUsed indicates that the DVCR provisioning chosen.
DVCRTypeUsed StorageClassReadyReason = "DVCRTypeUsed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (r
}

if readyCondition.Status != metav1.ConditionTrue && storageClassReadyCondition.Status != metav1.ConditionTrue {
defer func() {
readyCondition.Status = metav1.ConditionFalse
readyCondition.Reason = vdcondition.StorageClassNotReady
readyCondition.Message = "Storage class is not ready, please read the StorageClassReady condition state."
service.SetCondition(readyCondition, &vd.Status.Conditions)
}()
readyCondition.Status = metav1.ConditionFalse
readyCondition.Reason = vdcondition.StorageClassNotReady
readyCondition.Message = "Storage class is not ready, please read the StorageClassReady condition state."
service.SetCondition(readyCondition, &vd.Status.Conditions)
}

if readyCondition.Status != metav1.ConditionTrue && storageClassReadyCondition.Status != metav1.ConditionTrue && vd.Status.StorageClassName != "" {
Expand All @@ -118,7 +116,6 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (r
ObservedGeneration: vd.Status.ObservedGeneration,
StorageClassName: vd.Status.StorageClassName,
}
vd.Status.Phase = virtv2.DiskPending

_, err := h.sources.CleanUp(ctx, vd)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

cc "github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
Expand All @@ -47,14 +48,15 @@ func (h StorageClassReadyHandler) Handle(ctx context.Context, vd *virtv2.Virtual
condition = metav1.Condition{
Type: vdcondition.StorageClassReadyType,
Status: metav1.ConditionUnknown,
Reason: conditions.ReasonUnknown.String(),
}
}

defer func() { service.SetCondition(condition, &vd.Status.Conditions) }()

if vd.DeletionTimestamp != nil {
condition.Status = metav1.ConditionUnknown
condition.Reason = ""
condition.Reason = conditions.ReasonUnknown.String()
condition.Message = ""
return reconcile.Result{}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vi *virtv2.VirtualImage) (
ObservedGeneration: vi.Status.ObservedGeneration,
StorageClassName: vi.Status.StorageClassName,
}
vi.Status.Phase = virtv2.ImagePending

_, err := h.sources.CleanUp(ctx, vi)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

cc "github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
Expand Down Expand Up @@ -53,6 +54,7 @@ func (h StorageClassReadyHandler) Handle(ctx context.Context, vi *virtv2.Virtual
if !ok {
condition = metav1.Condition{
Type: vicondition.StorageClassReadyType,
Reason: conditions.ReasonUnknown.String(),
Status: metav1.ConditionUnknown,
}
}
Expand All @@ -61,7 +63,7 @@ func (h StorageClassReadyHandler) Handle(ctx context.Context, vi *virtv2.Virtual

if vi.DeletionTimestamp != nil {
condition.Status = metav1.ConditionUnknown
condition.Reason = ""
condition.Reason = conditions.ReasonUnknown.String()
condition.Message = ""
return reconcile.Result{}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func (h *SyncKvvmHandler) isWaiting(vm *virtv2.VirtualMachine) bool {
if c.Status != metav1.ConditionTrue {
return true
}

case vmcondition.TypeSizingPolicyMatched:
if c.Status != metav1.ConditionTrue {
return true
}
}
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func SetupController(
internal.NewFilesystemHandler(),
internal.NewSnapshottingHandler(client),
internal.NewPodHandler(client),
internal.NewSizePolicyHandler(),
internal.NewSyncKvvmHandler(dvcrSettings, client, recorder),
internal.NewSyncMetadataHandler(client),
internal.NewLifeCycleHandler(client, recorder),
internal.NewStatisticHandler(client),
internal.NewSizePolicyHandler(),
}
r := NewReconciler(client, handlers...)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (h *BlockDeviceLimiter) Handle(ctx context.Context, vmbda *virtv2.VirtualMa
return reconcile.Result{}, nil
}

if blockDeviceAttachedCount > common.VmBlockDeviceAttachedLimit {
if blockDeviceAttachedCount <= common.VmBlockDeviceAttachedLimit {
cb.
Status(metav1.ConditionTrue).
Reason(vmbdacondition.CapacityAvailable).
Expand Down

0 comments on commit 7384273

Please sign in to comment.