diff --git a/api/core/v1alpha2/virtual_machine.go b/api/core/v1alpha2/virtual_machine.go index d658aa185..fdc52a601 100644 --- a/api/core/v1alpha2/virtual_machine.go +++ b/api/core/v1alpha2/virtual_machine.go @@ -274,6 +274,7 @@ type VirtualMachineStatus struct { // List of virtual machine pods. VirtualMachinePods []VirtualMachinePod `json:"virtualMachinePods,omitempty"` Resources ResourcesStatus `json:"resources,omitempty"` + WaitCondition string `json:"waitCondition,omitempty"` } type VirtualMachineStats struct { diff --git a/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go b/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go index d769f5487..f18384357 100644 --- a/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go +++ b/api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go @@ -5146,6 +5146,12 @@ func schema_virtualization_api_core_v1alpha2_VirtualMachineStatus(ref common.Ref Ref: ref("github.com/deckhouse/virtualization/api/core/v1alpha2.ResourcesStatus"), }, }, + "waitCondition": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, }, Required: []string{"phase", "nodeName", "virtualMachineIPAddressName", "ipAddress"}, }, diff --git a/crds/virtualmachines.yaml b/crds/virtualmachines.yaml index f37f86437..58b7b6bc1 100644 --- a/crds/virtualmachines.yaml +++ b/crds/virtualmachines.yaml @@ -1290,6 +1290,11 @@ spec: jsonPath: .status.ipAddress name: IPAddress type: string + - description: The waiting state of the virtual machine + jsonPath: .status.waitCondition + name: Wait condition + priority: 1 + type: string - description: Time of creation resource. jsonPath: .metadata.creationTimestamp name: Age diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go b/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go index 6360cea4d..97bc1c9a5 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go @@ -123,7 +123,7 @@ func (h *SyncKvvmHandler) Handle(ctx context.Context, s state.VirtualMachineStat } // 2. Wait if dependent resources are not ready yet. - if h.isWaiting(changed) { + if wait, cond := h.isWaiting(changed); wait { cbConfApplied. Status(metav1.ConditionFalse). Reason(vmcondition.ReasonConfigurationNotApplied). @@ -132,8 +132,10 @@ func (h *SyncKvvmHandler) Handle(ctx context.Context, s state.VirtualMachineStat "the virtual machine cannot be restarted immediately to apply pending configuration changes " + "as it is awaiting the availability of dependent resources.", ) + changed.Status.WaitCondition = cond return reconcile.Result{RequeueAfter: time.Minute}, nil } + changed.Status.WaitCondition = "" var errs error @@ -187,42 +189,34 @@ func (h *SyncKvvmHandler) Name() string { return nameSyncKvvmHandler } -func (h *SyncKvvmHandler) isWaiting(vm *virtv2.VirtualMachine) bool { +func (h *SyncKvvmHandler) isWaiting(vm *virtv2.VirtualMachine) (bool, string) { for _, c := range vm.Status.Conditions { switch vmcondition.Type(c.Type) { case vmcondition.TypeBlockDevicesReady: if c.Status != metav1.ConditionTrue && c.Reason != vmcondition.ReasonWaitingForProvisioningToPVC.String() { - return true + return true, c.Type } case vmcondition.TypeSnapshotting: if c.Status == metav1.ConditionTrue && c.Reason == vmcondition.ReasonSnapshottingInProgress.String() { - return true + return true, c.Type } case vmcondition.TypeIPAddressReady: if c.Status != metav1.ConditionTrue && c.Reason != vmcondition.ReasonIPAddressNotAssigned.String() { - return true + return true, c.Type } case vmcondition.TypeProvisioningReady, - vmcondition.TypeClassReady: + vmcondition.TypeClassReady, + vmcondition.TypeDiskAttachmentCapacityAvailable, + vmcondition.TypeSizingPolicyMatched: if c.Status != metav1.ConditionTrue { - return true - } - - case vmcondition.TypeDiskAttachmentCapacityAvailable: - if c.Status != metav1.ConditionTrue { - return true - } - - case vmcondition.TypeSizingPolicyMatched: - if c.Status != metav1.ConditionTrue { - return true + return true, c.Type } } } - return false + return false, "" } func (h *SyncKvvmHandler) syncKVVM(ctx context.Context, s state.VirtualMachineState, changes vmchange.SpecChanges) (bool, error) {