Skip to content

Commit

Permalink
MGMT-15047: use installer to deploy on external platform
Browse files Browse the repository at this point in the history
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 Jul 24, 2023
1 parent 6a583ef commit 4a29b3d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 177 deletions.
5 changes: 5 additions & 0 deletions internal/installcfg/installcfg.go
Original file line number Diff line number Diff line change
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
53 changes: 0 additions & 53 deletions internal/provider/external/ignition.go
Original file line number Diff line number Diff line change
@@ -1,66 +1,13 @@
package external

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

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

// 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 {

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

p.Log.Infof("Patching Infrastructure CR with external platform: platformName=%s", platformName)

infraManifest := filepath.Join(workDir, "manifests", "cluster-infrastructure-02-config.yml")
data, err := os.ReadFile(infraManifest)
if err != nil {
return errors.Wrapf(err, "failed to read Infrastructure Manifest \"%s\"", infraManifest)
}
p.Log.Infof("read the infrastructure manifest at %s", infraManifest)

data, err = common.ApplyYamlPatch(data, []byte(clusterInfraPatch))
if err != nil {
return errors.Wrapf(err, "failed to patch Infrastructure Manifest \"%s\"", infraManifest)
}
p.Log.Infof("applied the yaml patch to the infrastructure manifest at %s: \n %s", infraManifest, string(data[:]))

err = os.WriteFile(infraManifest, data, 0600)
if err != nil {
return errors.Wrapf(err, "failed to write Infrastructure Manifest \"%s\"", infraManifest)
}
p.Log.Infof("wrote the resulting infrastructure manifest at %s", infraManifest)

return nil
}
114 changes: 0 additions & 114 deletions internal/provider/external/ignition_test.go

This file was deleted.

9 changes: 3 additions & 6 deletions internal/provider/external/installConfig.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -406,7 +405,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 @@ -417,8 +416,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 4a29b3d

Please sign in to comment.