-
Notifications
You must be signed in to change notification settings - Fork 5
chore(vm): propagate pod errors to vm #2125
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
Open
eofff
wants to merge
12
commits into
main
Choose a base branch
from
chore/api/provide-pod-errors-to-vm-and-vmbda
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+64
−47
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5593cd4
unscheduled hotplug pod
dc803ce
failed attachment
a9c1a31
dirty
ab2faa4
resolve self-review
a19e782
fix logic
50bf6b4
fix linter
8d7c395
fix getPodVolumeError
4cba9e1
final
2fa5da8
resolve
4dc4a05
nil guard
2e18cec
fix message
1892fee
capitalize
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,13 @@ import ( | |
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/fields" | ||
| "k8s.io/apimachinery/pkg/labels" | ||
| virtv1 "kubevirt.io/api/core/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
|
||
| "github.com/deckhouse/virtualization-controller/pkg/common/annotations" | ||
| ccpod "github.com/deckhouse/virtualization-controller/pkg/common/pod" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does |
||
| "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" | ||
| "github.com/deckhouse/virtualization-controller/pkg/controller/service" | ||
| "github.com/deckhouse/virtualization-controller/pkg/controller/vm/internal/state" | ||
|
|
@@ -103,7 +103,6 @@ func (h *LifeCycleHandler) Handle(ctx context.Context, s state.VirtualMachineSta | |
| } | ||
|
|
||
| log := logger.FromContext(ctx).With(logger.SlogHandler(nameLifeCycleHandler)) | ||
|
|
||
| h.syncRunning(ctx, changed, kvvm, kvvmi, pod, log) | ||
| return reconcile.Result{}, nil | ||
| } | ||
|
|
@@ -123,10 +122,10 @@ func (h *LifeCycleHandler) syncRunning(ctx context.Context, vm *v1alpha2.Virtual | |
| return | ||
| } | ||
|
|
||
| if volumeError := h.checkPodVolumeErrors(ctx, vm, log); volumeError != nil { | ||
| if volumeError := h.checkVMPodVolumeErrors(ctx, vm, log); volumeError != nil { | ||
| cb.Status(metav1.ConditionFalse). | ||
| Reason(vmcondition.ReasonPodNotStarted). | ||
| Message(volumeError.Error()) | ||
| Message(service.CapitalizeFirstLetter(volumeError.Error())) | ||
| conditions.SetCondition(cb, &vm.Status.Conditions) | ||
| return | ||
| } | ||
|
|
@@ -138,7 +137,7 @@ func (h *LifeCycleHandler) syncRunning(ctx context.Context, vm *v1alpha2.Virtual | |
| if podScheduled.Message != "" { | ||
| cb.Status(metav1.ConditionFalse). | ||
| Reason(vmcondition.ReasonPodNotStarted). | ||
| Message(fmt.Sprintf("%s: %s", podScheduled.Reason, podScheduled.Message)) | ||
| Message(fmt.Sprintf("Could not schedule the virtual machine: %s: %s", podScheduled.Reason, podScheduled.Message)) | ||
| conditions.SetCondition(cb, &vm.Status.Conditions) | ||
| } | ||
|
|
||
|
|
@@ -210,11 +209,12 @@ func (h *LifeCycleHandler) syncRunning(ctx context.Context, vm *v1alpha2.Virtual | |
| } else { | ||
| vm.Status.Node = "" | ||
| } | ||
|
|
||
| cb.Reason(vmcondition.ReasonVirtualMachineNotRunning).Status(metav1.ConditionFalse) | ||
| conditions.SetCondition(cb, &vm.Status.Conditions) | ||
| } | ||
|
|
||
| func (h *LifeCycleHandler) checkPodVolumeErrors(ctx context.Context, vm *v1alpha2.VirtualMachine, log *slog.Logger) error { | ||
| func (h *LifeCycleHandler) checkVMPodVolumeErrors(ctx context.Context, vm *v1alpha2.VirtualMachine, log *slog.Logger) error { | ||
| var podList corev1.PodList | ||
| err := h.client.List(ctx, &podList, &client.ListOptions{ | ||
| Namespace: vm.Namespace, | ||
|
|
@@ -224,51 +224,20 @@ func (h *LifeCycleHandler) checkPodVolumeErrors(ctx context.Context, vm *v1alpha | |
| }) | ||
| if err != nil { | ||
| log.Error("Failed to list pods", "error", err) | ||
| return nil | ||
| return err | ||
| } | ||
|
|
||
| for i := range podList.Items { | ||
| if volumeErr := h.getPodVolumeError(ctx, &podList.Items[i], log); volumeErr != nil { | ||
| return volumeErr | ||
| for _, pod := range podList.Items { | ||
| if !ccpod.IsContainerCreating(&pod) { | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func isContainerCreating(pod *corev1.Pod) bool { | ||
| if pod.Status.Phase != corev1.PodPending { | ||
| return false | ||
| } | ||
| for _, cs := range pod.Status.ContainerStatuses { | ||
| if cs.State.Waiting != nil && cs.State.Waiting.Reason == "ContainerCreating" { | ||
| return true | ||
| lastEvent, err := ccpod.GetLastPodEvent(ctx, h.client, &pod) | ||
| if err != nil { | ||
| log.Error("Failed to get last pod event", "error", err) | ||
| return err | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure you want to show this error on condition? |
||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (h *LifeCycleHandler) getPodVolumeError(ctx context.Context, pod *corev1.Pod, log *slog.Logger) error { | ||
| if !isContainerCreating(pod) { | ||
| return nil | ||
| } | ||
|
|
||
| eventList := &corev1.EventList{} | ||
| err := h.client.List(ctx, eventList, &client.ListOptions{ | ||
| Namespace: pod.Namespace, | ||
| FieldSelector: fields.SelectorFromSet(fields.Set{ | ||
| "involvedObject.name": pod.Name, | ||
| "involvedObject.kind": "Pod", | ||
| }), | ||
| }) | ||
| if err != nil { | ||
| log.Error("Failed to list pod events", "error", err) | ||
| return nil | ||
| } | ||
|
|
||
| for _, e := range eventList.Items { | ||
| if e.Type == corev1.EventTypeWarning && (e.Reason == watcher.ReasonFailedAttachVolume || e.Reason == watcher.ReasonFailedMount) { | ||
| return fmt.Errorf("%s: %s", e.Reason, e.Message) | ||
| if lastEvent != nil && (lastEvent.Reason == watcher.ReasonFailedAttachVolume || lastEvent.Reason == watcher.ReasonFailedMount) { | ||
| return fmt.Errorf("error attaching block devices to virtual machine: %s: %s", lastEvent.Reason, lastEvent.Message) | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.