-
Notifications
You must be signed in to change notification settings - Fork 5
fix(vm): show CSI and volume errors in VM status #1766
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
loktev-d
wants to merge
14
commits into
main
Choose a base branch
from
fix/vm/show-csi-volume-errors
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.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
175643f
wip
loktev-d e56f6fd
Merge branch 'main' into fix/vm/show-csi-volume-errors
loktev-d c88e8fa
wip
loktev-d 5c89d65
wip
loktev-d 964dd92
wip
loktev-d a9030a6
Merge branch 'main' into fix/vm/show-csi-volume-errors
loktev-d 96097c8
wip
loktev-d a991b8d
wip
loktev-d 4a4ecdd
wip
loktev-d f4c4459
Merge branch 'main' into fix/vm/show-csi-volume-errors
loktev-d 599bc00
Merge branch 'main' into fix/vm/show-csi-volume-errors
loktev-d 8234d9d
resolve comments
loktev-d 1aac678
Merge branch 'main' into fix/vm/show-csi-volume-errors
loktev-d 43c6f1d
Merge branch 'main' into fix/vm/show-csi-volume-errors
loktev-d 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
42 changes: 42 additions & 0 deletions
42
images/virtualization-artifact/pkg/controller/indexer/event_indexer.go
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| Copyright 2026 Flant JSC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package indexer | ||
|
|
||
| import ( | ||
| corev1 "k8s.io/api/core/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| func IndexEventByInvolvedObjectName() (obj client.Object, field string, extractValue client.IndexerFunc) { | ||
| return &corev1.Event{}, IndexFieldEventByInvolvedObjectName, func(object client.Object) []string { | ||
| event, ok := object.(*corev1.Event) | ||
| if !ok || event == nil { | ||
| return nil | ||
| } | ||
| return []string{event.InvolvedObject.Name} | ||
| } | ||
| } | ||
|
|
||
| func IndexEventByInvolvedObjectKind() (obj client.Object, field string, extractValue client.IndexerFunc) { | ||
| return &corev1.Event{}, IndexFieldEventByInvolvedObjectKind, func(object client.Object) []string { | ||
| event, ok := object.(*corev1.Event) | ||
| if !ok || event == nil { | ||
| return nil | ||
| } | ||
| return []string{event.InvolvedObject.Kind} | ||
| } | ||
| } |
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
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
104 changes: 104 additions & 0 deletions
104
images/virtualization-artifact/pkg/controller/vm/internal/watcher/volumeevent_watcher.go
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| Copyright 2026 Flant JSC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package watcher | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| virtv1 "kubevirt.io/api/core/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller" | ||
| "sigs.k8s.io/controller-runtime/pkg/event" | ||
| "sigs.k8s.io/controller-runtime/pkg/handler" | ||
| "sigs.k8s.io/controller-runtime/pkg/manager" | ||
| "sigs.k8s.io/controller-runtime/pkg/predicate" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
| "sigs.k8s.io/controller-runtime/pkg/source" | ||
| ) | ||
|
|
||
| const ( | ||
| ReasonFailedAttachVolume = "FailedAttachVolume" | ||
| ReasonFailedMount = "FailedMount" | ||
| ) | ||
|
|
||
| func NewVolumeEventWatcher(client client.Client) *VolumeEventWatcher { | ||
| return &VolumeEventWatcher{ | ||
| client: client, | ||
| } | ||
| } | ||
|
|
||
| type VolumeEventWatcher struct { | ||
| client client.Client | ||
| } | ||
|
|
||
| func (w *VolumeEventWatcher) Watch(mgr manager.Manager, ctr controller.Controller) error { | ||
| if err := ctr.Watch( | ||
| source.Kind( | ||
| mgr.GetCache(), | ||
| &corev1.Event{}, | ||
| handler.TypedEnqueueRequestsFromMapFunc(func(ctx context.Context, e *corev1.Event) []reconcile.Request { | ||
| if e.InvolvedObject.Kind != "Pod" { | ||
| return nil | ||
| } | ||
|
|
||
| if e.Reason != ReasonFailedAttachVolume && e.Reason != ReasonFailedMount { | ||
| return nil | ||
| } | ||
|
|
||
| pod := &corev1.Pod{} | ||
| if err := w.client.Get(ctx, types.NamespacedName{ | ||
| Name: e.InvolvedObject.Name, | ||
| Namespace: e.InvolvedObject.Namespace, | ||
| }, pod); err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| vmName, hasLabel := pod.GetLabels()[virtv1.VirtualMachineNameLabel] | ||
| if !hasLabel { | ||
| return nil | ||
| } | ||
|
|
||
| return []reconcile.Request{ | ||
| { | ||
| NamespacedName: types.NamespacedName{ | ||
| Name: vmName, | ||
| Namespace: pod.GetNamespace(), | ||
| }, | ||
| }, | ||
| } | ||
| }), | ||
| predicate.TypedFuncs[*corev1.Event]{ | ||
| CreateFunc: func(e event.TypedCreateEvent[*corev1.Event]) bool { | ||
| return e.Object.Type == corev1.EventTypeWarning && | ||
| (e.Object.Reason == ReasonFailedAttachVolume || e.Object.Reason == ReasonFailedMount) | ||
| }, | ||
| UpdateFunc: func(e event.TypedUpdateEvent[*corev1.Event]) bool { | ||
| return false | ||
| }, | ||
| DeleteFunc: func(e event.TypedDeleteEvent[*corev1.Event]) bool { | ||
| return false | ||
| }, | ||
| }, | ||
| ), | ||
| ); err != nil { | ||
| return fmt.Errorf("error setting watch on Event: %w", err) | ||
| } | ||
| return nil | ||
| } |
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
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.