@@ -18,7 +18,19 @@ import (
1818 gcptypes "github.com/openshift/installer/pkg/types/gcp"
1919)
2020
21- const masterRole = "master"
21+ const (
22+ masterRole = "master"
23+
24+ kmsKeyNameFmt = "projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s"
25+ )
26+
27+ func generateDiskEncryptionKeyLink (kmsKey * gcptypes.KMSKeyReference , projectID string ) string {
28+ if kmsKey .ProjectID != "" {
29+ projectID = kmsKey .ProjectID
30+ }
31+
32+ return fmt .Sprintf (kmsKeyNameFmt , projectID , kmsKey .Location , kmsKey .KeyRing , kmsKey .Name )
33+ }
2234
2335// GenerateMachines returns manifests and runtime objects to provision control plane nodes using CAPI.
2436func GenerateMachines (installConfig * installconfig.InstallConfig , infraID string , pool * types.MachinePool , imageName string ) ([]* asset.RuntimeFile , error ) {
@@ -161,6 +173,17 @@ func createGCPMachine(name string, installConfig *installconfig.InstallConfig, i
161173 }
162174 gcpMachine .Spec .ServiceAccount = serviceAccount
163175
176+ if mpool .OSDisk .EncryptionKey != nil {
177+ encryptionKey := & capg.CustomerEncryptionKey {
178+ KeyType : capg .CustomerManagedKey ,
179+ KMSKeyServiceAccount : ptr .To (mpool .OSDisk .EncryptionKey .KMSKeyServiceAccount ),
180+ ManagedKey : & capg.ManagedKey {
181+ KMSKeyName : generateDiskEncryptionKeyLink (mpool .OSDisk .EncryptionKey .KMSKey , installConfig .Config .GCP .ProjectID ),
182+ },
183+ }
184+ gcpMachine .Spec .RootDiskEncryptionKey = encryptionKey
185+ }
186+
164187 return gcpMachine
165188}
166189
0 commit comments