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

Fix direct LUN migrations (backport) #902

Merged
merged 3 commits into from
May 19, 2024
Merged
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
15 changes: 9 additions & 6 deletions pkg/controller/plan/adapter/ovirt/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,13 @@ func (r *Builder) LunPersistentVolumes(vmRef ref.Ref) (pvs []core.PersistentVolu
Namespace: r.Plan.Spec.TargetNamespace,
Annotations: map[string]string{
planbase.AnnDiskSource: da.Disk.ID,
"vmID": vm.ID,
"plan": string(r.Plan.UID),
"lun": "true",
},
Labels: map[string]string{
"volume": fmt.Sprintf("%v-%v", vm.Name, da.ID),
"volume": fmt.Sprintf("%v-%v", vm.Name, da.ID),
"vmID": vm.ID,
"plan": string(r.Plan.UID),
"migration": string(r.Migration.UID),
},
},
Spec: core.PersistentVolumeSpec{
Expand Down Expand Up @@ -670,11 +671,13 @@ func (r *Builder) LunPersistentVolumeClaims(vmRef ref.Ref) (pvcs []core.Persiste
Namespace: r.Plan.Spec.TargetNamespace,
Annotations: map[string]string{
planbase.AnnDiskSource: da.Disk.ID,
"vmID": vm.ID,
"plan": string(r.Plan.UID),
"lun": "true",
},
Labels: map[string]string{"migration": r.Migration.Name},
Labels: map[string]string{
"vmID": vm.ID,
"plan": string(r.Plan.UID),
"migration": string(r.Migration.UID),
},
},
Spec: core.PersistentVolumeClaimSpec{
AccessModes: []core.PersistentVolumeAccessMode{
Expand Down
17 changes: 16 additions & 1 deletion pkg/controller/provider/container/ovirt/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "ovirt",
Expand Down Expand Up @@ -29,3 +29,18 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
],
)

go_test(
name = "ovirt_test",
srcs = [
"collector_suite_test.go",
"collector_test.go",
],
embed = [":ovirt"],
deps = [
"//vendor/github.com/onsi/ginkgo",
"//vendor/github.com/onsi/ginkgo/extensions/table",
"//vendor/github.com/onsi/gomega",
"//vendor/github.com/onsi/gomega/types",
],
)
19 changes: 15 additions & 4 deletions pkg/controller/provider/container/ovirt/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,24 @@ func (r *Collector) Version() (major, minor, build, revision string, err error)
if err != nil {
return
}
version := strings.Split(system.Product.Version.FullVersion, ".")
major, minor, build, revision = parseVersion(system.Product.Version.FullVersion)
return
}

func parseVersion(fullVersion string) (major, minor, build, revision string) {
version := strings.Split(fullVersion, ".")
major = version[0]
minor = version[1]
build = version[2]
revision = "0"
if len(version) > 3 {

split := strings.SplitN(version[2], "-", 2)
build = split[0]
switch {
case len(split) > 1:
revision = split[1]
case len(version) > 3:
revision = strings.Split(version[3], "-")[0]
default:
revision = "0"
}
return
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/provider/container/ovirt/collector_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ovirt

import (
"testing"

"github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

// forkliftFailHandler call ginkgo.Fail with printing the additional information
func forkliftFailHandler(message string, callerSkip ...int) {
if len(callerSkip) > 0 {
callerSkip[0]++
}
ginkgo.Fail(message, callerSkip...)
}

func TestTests(t *testing.T) {
defer ginkgo.GinkgoRecover()
RegisterFailHandler(forkliftFailHandler)
ginkgo.RunSpecs(t, "ovirt collector")
}
20 changes: 20 additions & 0 deletions pkg/controller/provider/container/ovirt/collector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ovirt

import (
"strings"

"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
gtypes "github.com/onsi/gomega/types"
)

var _ = ginkgo.Describe("ovirt collector", func() {
table.DescribeTable("should", func(version string, matchVersion gtypes.GomegaMatcher) {
major, minor, build, revision := parseVersion(version)
Expect(strings.Join([]string{major, minor, build, revision}, ".")).Should(matchVersion)
},
table.Entry("get version when revision is in the 3rd element", "4.5.5-1.el8", Equal("4.5.5.1")),
table.Entry("get version when revision is in the 4th element", "4.5.3.4-1.el8ev", Equal("4.5.3.4")),
)
})
Loading