mirror of
https://github.com/openshift/installer.git
synced 2026-02-05 06:46:36 +01:00
This PR improves cross-platform compatibility. It solves two main issues: 1. inconsistent line endings 2. inconsistent path separators Path separators, in installer, needs to target two different environments: 1. the OS where the installer runs 2. the OS where the injected files been used This PR unified path separators used in 2 to be UNIX path separators, while in 1 to be platform-dependant. Ref: https://forum.golangbridge.org/t/filepath-join-or-path-join/13479 Known issues: The spawn processes, including etcd.exe, kube-apiserver.exe, and openshift-installer.exe, will not exit once installation aborted or completed. Users need to manually terminate those processes in task manager.
149 lines
4.6 KiB
Go
149 lines
4.6 KiB
Go
package manifests
|
|
|
|
import (
|
|
"context"
|
|
"path"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/openshift/installer/pkg/asset"
|
|
"github.com/openshift/installer/pkg/asset/installconfig"
|
|
"github.com/openshift/installer/pkg/asset/manifests/aws"
|
|
"github.com/openshift/installer/pkg/asset/manifests/azure"
|
|
"github.com/openshift/installer/pkg/asset/manifests/gcp"
|
|
"github.com/openshift/installer/pkg/asset/manifests/ibmcloud"
|
|
awstypes "github.com/openshift/installer/pkg/types/aws"
|
|
azuretypes "github.com/openshift/installer/pkg/types/azure"
|
|
gcptypes "github.com/openshift/installer/pkg/types/gcp"
|
|
ibmcloudtypes "github.com/openshift/installer/pkg/types/ibmcloud"
|
|
)
|
|
|
|
var (
|
|
clusterCSIDriverConfigFileName = path.Join(manifestDir, "cluster-csi-driver-config.yaml")
|
|
)
|
|
|
|
// ClusterCSIDriverConfig generates the cluster-csi-driver-config.yaml file.
|
|
type ClusterCSIDriverConfig struct {
|
|
File *asset.File
|
|
}
|
|
|
|
// Type check the interface at compile time.
|
|
var _ asset.WritableAsset = (*ClusterCSIDriverConfig)(nil)
|
|
|
|
// Name returns a human friendly name for the asset.
|
|
func (*ClusterCSIDriverConfig) Name() string {
|
|
return "Cluster CSI Driver Config"
|
|
}
|
|
|
|
// Dependencies returns all of the dependencies directly needed to generate the
|
|
// asset.
|
|
func (*ClusterCSIDriverConfig) Dependencies() []asset.Asset {
|
|
return []asset.Asset{
|
|
&installconfig.InstallConfig{},
|
|
&installconfig.ClusterID{},
|
|
}
|
|
}
|
|
|
|
// Generate the ClusterCSIDriverConfig.
|
|
func (csi *ClusterCSIDriverConfig) Generate(_ context.Context, dependencies asset.Parents) error {
|
|
installConfig := &installconfig.InstallConfig{}
|
|
clusterID := &installconfig.ClusterID{}
|
|
dependencies.Get(installConfig, clusterID)
|
|
|
|
switch installConfig.Config.Platform.Name() {
|
|
case awstypes.Name:
|
|
platform := installConfig.Config.Platform.AWS.DefaultMachinePlatform
|
|
if platform == nil || platform.EC2RootVolume.KMSKeyARN == "" {
|
|
return nil
|
|
}
|
|
configData, err := aws.ClusterCSIDriverConfig{
|
|
KMSKeyARN: platform.EC2RootVolume.KMSKeyARN,
|
|
}.YAML()
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not create CSI cluster driver config")
|
|
}
|
|
csi.File = &asset.File{
|
|
Filename: clusterCSIDriverConfigFileName,
|
|
Data: configData,
|
|
}
|
|
|
|
case azuretypes.Name:
|
|
platform := installConfig.Config.Platform.Azure.DefaultMachinePlatform
|
|
if platform == nil || platform.OSDisk.DiskEncryptionSet == nil {
|
|
return nil
|
|
}
|
|
subscriptionID := platform.OSDisk.DiskEncryptionSet.SubscriptionID
|
|
if subscriptionID == "" {
|
|
session, err := installConfig.Azure.Session()
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not get azure session")
|
|
}
|
|
subscriptionID = session.Credentials.SubscriptionID
|
|
}
|
|
configData, err := azure.ClusterCSIDriverConfig{
|
|
SubscriptionID: subscriptionID,
|
|
ResourceGroupName: platform.OSDisk.DiskEncryptionSet.ResourceGroup,
|
|
DiskEncryptionSetName: platform.OSDisk.DiskEncryptionSet.Name,
|
|
}.YAML()
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not create CSI cluster driver config")
|
|
}
|
|
csi.File = &asset.File{
|
|
Filename: clusterCSIDriverConfigFileName,
|
|
Data: configData,
|
|
}
|
|
case gcptypes.Name:
|
|
platform := installConfig.Config.Platform.GCP.DefaultMachinePlatform
|
|
if platform == nil || platform.OSDisk.EncryptionKey == nil || platform.OSDisk.EncryptionKey.KMSKey == nil {
|
|
return nil
|
|
}
|
|
kmsKey := platform.OSDisk.EncryptionKey.KMSKey
|
|
|
|
configData, err := gcp.ClusterCSIDriverConfig{
|
|
Name: kmsKey.Name,
|
|
KeyRing: kmsKey.KeyRing,
|
|
ProjectID: kmsKey.ProjectID,
|
|
Location: kmsKey.Location,
|
|
}.YAML()
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not create CSI cluster driver config")
|
|
}
|
|
csi.File = &asset.File{
|
|
Filename: clusterCSIDriverConfigFileName,
|
|
Data: configData,
|
|
}
|
|
case ibmcloudtypes.Name:
|
|
platform := installConfig.Config.Platform.IBMCloud.DefaultMachinePlatform
|
|
if platform == nil || platform.BootVolume == nil || platform.BootVolume.EncryptionKey == "" {
|
|
return nil
|
|
}
|
|
|
|
encryptionKey := platform.BootVolume.EncryptionKey
|
|
configData, err := ibmcloud.ClusterCSIDriverConfig{
|
|
EncryptionKeyCRN: encryptionKey,
|
|
}.YAML()
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not create CSI cluster driver config")
|
|
}
|
|
csi.File = &asset.File{
|
|
Filename: clusterCSIDriverConfigFileName,
|
|
Data: configData,
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Files returns the files generated by the asset.
|
|
func (csi *ClusterCSIDriverConfig) Files() []*asset.File {
|
|
if csi.File != nil {
|
|
return []*asset.File{csi.File}
|
|
}
|
|
return []*asset.File{}
|
|
}
|
|
|
|
// Load loads the already-rendered files back from disk.
|
|
func (csi *ClusterCSIDriverConfig) Load(f asset.FileFetcher) (bool, error) {
|
|
return false, nil
|
|
}
|