Skip to content

Commit

Permalink
add mtv feature support
Browse files Browse the repository at this point in the history
  • Loading branch information
tupyy committed Sep 4, 2024
1 parent b6419a4 commit 1f44e3f
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 21 deletions.
1 change: 1 addition & 0 deletions internal/featuresupport/feature_support_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var featuresList = map[models.FeatureSupportLevelID]SupportLevelFeature{
models.FeatureSupportLevelIDLSO: (&LsoFeature{}).New(),
models.FeatureSupportLevelIDMCE: (&MceFeature{}).New(),
models.FeatureSupportLevelIDODF: (&OdfFeature{}).New(),
models.FeatureSupportLevelIDMTV: (&MtvFeature{}).New(),

// Platform features
models.FeatureSupportLevelIDNUTANIXINTEGRATION: (&NutanixIntegrationFeature{}).New(),
Expand Down
6 changes: 3 additions & 3 deletions internal/featuresupport/feature_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,19 @@ var _ = Describe("V2ListFeatureSupportLevels API", func() {
When("GetFeatureSupportList 4.12 with Platform", func() {
It(string(*filters.PlatformType)+" "+swag.StringValue(filters.ExternalPlatformName), func() {
list := GetFeatureSupportList("dummy", nil, filters.PlatformType, filters.ExternalPlatformName)
Expect(len(list)).To(Equal(19))
Expect(len(list)).To(Equal(20))
})
})
}

It("GetFeatureSupportList 4.12", func() {
list := GetFeatureSupportList("4.12", nil, nil, nil)
Expect(len(list)).To(Equal(24))
Expect(len(list)).To(Equal(25))
})

It("GetFeatureSupportList 4.13", func() {
list := GetFeatureSupportList("4.13", nil, nil, nil)
Expect(len(list)).To(Equal(24))
Expect(len(list)).To(Equal(25))
})

It("GetCpuArchitectureSupportList 4.12", func() {
Expand Down
54 changes: 54 additions & 0 deletions internal/featuresupport/features_olm_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,57 @@ func (feature *MceFeature) getFeatureActiveLevel(cluster *common.Cluster, _ *mod
}
return activeLevelNotActive
}

// MtvFeature
type MtvFeature struct{}

func (feature *MtvFeature) New() SupportLevelFeature {
return &MtvFeature{}
}

func (feature *MtvFeature) getId() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDMTV
}

func (feature *MtvFeature) GetName() string {
return "OpenShift Migration Toolkit for Virtualization"
}

func (feature *MtvFeature) getSupportLevel(filters SupportLevelFilters) models.SupportLevel {
if !isFeatureCompatibleWithArchitecture(feature, filters.OpenshiftVersion, swag.StringValue(filters.CPUArchitecture)) {
return models.SupportLevelUnavailable
}

if filters.PlatformType != nil && (*filters.PlatformType == models.PlatformTypeVsphere || *filters.PlatformType == models.PlatformTypeNutanix || *filters.PlatformType == models.PlatformTypeNone) {
return models.SupportLevelUnavailable
}

if isNotSupported, err := common.BaseVersionLessThan("4.14", filters.OpenshiftVersion); isNotSupported || err != nil {
return models.SupportLevelUnavailable
}

return models.SupportLevelSupported
}

func (feature *MtvFeature) getIncompatibleArchitectures(_ *string) *[]models.ArchitectureSupportLevelID {
incompatibleArchitecture := []models.ArchitectureSupportLevelID{
models.ArchitectureSupportLevelIDARM64ARCHITECTURE,
models.ArchitectureSupportLevelIDS390XARCHITECTURE,
models.ArchitectureSupportLevelIDPPC64LEARCHITECTURE,
}
return &incompatibleArchitecture
}

func (feature *MtvFeature) getIncompatibleFeatures(string) *[]models.FeatureSupportLevelID {
return &[]models.FeatureSupportLevelID{
models.FeatureSupportLevelIDNUTANIXINTEGRATION,
models.FeatureSupportLevelIDVSPHEREINTEGRATION,
}
}

func (feature *MtvFeature) getFeatureActiveLevel(cluster *common.Cluster, _ *models.InfraEnv, clusterUpdateParams *models.V2ClusterUpdateParams, _ *models.InfraEnvUpdateParams) featureActiveLevel {
if isOperatorActivated("mtv", cluster, clusterUpdateParams) && isOperatorActivated("cnv", cluster, clusterUpdateParams) {
return activeLevelActive
}
return activeLevelNotActive
}
32 changes: 32 additions & 0 deletions internal/featuresupport/features_olm_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,36 @@ var _ = Describe("V2ListFeatureSupportLevels API", func() {
Entry("on S390x is NOT supported", []string{"4.11", "4.13", "4.14", "4.21"}, models.ClusterCPUArchitectureS390x, false),
Entry("on ppc64le is NOT supported", []string{"4.11", "4.13", "4.14", "4.21"}, models.ClusterCPUArchitecturePpc64le, false),
)

Context("Test MTV feature", func() {
DescribeTable("Validate MTV on Architecture", func(ocpVersion []string, cpuArch string, expectedResult bool) {
for _, v := range ocpVersion {
version := v
result := IsFeatureAvailable(models.FeatureSupportLevelIDMTV, version, swag.String(cpuArch))
Expect(result).Should(Equal(expectedResult),
fmt.Sprintf("Feature: %s, OCP version: %s, CpuArch: %s, should be %v", models.FeatureSupportLevelIDMTV, v, cpuArch, expectedResult))
}
},
Entry("on X86 is supported above 4.14", []string{"4.14", "4.21"}, models.ClusterCPUArchitectureX8664, true),
Entry("on X86 is NOT supported", []string{"4.8", "4.11", "4.13"}, models.ClusterCPUArchitectureX8664, false),
Entry("on arm64 is NOT supported", []string{"4.8", "4.11", "4.14", "4.21"}, models.ClusterCPUArchitectureArm64, false),
Entry("on S390x is NOT supported", []string{"4.11", "4.13", "4.14", "4.21"}, models.ClusterCPUArchitectureS390x, false),
Entry("on ppc64le is NOT supported", []string{"4.11", "4.13", "4.14", "4.21"}, models.ClusterCPUArchitecturePpc64le, false),
)

DescribeTable("Validate MTV on platform", func(ocpVersion string, cpuArch string, platformType models.PlatformType, expectedResult models.SupportLevel) {
featureSupportLevels := GetFeatureSupportList(
ocpVersion,
swag.String(cpuArch),
common.PlatformTypePtr(platformType),
nil,
)
Expect(featureSupportLevels[string(models.FeatureSupportLevelIDMTV)]).To(Equal(expectedResult))
},
Entry("on Vsphere", "4.14", common.X86CPUArchitecture, models.PlatformTypeVsphere, models.SupportLevelUnavailable),
Entry("on Nutanix", "4.14", common.X86CPUArchitecture, models.PlatformTypeNutanix, models.SupportLevelUnavailable),
Entry("on None", "4.14", common.X86CPUArchitecture, models.PlatformTypeNone, models.SupportLevelUnavailable),
Entry("on baremetal", "4.14", common.X86CPUArchitecture, models.PlatformTypeBaremetal, models.SupportLevelSupported),
)
})
})
2 changes: 2 additions & 0 deletions internal/featuresupport/features_platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (feature *NutanixIntegrationFeature) getIncompatibleFeatures(string) *[]mod
models.FeatureSupportLevelIDMCE,
models.FeatureSupportLevelIDCNV,
models.FeatureSupportLevelIDPLATFORMMANAGEDNETWORKING,
models.FeatureSupportLevelIDMTV,
}
}

Expand Down Expand Up @@ -234,6 +235,7 @@ func (feature *VsphereIntegrationFeature) getIncompatibleFeatures(openshiftVersi
models.FeatureSupportLevelIDLVM,
models.FeatureSupportLevelIDPLATFORMMANAGEDNETWORKING,
models.FeatureSupportLevelIDCNV,
models.FeatureSupportLevelIDMTV,
}

if isNotSupported, err := common.BaseVersionLessThan("4.13", openshiftVersion); isNotSupported || err != nil {
Expand Down
16 changes: 8 additions & 8 deletions internal/operators/mtv/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
)

func Manifests() (map[string][]byte, []byte, error) {
mtvSubscription, err := subscription(Namespace, Subscription, Source, SourceName)
mtvSubscription, err := getSubscription(Namespace, Subscription, Source, SourceName)
if err != nil {
return nil, nil, err
}

mtvNamespace, err := namespace(Namespace)
mtvNamespace, err := getNamespace(Namespace)
if err != nil {
return nil, nil, err
}

mtvOperatorGroup, err := group(Namespace)
mtvOperatorGroup, err := getOperatorGroup(Namespace)
if err != nil {
return nil, nil, err
}

forklistController, err := controller(Namespace)
forklistController, err := getController(Namespace)
if err != nil {
return nil, nil, err
}
Expand All @@ -48,7 +48,7 @@ func executeTemplate(data map[string]string, contentName, content string) ([]byt
return buf.Bytes(), nil
}

func subscription(namespace, subscription, source, sourceName string) ([]byte, error) {
func getSubscription(namespace, subscription, source, sourceName string) ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": namespace,
"OPERATOR_SUBSCRIPTION_NAME": subscription,
Expand All @@ -58,21 +58,21 @@ func subscription(namespace, subscription, source, sourceName string) ([]byte, e
return executeTemplate(data, "mtvSubscription", mtvSubscription)
}

func namespace(namespace string) ([]byte, error) {
func getNamespace(namespace string) ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": namespace,
}
return executeTemplate(data, "mtvNamespace", mtvNamespace)
}

func group(namespace string) ([]byte, error) {
func getOperatorGroup(namespace string) ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": namespace,
}
return executeTemplate(data, "mtvGroup", mtvGroup)
}

func controller(namespace string) ([]byte, error) {
func getController(namespace string) ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": namespace,
}
Expand Down
8 changes: 4 additions & 4 deletions internal/operators/mtv/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("MTV manifest generation", func() {
})

It("Check Subscription manifest", func() {
subscriptionData, err := subscription(Namespace, Subscription, Source, SourceName)
subscriptionData, err := getSubscription(Namespace, Subscription, Source, SourceName)
Expect(err).To(BeNil())

Expect(extractData(subscriptionData, "metadata.name")).To(Equal(Subscription))
Expand All @@ -53,21 +53,21 @@ var _ = Describe("MTV manifest generation", func() {
})

It("Check namespace manifest", func() {
nsData, err := namespace(Namespace)
nsData, err := getNamespace(Namespace)
Expect(err).To(BeNil())

Expect(extractData(nsData, "metadata.name")).To(Equal(Namespace))
})

It("Check operator group manifest", func() {
opData, err := group(Namespace)
opData, err := getOperatorGroup(Namespace)
Expect(err).To(BeNil())

Expect(extractData(opData, "metadata.namespace")).To(Equal(Namespace))
})

It("Check controller manifest", func() {
controllerData, err := controller(Namespace)
controllerData, err := getController(Namespace)
Expect(err).To(BeNil())

Expect(extractData(controllerData, "metadata.namespace")).To(Equal(Namespace))
Expand Down
11 changes: 5 additions & 6 deletions internal/operators/mtv/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (

var _ = Describe("MTV Operator", func() {
const (
openshiftVersion = "4.10.0"
minCpu = 1
minRamMib = 400
minCpu = 1
minRamMib = 400
)

var (
Expand Down Expand Up @@ -56,7 +55,7 @@ var _ = Describe("MTV Operator", func() {
BeforeEach(func() {
mode := models.ClusterHighAvailabilityModeFull
cluster = common.Cluster{
Cluster: models.Cluster{HighAvailabilityMode: &mode, OpenshiftVersion: openshiftVersion},
Cluster: models.Cluster{HighAvailabilityMode: &mode},
}
})

Expand Down Expand Up @@ -90,7 +89,7 @@ var _ = Describe("MTV Operator", func() {
BeforeEach(func() {
mode := models.ClusterHighAvailabilityModeFull
cluster = common.Cluster{
Cluster: models.Cluster{HighAvailabilityMode: &mode, OpenshiftVersion: openshiftVersion},
Cluster: models.Cluster{HighAvailabilityMode: &mode},
}
})

Expand Down Expand Up @@ -125,7 +124,7 @@ func newRequirements(cpuCores int64, ramMib int64) *models.ClusterHostRequiremen
}

func getInventory(memMiB int64) string {
inventory := models.Inventory{CPU: &models.CPU{Architecture: "x86", Count: 1}, Memory: &models.Memory{UsableBytes: conversions.MibToBytes(memMiB)}}
inventory := models.Inventory{CPU: &models.CPU{Architecture: "x86_64", Count: 1}, Memory: &models.Memory{UsableBytes: conversions.MibToBytes(memMiB)}}
inventoryJSON, err := common.MarshalInventory(&inventory)
Expect(err).ToNot(HaveOccurred())
return inventoryJSON
Expand Down

0 comments on commit 1f44e3f

Please sign in to comment.