-
Notifications
You must be signed in to change notification settings - Fork 3
feat(vm): Add firmware handler #874
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61ea5b2
add firmware handler
yaroslavborbat f5b8c4b
add metric
yaroslavborbat f7ee533
fix
yaroslavborbat 7749f12
fix
yaroslavborbat a2b1c2e
fix
yaroslavborbat ea52fb8
fix
yaroslavborbat dbe540a
fix
yaroslavborbat 129ea22
fix
yaroslavborbat 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,5 @@ lib | |
| Makefile | ||
| openapi | ||
| *.md | ||
| release.yaml | ||
| werf*.yaml | ||
| NOTES.txt | ||
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
7 changes: 7 additions & 0 deletions
7
api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,13 @@ | ||
| firmware: | ||
| # Don't touch! Generating in CI. | ||
| version: main | ||
| ## Components | ||
| qemu: 9.2.0 | ||
| libvirt: 10.9.0 | ||
| edk2: stable202411 | ||
|
|
||
| module: | ||
| # Don't touch! Generating in CI. | ||
| version: main | ||
| # Should be updated manual. | ||
| firmwareMinSupportedVersion: "v0.17.0" |
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
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
119 changes: 119 additions & 0 deletions
119
images/virtualization-artifact/pkg/controller/vm/internal/firmware.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,119 @@ | ||
| /* | ||
| Copyright 2025 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 internal | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
|
||
| "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" | ||
| "github.com/deckhouse/virtualization-controller/pkg/controller/vm/internal/state" | ||
| "github.com/deckhouse/virtualization-controller/pkg/version" | ||
| virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2" | ||
| "github.com/deckhouse/virtualization/api/core/v1alpha2/vmcondition" | ||
| ) | ||
|
|
||
| const firmwareHandler = "FirmwareHandler" | ||
|
|
||
| func NewFirmwareHandler(firmwareImage string) *FirmwareHandler { | ||
| return &FirmwareHandler{ | ||
| firmwareVersion: version.GetFirmwareVersion(), | ||
| firmwareMinSupportedVersion: version.GetFirmwareMinSupportedVersion(), | ||
| firmwareImage: firmwareImage, | ||
| } | ||
| } | ||
|
|
||
| type FirmwareHandler struct { | ||
| firmwareVersion version.Version | ||
| firmwareMinSupportedVersion version.Version | ||
| firmwareImage string | ||
| } | ||
|
|
||
| func (f FirmwareHandler) Handle(ctx context.Context, s state.VirtualMachineState) (reconcile.Result, error) { | ||
| if s.VirtualMachine().IsEmpty() { | ||
| return reconcile.Result{}, nil | ||
| } | ||
| changed := s.VirtualMachine().Changed() | ||
|
|
||
| kvvmi, err := s.KVVMI(ctx) | ||
| if err != nil { | ||
| return reconcile.Result{}, err | ||
| } | ||
|
|
||
| if kvvmi == nil || kvvmi.Status.LauncherContainerImageVersion == f.firmwareImage { | ||
| // If kvvmi does not exist, update the firmware version, | ||
| // as any newly created kvvmi will use the currently available firmware version. | ||
| changed.Status.FirmwareVersion = f.firmwareVersion.String() | ||
| f.removeCondition(changed) | ||
| return reconcile.Result{}, nil | ||
| } | ||
| if f.needUpdate(changed.Status.FirmwareVersion, kvvmi.Status.LauncherContainerImageVersion) { | ||
| f.addCondition(changed) | ||
| return reconcile.Result{}, nil | ||
| } | ||
|
|
||
| f.removeCondition(changed) | ||
|
|
||
| return reconcile.Result{}, nil | ||
| } | ||
|
|
||
| func (f FirmwareHandler) Name() string { | ||
| return firmwareHandler | ||
| } | ||
|
|
||
| func (f FirmwareHandler) needUpdate(currentVersion, firmwareImage string) bool { | ||
| if currentVersion == "" { | ||
| return true | ||
| } | ||
| currVersion := version.Version(currentVersion) | ||
|
|
||
| if !currVersion.IsValid() { | ||
| return true | ||
| } | ||
|
|
||
| if f.firmwareVersion.Compare(currVersion) == 0 { | ||
| // Update is required if the version is 'main', but the virt-launcher images are different | ||
| if f.firmwareVersion.IsMain() { | ||
| return f.firmwareImage != firmwareImage | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // Update is required if the current version is less than the minimum supported version. | ||
| if currVersion.Compare(f.firmwareMinSupportedVersion) == -1 { | ||
| return true | ||
| } | ||
|
|
||
| // Update is required if the current version is greater than the firmware version | ||
| return currVersion.Compare(f.firmwareVersion) == 1 | ||
| } | ||
|
|
||
| func (f FirmwareHandler) addCondition(changed *virtv2.VirtualMachine) { | ||
| conditions.SetCondition(conditions.NewConditionBuilder(vmcondition.TypeFirmwareUpdateRequired). | ||
| Generation(changed.GetGeneration()). | ||
| Status(metav1.ConditionTrue). | ||
| Reason(vmcondition.ReasonFirmwareUpdateRequired). | ||
| Message("The VM firmware is outdated and not recommended for use by the current version of the module, please migrate or reboot the VM to upgrade to the new firmware version."), | ||
| &changed.Status.Conditions, | ||
| ) | ||
| } | ||
|
|
||
| func (f FirmwareHandler) removeCondition(changed *virtv2.VirtualMachine) { | ||
| conditions.RemoveCondition(vmcondition.TypeFirmwareUpdateRequired, &changed.Status.Conditions) | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Can we guarantee this? What if the virt-controller has been updated, but the virt-operator hasn't yet? In that case, the virtual machine will start with the old firmware, but the version will already be the new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Currently, we cannot guarantee that our controller and KubeVirt are using the same configuration. A possible solution could be to introduce a special wait for the readiness of KubeVirt components during startup.