Skip to content

Commit cb32a89

Browse files
authored
fix(vmbda): do not change phase to pending if vm is migrating (#1852)
Signed-off-by: Valeriy Khorunzhin <valeriy.khorunzhin@flant.com>
1 parent 958f9c3 commit cb32a89

File tree

6 files changed

+462
-4
lines changed

6 files changed

+462
-4
lines changed

images/virtualization-artifact/pkg/builder/vmbda/vd.go renamed to images/virtualization-artifact/pkg/builder/vmbda/vmbda.go

File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2026 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package internal
18+
19+
import (
20+
"context"
21+
22+
virtv1 "kubevirt.io/api/core/v1"
23+
24+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
25+
)
26+
27+
//go:generate go tool moq -rm -out mock.go . AttachmentService
28+
29+
type AttachmentService interface {
30+
GetVirtualMachine(ctx context.Context, name, namespace string) (*v1alpha2.VirtualMachine, error)
31+
GetKVVMI(ctx context.Context, vm *v1alpha2.VirtualMachine) (*virtv1.VirtualMachineInstance, error)
32+
GetKVVM(ctx context.Context, vm *v1alpha2.VirtualMachine) (*virtv1.VirtualMachine, error)
33+
}

images/virtualization-artifact/pkg/controller/vmbda/internal/mock.go

Lines changed: 189 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2026 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package internal
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
func TestVirtualMachineBlockDeviceAttachment(t *testing.T) {
27+
RegisterFailHandler(Fail)
28+
RunSpecs(t, "VirtualMachineBlockDeviceAttachment Handlers Suite")
29+
}

images/virtualization-artifact/pkg/controller/vmbda/internal/virtual_machine_ready.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ import (
2525
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2626

2727
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
28-
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
2928
"github.com/deckhouse/virtualization/api/core/v1alpha2"
3029
"github.com/deckhouse/virtualization/api/core/v1alpha2/vmbdacondition"
3130
)
3231

3332
type VirtualMachineReadyHandler struct {
34-
attachment *service.AttachmentService
33+
attachment AttachmentService
3534
}
3635

37-
func NewVirtualMachineReadyHandler(attachment *service.AttachmentService) *VirtualMachineReadyHandler {
36+
func NewVirtualMachineReadyHandler(attachment AttachmentService) *VirtualMachineReadyHandler {
3837
return &VirtualMachineReadyHandler{
3938
attachment: attachment,
4039
}
@@ -72,7 +71,7 @@ func (h VirtualMachineReadyHandler) Handle(ctx context.Context, vmbda *v1alpha2.
7271
}
7372

7473
switch vm.Status.Phase {
75-
case v1alpha2.MachineRunning:
74+
case v1alpha2.MachineRunning, v1alpha2.MachineMigrating:
7675
// OK.
7776
case v1alpha2.MachineStopping, v1alpha2.MachineStopped, v1alpha2.MachineStarting:
7877
vmbda.Status.Phase = v1alpha2.BlockDeviceAttachmentPhasePending

0 commit comments

Comments
 (0)