Skip to content

Commit

Permalink
[release-ocm-2.8] MGMT-15034: MGMT-15047: use installer to deploy on …
Browse files Browse the repository at this point in the history
…external platform (#5490)

* MGMT-15034: Fix patch of infrastructure CR with external platform (#5312)

Patch directly the Infrastructure CR from PostCreateManifestsHook
function which makes it easier to test.

This part of the code is a workaround until the openshift installer
supports external platform.

* MGMT-15047: use installer to deploy on external platform (#5381)

Use the installer to deploy the external platform, and cleanup the
previous hack.
Remove the feature set as the external platform is now stable.
  • Loading branch information
adriengentil committed Sep 14, 2023
1 parent ad21c9e commit 4156577
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 50 deletions.
5 changes: 5 additions & 0 deletions internal/installcfg/installcfg.go
Expand Up @@ -11,6 +11,7 @@ type Platform struct {
None *PlatformNone `yaml:"none,omitempty"`
Vsphere *VsphereInstallConfigPlatform `yaml:"vsphere,omitempty"`
Nutanix *NutanixInstallConfigPlatform `yaml:"nutanix,omitempty"`
External *ExternalInstallConfigPlatform `yaml:"external,omitempty"`
}

type Host struct {
Expand Down Expand Up @@ -127,6 +128,10 @@ type NutanixPrismElement struct {
Name string `yaml:"name"`
}

type ExternalInstallConfigPlatform struct {
PlatformName string `yaml:"platformName"`
}

type PlatformNone struct {
}

Expand Down
13 changes: 13 additions & 0 deletions internal/provider/external/external_suite_test.go
@@ -0,0 +1,13 @@
package external

import (
"testing"

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

func TestProviderRegistry(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "ProviderExternal test")
}
40 changes: 0 additions & 40 deletions internal/provider/external/ignition.go
@@ -1,53 +1,13 @@
package external

import (
"fmt"
"os"
"path/filepath"

"github.com/openshift/assisted-service/internal/common"
)

// Workaround as openshift installer does not support the external platform.
// The trick is to generate the manifests with platform=none and patch
// the insfrastructure object with the external platform.
const (
clusterInfraPatchTemplate = `---
- op: replace
path: /spec/platformSpec
value:
type: External
external:
platformName: %s
- op: replace
path: /status/platform
value: External
- op: replace
path: /status/platformStatus
value:
type: External
external:
cloudControllerManager:
state: External
`
)

func (p externalProvider) PreCreateManifestsHook(cluster *common.Cluster, envVars *[]string, workDir string) error {
return nil
}

func (p externalProvider) PostCreateManifestsHook(cluster *common.Cluster, envVars *[]string, workDir string) error {
p.Log.Info("Patching infrastructure object")

platformName := string(p.platformType)
clusterInfraPatch := fmt.Sprintf(clusterInfraPatchTemplate, platformName)

clusterInfraPatchPath := filepath.Join(workDir, "manifests", "cluster-infrastructure-02-config.yml.patch_01_configure_external_platform")
err := os.WriteFile(clusterInfraPatchPath, []byte(clusterInfraPatch), 0600)
if err != nil {
p.Log.Error("Couldn't write infrastructure patch %v", clusterInfraPatchPath)
return err
}

return nil
}
9 changes: 3 additions & 6 deletions internal/provider/external/installConfig.go
Expand Up @@ -2,7 +2,6 @@ package external

import (
"github.com/go-openapi/swag"
configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/host/hostutil"
"github.com/openshift/assisted-service/internal/installcfg"
Expand All @@ -11,14 +10,12 @@ import (
)

func (p externalProvider) AddPlatformToInstallConfig(cfg *installcfg.InstallerConfigBaremetal, cluster *common.Cluster) error {
// workaround until openshift installer supports external platform
cfg.Platform = installcfg.Platform{
None: &installcfg.PlatformNone{},
External: &installcfg.ExternalInstallConfigPlatform{
PlatformName: string(p.Name()),
},
}

// Enable feature set "TechPreviewNoUpgrade" in order to access External platform feature
cfg.FeatureSet = configv1.TechPreviewNoUpgrade

cfg.Networking.MachineNetwork = provider.GetMachineNetworkForUserManagedNetworking(p.Log, cluster)
if cluster.NetworkType != nil {
cfg.Networking.NetworkType = swag.StringValue(cluster.NetworkType)
Expand Down
7 changes: 3 additions & 4 deletions internal/provider/registry/registry_test.go
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/google/uuid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/installcfg"
"github.com/openshift/assisted-service/internal/provider/vsphere"
Expand Down Expand Up @@ -397,7 +396,7 @@ var _ = Describe("Test AddPlatformToInstallConfig", func() {
})

Context("oci", func() {
It("should set platform to none and featureset to TechPreviewNoUpgrade", func() {
It("should set platform name to oci", func() {
cfg := getInstallerConfigBaremetal()
hosts := make([]*models.Host, 0)
hosts = append(hosts, createHost(true, models.HostStatusKnown, getBaremetalInventoryStr("hostname0", "bootMode", true, false)))
Expand All @@ -408,8 +407,8 @@ var _ = Describe("Test AddPlatformToInstallConfig", func() {
cluster := createClusterFromHosts(hosts)
err := providerRegistry.AddPlatformToInstallConfig(models.PlatformTypeOci, &cfg, &cluster)
Expect(err).To(BeNil())
Expect(cfg.Platform.None).ToNot(BeNil())
Expect(cfg.FeatureSet).To(Equal(configv1.TechPreviewNoUpgrade))
Expect(cfg.Platform.External).ToNot(BeNil())
Expect(cfg.Platform.External.PlatformName).To(Equal(string(models.PlatformTypeOci)))
})
})
})
Expand Down

0 comments on commit 4156577

Please sign in to comment.