diff --git a/internal/featuresupport/feature_support_test.go b/internal/featuresupport/feature_support_test.go index f36676fc14..e514ca2168 100644 --- a/internal/featuresupport/feature_support_test.go +++ b/internal/featuresupport/feature_support_test.go @@ -493,7 +493,7 @@ var _ = Describe("V2ListFeatureSupportLevels API", func() { Expect((&MinimalIso{}).getSupportLevel(filters)).To(Equal(models.SupportLevelSupported)) }) It("Empty support level - platforms", func() { - for _, platform := range []models.PlatformType{models.PlatformTypeOci, models.PlatformTypeVsphere, models.PlatformTypeNutanix, models.PlatformTypeBaremetal, models.PlatformTypeNone} { + for _, platform := range []models.PlatformType{models.PlatformTypeOci, models.PlatformTypeVsphere, models.PlatformTypeNutanix, models.PlatformTypeBaremetal, models.PlatformTypeNone, models.PlatformTypeExternal} { p := platform for _, feature := range []SupportLevelFeature{&VsphereIntegrationFeature{}, &NutanixIntegrationFeature{}, @@ -511,7 +511,7 @@ var _ = Describe("V2ListFeatureSupportLevels API", func() { } }) It("Empty support level - PlatformManagedNetworkingFeature", func() { - for _, platform := range []models.PlatformType{models.PlatformTypeOci, models.PlatformTypeVsphere, models.PlatformTypeNutanix, models.PlatformTypeBaremetal, models.PlatformTypeNone} { + for _, platform := range []models.PlatformType{models.PlatformTypeOci, models.PlatformTypeVsphere, models.PlatformTypeNutanix, models.PlatformTypeBaremetal, models.PlatformTypeNone, models.PlatformTypeExternal} { p := platform feature := &PlatformManagedNetworkingFeature{} filters := SupportLevelFilters{OpenshiftVersion: "", CPUArchitecture: nil, PlatformType: nil} diff --git a/internal/provider/common.go b/internal/provider/common.go index ec81ce3db6..2c493d56b1 100644 --- a/internal/provider/common.go +++ b/internal/provider/common.go @@ -76,7 +76,7 @@ func setExternalDefaultValues(platform *models.Platform, cluster *common.Cluster return } - // set platform type to force the update of the platform in DB later + // set platform type to force the update of the platform later in DB platform.Type = common.PlatformTypePtr(models.PlatformTypeExternal) // we are creating a new cluster, set CloudControllerManager to "" if unset @@ -237,12 +237,10 @@ func checkExternalPlatformUpdate(platform models.Platform, cluster *common.Clust update := false if platform.External.PlatformName != nil && *cluster.Platform.External.PlatformName != *platform.External.PlatformName { update = true - return updatePlatformIsExternal(&platform) } if platform.External.CloudControllerManager != nil && *cluster.Platform.External.CloudControllerManager != *platform.External.CloudControllerManager { update = true - return updatePlatformIsExternal(&platform) } if update { diff --git a/internal/provider/external/external.go b/internal/provider/external/external.go index 617a1996fb..3c55fee00e 100644 --- a/internal/provider/external/external.go +++ b/internal/provider/external/external.go @@ -1,6 +1,10 @@ package external import ( + "github.com/go-openapi/swag" + "github.com/openshift/assisted-service/internal/common" + "github.com/openshift/assisted-service/internal/host/hostutil" + "github.com/openshift/assisted-service/internal/installcfg" "github.com/openshift/assisted-service/internal/provider" "github.com/openshift/assisted-service/models" "github.com/sirupsen/logrus" @@ -23,3 +27,31 @@ func NewExternalProvider(log logrus.FieldLogger) provider.Provider { func (p *externalProvider) Name() models.PlatformType { return models.PlatformTypeExternal } + +func (p *externalProvider) AddPlatformToInstallConfig(cfg *installcfg.InstallerConfigBaremetal, cluster *common.Cluster) error { + cfg.Platform = installcfg.Platform{ + External: &installcfg.ExternalInstallConfigPlatform{ + PlatformName: *cluster.Platform.External.PlatformName, + CloudControllerManager: installcfg.CloudControllerManager(*cluster.Platform.External.CloudControllerManager), + }, + } + + cfg.Networking.MachineNetwork = provider.GetMachineNetworkForUserManagedNetworking(p.Log, cluster) + if cluster.NetworkType != nil { + cfg.Networking.NetworkType = swag.StringValue(cluster.NetworkType) + } + + if common.IsSingleNodeCluster(cluster) { + + if cfg.Networking.NetworkType == "" { + cfg.Networking.NetworkType = models.ClusterNetworkTypeOVNKubernetes + } + + bootstrap := common.GetBootstrapHost(cluster) + if bootstrap != nil { + cfg.BootstrapInPlace = &installcfg.BootstrapInPlace{InstallationDisk: hostutil.GetHostInstallationPath(bootstrap)} + } + } + + return nil +} diff --git a/internal/provider/external/installConfig.go b/internal/provider/external/installConfig.go deleted file mode 100644 index fd09aabab5..0000000000 --- a/internal/provider/external/installConfig.go +++ /dev/null @@ -1,38 +0,0 @@ -package external - -import ( - "github.com/go-openapi/swag" - "github.com/openshift/assisted-service/internal/common" - "github.com/openshift/assisted-service/internal/host/hostutil" - "github.com/openshift/assisted-service/internal/installcfg" - "github.com/openshift/assisted-service/internal/provider" - "github.com/openshift/assisted-service/models" -) - -func (p baseExternalProvider) AddPlatformToInstallConfig(cfg *installcfg.InstallerConfigBaremetal, cluster *common.Cluster) error { - cfg.Platform = installcfg.Platform{ - External: &installcfg.ExternalInstallConfigPlatform{ - PlatformName: string(p.Provider.Name()), - CloudControllerManager: installcfg.CloudControllerManagerTypeExternal, - }, - } - - cfg.Networking.MachineNetwork = provider.GetMachineNetworkForUserManagedNetworking(p.Log, cluster) - if cluster.NetworkType != nil { - cfg.Networking.NetworkType = swag.StringValue(cluster.NetworkType) - } - - if common.IsSingleNodeCluster(cluster) { - - if cfg.Networking.NetworkType == "" { - cfg.Networking.NetworkType = models.ClusterNetworkTypeOVNKubernetes - } - - bootstrap := common.GetBootstrapHost(cluster) - if bootstrap != nil { - cfg.BootstrapInPlace = &installcfg.BootstrapInPlace{InstallationDisk: hostutil.GetHostInstallationPath(bootstrap)} - } - } - - return nil -} diff --git a/internal/provider/external/oci.go b/internal/provider/external/oci.go index 9d46346337..faf0e61230 100644 --- a/internal/provider/external/oci.go +++ b/internal/provider/external/oci.go @@ -3,7 +3,10 @@ package external import ( "fmt" + "github.com/go-openapi/swag" "github.com/openshift/assisted-service/internal/common" + "github.com/openshift/assisted-service/internal/host/hostutil" + "github.com/openshift/assisted-service/internal/installcfg" "github.com/openshift/assisted-service/internal/provider" "github.com/openshift/assisted-service/models" "github.com/sirupsen/logrus" @@ -55,3 +58,31 @@ func (p *ociExternalProvider) AreHostsSupported(hosts []*models.Host) (bool, err } return true, nil } + +func (p *ociExternalProvider) AddPlatformToInstallConfig(cfg *installcfg.InstallerConfigBaremetal, cluster *common.Cluster) error { + cfg.Platform = installcfg.Platform{ + External: &installcfg.ExternalInstallConfigPlatform{ + PlatformName: string(p.Provider.Name()), + CloudControllerManager: installcfg.CloudControllerManagerTypeExternal, + }, + } + + cfg.Networking.MachineNetwork = provider.GetMachineNetworkForUserManagedNetworking(p.Log, cluster) + if cluster.NetworkType != nil { + cfg.Networking.NetworkType = swag.StringValue(cluster.NetworkType) + } + + if common.IsSingleNodeCluster(cluster) { + + if cfg.Networking.NetworkType == "" { + cfg.Networking.NetworkType = models.ClusterNetworkTypeOVNKubernetes + } + + bootstrap := common.GetBootstrapHost(cluster) + if bootstrap != nil { + cfg.BootstrapInPlace = &installcfg.BootstrapInPlace{InstallationDisk: hostutil.GetHostInstallationPath(bootstrap)} + } + } + + return nil +} diff --git a/internal/provider/registry/registry_test.go b/internal/provider/registry/registry_test.go index 719ebccde6..ba23117218 100644 --- a/internal/provider/registry/registry_test.go +++ b/internal/provider/registry/registry_test.go @@ -422,6 +422,61 @@ var _ = Describe("Test AddPlatformToInstallConfig", func() { Expect(err).To(BeNil()) Expect(cfg.Platform.External).ToNot(BeNil()) Expect(cfg.Platform.External.PlatformName).To(Equal(string(models.PlatformTypeOci))) + Expect(string(cfg.Platform.External.CloudControllerManager)).To(Equal(models.PlatformExternalCloudControllerManagerExternal)) + }) + }) + + Context("external", func() { + It("should set platform name to external - CCM is empty", func() { + platformName := "platform-name" + cloudControllerManager := models.PlatformExternalCloudControllerManagerEmpty + + cfg := getInstallerConfigBaremetal() + hosts := make([]*models.Host, 0) + hosts = append(hosts, createHost(true, models.HostStatusKnown, getBaremetalInventoryStr("hostname0", "bootMode", true, false))) + hosts = append(hosts, createHost(true, models.HostStatusKnown, getBaremetalInventoryStr("hostname1", "bootMode", true, false))) + hosts = append(hosts, createHost(true, models.HostStatusKnown, getBaremetalInventoryStr("hostname2", "bootMode", true, false))) + hosts = append(hosts, createHost(false, models.HostStatusKnown, getBaremetalInventoryStr("hostname3", "bootMode", true, false))) + hosts = append(hosts, createHost(false, models.HostStatusKnown, getBaremetalInventoryStr("hostname4", "bootMode", true, false))) + cluster := createClusterFromHosts(hosts) + cluster.Platform = &models.Platform{ + Type: common.PlatformTypePtr(models.PlatformTypeExternal), + External: &models.PlatformExternal{ + PlatformName: &platformName, + CloudControllerManager: &cloudControllerManager, + }, + } + err := providerRegistry.AddPlatformToInstallConfig(models.PlatformTypeExternal, &cfg, &cluster) + Expect(err).To(BeNil()) + Expect(cfg.Platform.External).ToNot(BeNil()) + Expect(cfg.Platform.External.PlatformName).To(Equal(platformName)) + Expect(string(cfg.Platform.External.CloudControllerManager)).To(Equal(cloudControllerManager)) + }) + + It("should set platform name to external - CCM=External", func() { + platformName := "platform-name" + cloudControllerManager := models.PlatformExternalCloudControllerManagerExternal + + cfg := getInstallerConfigBaremetal() + hosts := make([]*models.Host, 0) + hosts = append(hosts, createHost(true, models.HostStatusKnown, getBaremetalInventoryStr("hostname0", "bootMode", true, false))) + hosts = append(hosts, createHost(true, models.HostStatusKnown, getBaremetalInventoryStr("hostname1", "bootMode", true, false))) + hosts = append(hosts, createHost(true, models.HostStatusKnown, getBaremetalInventoryStr("hostname2", "bootMode", true, false))) + hosts = append(hosts, createHost(false, models.HostStatusKnown, getBaremetalInventoryStr("hostname3", "bootMode", true, false))) + hosts = append(hosts, createHost(false, models.HostStatusKnown, getBaremetalInventoryStr("hostname4", "bootMode", true, false))) + cluster := createClusterFromHosts(hosts) + cluster.Platform = &models.Platform{ + Type: common.PlatformTypePtr(models.PlatformTypeExternal), + External: &models.PlatformExternal{ + PlatformName: &platformName, + CloudControllerManager: &cloudControllerManager, + }, + } + err := providerRegistry.AddPlatformToInstallConfig(models.PlatformTypeExternal, &cfg, &cluster) + Expect(err).To(BeNil()) + Expect(cfg.Platform.External).ToNot(BeNil()) + Expect(cfg.Platform.External.PlatformName).To(Equal(platformName)) + Expect(string(cfg.Platform.External.CloudControllerManager)).To(Equal(cloudControllerManager)) }) }) }) @@ -463,6 +518,14 @@ var _ = Describe("Test SetPlatformUsages", func() { Expect(err).To(BeNil()) }) }) + + Context("external", func() { + It("success", func() { + usageApi.EXPECT().Add(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() + err := providerRegistry.SetPlatformUsages(models.PlatformTypeExternal, nil, usageApi) + Expect(err).To(BeNil()) + }) + }) }) func createHost(isMaster bool, state string, inventory string) *models.Host {