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(vm): add waitCondition #548

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions api/core/v1alpha2/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crds/virtualmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
Loading