Skip to content

Commit

Permalink
MGMT-15388: Remove unsupported platforms from the supported-platforms…
Browse files Browse the repository at this point in the history
… endpoint
  • Loading branch information
eliorerz committed Jul 27, 2023
1 parent 83852f8 commit 9570bd8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
16 changes: 13 additions & 3 deletions internal/bminventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,15 +1560,25 @@ func (b *bareMetalInventory) GetClusterSupportedPlatformsInternal(
b.log.Infof("GetSupportedPlatforms - No hosts or cluster is SNO, setting supported-platform to [%s]", models.PlatformTypeNone)
return &[]models.PlatformType{models.PlatformTypeNone}, nil
}
hostSupportedPlatforms, err := b.providerRegistry.GetSupportedProvidersByHosts(cluster.Hosts)
hostsSupportedPlatforms, err := b.providerRegistry.GetSupportedProvidersByHosts(cluster.Hosts)
if err != nil {
err2 := fmt.Errorf("error while checking supported platforms, error: %w", err)
b.log.Error(err2.Error())
return nil, err2
}
var supportedPlatforms []models.PlatformType
for _, platformType := range hostsSupportedPlatforms {
featureId := provider.GetPlatformFeatureID(platformType)
if featureId == "" || featuresupport.IsFeatureAvailable(featureId, cluster.OpenshiftVersion, &cluster.CPUArchitecture) {
supportedPlatforms = append(supportedPlatforms, platformType)
} else {
b.log.Debugf("The platform %s was removed from cluster %s supported-platforms because it is not compatible with "+
"OpenShift version %s and CPU architecture %s", platformType, cluster.ID.String(), cluster.OpenshiftVersion, cluster.CPUArchitecture)
}
}

b.log.Infof("Found %d supported-platforms for cluster %s", len(hostSupportedPlatforms), cluster.ID)
return &hostSupportedPlatforms, nil
b.log.Infof("Found %d supported-platforms for cluster %s", len(supportedPlatforms), cluster.ID)
return &supportedPlatforms, nil
}

func (b *bareMetalInventory) GetClusterSupportedPlatforms(ctx context.Context, params installer.GetClusterSupportedPlatformsParams) middleware.Responder {
Expand Down
53 changes: 53 additions & 0 deletions internal/bminventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12617,6 +12617,11 @@ var _ = Describe("GetSupportedPlatformsFromInventory", func() {
addHost(clusterId, vsphereInventory, role)
}

addNutanixHost := func(clusterId strfmt.UUID, role models.HostRole) {
const vsphereInventory = "{\"system_vendor\": {\"manufacturer\": \"Nutanix\", \"product_name\": \"AHV\", \"serial_number\": \"7A8EB5A3-BB97-462B-9E65-92641F3C790F\", \"virtual\": true}}"
addHost(clusterId, vsphereInventory, role)
}

validateInventory := func(host models.Host, manufacturer string) bool {
var inventory models.Inventory
if err := json.Unmarshal([]byte(host.Inventory), &inventory); err != nil {
Expand Down Expand Up @@ -12675,6 +12680,54 @@ var _ = Describe("GetSupportedPlatformsFromInventory", func() {
platformReplay := bm.GetClusterSupportedPlatforms(ctx, installer.GetClusterSupportedPlatformsParams{ClusterID: clusterID})
Expect(platformReplay).Should(BeAssignableToTypeOf(installer.NewGetClusterSupportedPlatformsOK()))
})

It("Unsupported platform - nutanix", func() {
c.OpenshiftVersion = "4.10"
db.Save(c)

addNutanixHost(clusterID, models.HostRoleMaster)
addNutanixHost(clusterID, models.HostRoleMaster)
addNutanixHost(clusterID, models.HostRoleMaster)
expectedPlatforms := []models.PlatformType{"none", "nutanix", "baremetal"}
mockProviderRegistry.EXPECT().GetSupportedProvidersByHosts(gomock.Any()).Return(expectedPlatforms, nil)
platformReplay := bm.GetClusterSupportedPlatforms(ctx, installer.GetClusterSupportedPlatformsParams{ClusterID: clusterID})
platforms := platformReplay.(*installer.GetClusterSupportedPlatformsOK).Payload
Expect(len(platforms)).Should(Equal(2))
Expect(platforms).To(Not(ContainElement(models.PlatformTypeNutanix)))

// Nutanix is supported platform on OCP > 4.11
c.OpenshiftVersion = "4.12"
db.Save(c)
mockProviderRegistry.EXPECT().GetSupportedProvidersByHosts(gomock.Any()).Return(expectedPlatforms, nil)
platformReplay = bm.GetClusterSupportedPlatforms(ctx, installer.GetClusterSupportedPlatformsParams{ClusterID: clusterID})
platforms = platformReplay.(*installer.GetClusterSupportedPlatformsOK).Payload
Expect(len(platforms)).Should(Equal(3))
Expect(platforms).To(ContainElement(models.PlatformTypeNutanix))
})

It("Unsupported platform - oci", func() {
c.OpenshiftVersion = "4.13"
db.Save(c)

addNutanixHost(clusterID, models.HostRoleMaster)
addNutanixHost(clusterID, models.HostRoleMaster)
addNutanixHost(clusterID, models.HostRoleMaster)
expectedPlatforms := []models.PlatformType{"none", "oci", "baremetal"}
mockProviderRegistry.EXPECT().GetSupportedProvidersByHosts(gomock.Any()).Return(expectedPlatforms, nil)
platformReplay := bm.GetClusterSupportedPlatforms(ctx, installer.GetClusterSupportedPlatformsParams{ClusterID: clusterID})
platforms := platformReplay.(*installer.GetClusterSupportedPlatformsOK).Payload
Expect(len(platforms)).Should(Equal(2))
Expect(platforms).To(Not(ContainElement(models.PlatformTypeOci)))

// OCI is supported platform on OCP > 4.13
c.OpenshiftVersion = "4.14"
db.Save(c)
mockProviderRegistry.EXPECT().GetSupportedProvidersByHosts(gomock.Any()).Return(expectedPlatforms, nil)
platformReplay = bm.GetClusterSupportedPlatforms(ctx, installer.GetClusterSupportedPlatformsParams{ClusterID: clusterID})
platforms = platformReplay.(*installer.GetClusterSupportedPlatformsOK).Payload
Expect(len(platforms)).Should(Equal(3))
Expect(platforms).To(ContainElement(models.PlatformTypeOci))
})
})

func verifyApiError(responder middleware.Responder, expectedHttpStatus int32) {
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,16 @@ func GetActualCreateClusterPlatformParams(platform *models.Platform, userManaged
}
return GetClusterPlatformByHighAvailabilityMode(platform, userManagedNetworking, highAvailabilityMode)
}

func GetPlatformFeatureID(platformType models.PlatformType) models.FeatureSupportLevelID {
switch platformType {
case models.PlatformTypeOci:
return models.FeatureSupportLevelIDEXTERNALPLATFORMOCI
case models.PlatformTypeVsphere:
return models.FeatureSupportLevelIDVSPHEREINTEGRATION
case models.PlatformTypeNutanix:
return models.FeatureSupportLevelIDNUTANIXINTEGRATION
default:
return "" // Return empty string on platform without a feature support ID
}
}

0 comments on commit 9570bd8

Please sign in to comment.