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 Oct 8, 2024
1 parent b6419a4 commit eaa8173
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 25 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
9 changes: 8 additions & 1 deletion internal/operators/mtv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ const (
Source = "redhat-operators"
SourceName = "mtv-operator"
MtvMinOpenshiftVersion = "4.14.0"

// Memory value provided in MiB
MasterMemory int64 = 1024
MasterCPU int64 = 1
// Memory value provided in MiB
WorkerMemory int64 = 1024
WorkerCPU int64 = 1
)

type Config struct {
MtvCPUPerHost int64 `envconfig:"MTV_CPU_PER_HOST" default:"1"`
MtvMemoryPerHostMiB int64 `envconfig:"MTV_MEMORY_PER_HOST_MIB" default:"400"`
MtvMemoryPerHostMiB int64 `envconfig:"MTV_MEMORY_PER_HOST_MIB" default:"1024"`
}
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
13 changes: 6 additions & 7 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 = 1024
)

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,12 +89,12 @@ 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},
}
})

It("host should be valid", func() {
host := models.Host{Role: models.HostRoleMaster, Inventory: getInventory(int64(400))}
host := models.Host{Role: models.HostRoleMaster, Inventory: getInventory(int64(1024))}

result, err := operator.ValidateHost(context.TODO(), &cluster, &host, nil)
Expect(err).To(BeNil())
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
14 changes: 13 additions & 1 deletion subsystem/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/openshift/assisted-service/internal/operators/lso"
"github.com/openshift/assisted-service/internal/operators/lvm"
"github.com/openshift/assisted-service/internal/operators/mce"
"github.com/openshift/assisted-service/internal/operators/mtv"
"github.com/openshift/assisted-service/internal/operators/odf"
"github.com/openshift/assisted-service/internal/usage"
"github.com/openshift/assisted-service/models"
Expand Down Expand Up @@ -3704,6 +3705,14 @@ var _ = Describe("Preflight Cluster Requirements", func() {
CPUCores: mce.MinimumCPU,
RAMMib: conversions.GibToMib(mce.MinimumMemory),
}
workerMTVRequirements = models.ClusterHostRequirementsDetails{
CPUCores: mtv.WorkerCPU,
RAMMib: conversions.GibToMib(mtv.WorkerMemory),
}
masterMTVRequirements = models.ClusterHostRequirementsDetails{
CPUCores: mtv.MasterCPU,
RAMMib: conversions.GibToMib(mtv.MasterMemory),
}
)

BeforeEach(func() {
Expand Down Expand Up @@ -3731,7 +3740,7 @@ var _ = Describe("Preflight Cluster Requirements", func() {
},
}
Expect(*requirements.Ocp).To(BeEquivalentTo(expectedOcpRequirements))
Expect(requirements.Operators).To(HaveLen(5))
Expect(requirements.Operators).To(HaveLen(6))
for _, op := range requirements.Operators {
switch op.OperatorName {
case lso.Operator.Name:
Expand All @@ -3746,6 +3755,9 @@ var _ = Describe("Preflight Cluster Requirements", func() {
case mce.Operator.Name:
Expect(*op.Requirements.Master.Quantitative).To(BeEquivalentTo(masterMCERequirements))
Expect(*op.Requirements.Worker.Quantitative).To(BeEquivalentTo(workerMCERequirements))
case mtv.Operator.Name:
Expect(*op.Requirements.Master.Quantitative).To(BeEquivalentTo(masterMTVRequirements))
Expect(*op.Requirements.Worker.Quantitative).To(BeEquivalentTo(workerMTVRequirements))
case lvm.Operator.Name:
continue // lvm operator is tested separately
default:
Expand Down
3 changes: 2 additions & 1 deletion subsystem/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/openshift/assisted-service/internal/operators/lso"
"github.com/openshift/assisted-service/internal/operators/lvm"
"github.com/openshift/assisted-service/internal/operators/mce"
"github.com/openshift/assisted-service/internal/operators/mtv"
"github.com/openshift/assisted-service/internal/operators/odf"
"github.com/openshift/assisted-service/models"
)
Expand All @@ -36,7 +37,7 @@ var _ = Describe("Operators endpoint tests", func() {
reply, err := userBMClient.Operators.V2ListSupportedOperators(context.TODO(), opclient.NewV2ListSupportedOperatorsParams())

Expect(err).ToNot(HaveOccurred())
Expect(reply.GetPayload()).To(ConsistOf(odf.Operator.Name, lso.Operator.Name, cnv.Operator.Name, lvm.Operator.Name, mce.Operator.Name))
Expect(reply.GetPayload()).To(ConsistOf(odf.Operator.Name, lso.Operator.Name, cnv.Operator.Name, lvm.Operator.Name, mce.Operator.Name, mtv.Operator.Name))
})

It("should provide operator properties", func() {
Expand Down

0 comments on commit eaa8173

Please sign in to comment.