github.com/openshift/installer@v1.4.17/pkg/asset/manifests/clustercsidriver.go (about) 1 package manifests 2 3 import ( 4 "context" 5 "path/filepath" 6 7 "github.com/pkg/errors" 8 9 "github.com/openshift/installer/pkg/asset" 10 "github.com/openshift/installer/pkg/asset/installconfig" 11 "github.com/openshift/installer/pkg/asset/manifests/aws" 12 "github.com/openshift/installer/pkg/asset/manifests/azure" 13 "github.com/openshift/installer/pkg/asset/manifests/gcp" 14 "github.com/openshift/installer/pkg/asset/manifests/ibmcloud" 15 awstypes "github.com/openshift/installer/pkg/types/aws" 16 azuretypes "github.com/openshift/installer/pkg/types/azure" 17 gcptypes "github.com/openshift/installer/pkg/types/gcp" 18 ibmcloudtypes "github.com/openshift/installer/pkg/types/ibmcloud" 19 ) 20 21 var ( 22 clusterCSIDriverConfigFileName = filepath.Join(manifestDir, "cluster-csi-driver-config.yaml") 23 ) 24 25 // ClusterCSIDriverConfig generates the cluster-csi-driver-config.yaml file. 26 type ClusterCSIDriverConfig struct { 27 File *asset.File 28 } 29 30 // Type check the interface at compile time. 31 var _ asset.WritableAsset = (*ClusterCSIDriverConfig)(nil) 32 33 // Name returns a human friendly name for the asset. 34 func (*ClusterCSIDriverConfig) Name() string { 35 return "Cluster CSI Driver Config" 36 } 37 38 // Dependencies returns all of the dependencies directly needed to generate the 39 // asset. 40 func (*ClusterCSIDriverConfig) Dependencies() []asset.Asset { 41 return []asset.Asset{ 42 &installconfig.InstallConfig{}, 43 &installconfig.ClusterID{}, 44 } 45 } 46 47 // Generate the ClusterCSIDriverConfig. 48 func (csi *ClusterCSIDriverConfig) Generate(_ context.Context, dependencies asset.Parents) error { 49 installConfig := &installconfig.InstallConfig{} 50 clusterID := &installconfig.ClusterID{} 51 dependencies.Get(installConfig, clusterID) 52 53 switch installConfig.Config.Platform.Name() { 54 case awstypes.Name: 55 platform := installConfig.Config.Platform.AWS.DefaultMachinePlatform 56 if platform == nil || platform.EC2RootVolume.KMSKeyARN == "" { 57 return nil 58 } 59 configData, err := aws.ClusterCSIDriverConfig{ 60 KMSKeyARN: platform.EC2RootVolume.KMSKeyARN, 61 }.YAML() 62 if err != nil { 63 return errors.Wrap(err, "could not create CSI cluster driver config") 64 } 65 csi.File = &asset.File{ 66 Filename: clusterCSIDriverConfigFileName, 67 Data: configData, 68 } 69 70 case azuretypes.Name: 71 platform := installConfig.Config.Platform.Azure.DefaultMachinePlatform 72 if platform == nil || platform.OSDisk.DiskEncryptionSet == nil { 73 return nil 74 } 75 subscriptionID := platform.OSDisk.DiskEncryptionSet.SubscriptionID 76 if subscriptionID == "" { 77 session, err := installConfig.Azure.Session() 78 if err != nil { 79 return errors.Wrap(err, "could not get azure session") 80 } 81 subscriptionID = session.Credentials.SubscriptionID 82 } 83 configData, err := azure.ClusterCSIDriverConfig{ 84 SubscriptionID: subscriptionID, 85 ResourceGroupName: platform.OSDisk.DiskEncryptionSet.ResourceGroup, 86 DiskEncryptionSetName: platform.OSDisk.DiskEncryptionSet.Name, 87 }.YAML() 88 if err != nil { 89 return errors.Wrap(err, "could not create CSI cluster driver config") 90 } 91 csi.File = &asset.File{ 92 Filename: clusterCSIDriverConfigFileName, 93 Data: configData, 94 } 95 case gcptypes.Name: 96 platform := installConfig.Config.Platform.GCP.DefaultMachinePlatform 97 if platform == nil || platform.OSDisk.EncryptionKey == nil || platform.OSDisk.EncryptionKey.KMSKey == nil { 98 return nil 99 } 100 kmsKey := platform.OSDisk.EncryptionKey.KMSKey 101 configData, err := gcp.ClusterCSIDriverConfig{ 102 Name: kmsKey.Name, 103 KeyRing: kmsKey.KeyRing, 104 ProjectID: kmsKey.ProjectID, 105 Location: kmsKey.Location, 106 }.YAML() 107 if err != nil { 108 return errors.Wrap(err, "could not create CSI cluster driver config") 109 } 110 csi.File = &asset.File{ 111 Filename: clusterCSIDriverConfigFileName, 112 Data: configData, 113 } 114 case ibmcloudtypes.Name: 115 platform := installConfig.Config.Platform.IBMCloud.DefaultMachinePlatform 116 if platform == nil || platform.BootVolume == nil || platform.BootVolume.EncryptionKey == "" { 117 return nil 118 } 119 120 encryptionKey := platform.BootVolume.EncryptionKey 121 configData, err := ibmcloud.ClusterCSIDriverConfig{ 122 EncryptionKeyCRN: encryptionKey, 123 }.YAML() 124 if err != nil { 125 return errors.Wrap(err, "could not create CSI cluster driver config") 126 } 127 csi.File = &asset.File{ 128 Filename: clusterCSIDriverConfigFileName, 129 Data: configData, 130 } 131 } 132 133 return nil 134 } 135 136 // Files returns the files generated by the asset. 137 func (csi *ClusterCSIDriverConfig) Files() []*asset.File { 138 if csi.File != nil { 139 return []*asset.File{csi.File} 140 } 141 return []*asset.File{} 142 } 143 144 // Load loads the already-rendered files back from disk. 145 func (csi *ClusterCSIDriverConfig) Load(f asset.FileFetcher) (bool, error) { 146 return false, nil 147 }