@@ -54,12 +54,14 @@ const (
54
54
peerpodsCMAzureImageKey = "AZURE_IMAGE_ID"
55
55
peerpodsCMGCPImageKey = "PODVM_IMAGE_NAME"
56
56
peerpodsLibvirtImageKey = "LIBVIRT_IMAGE_ID"
57
+ peerpodsCMIBMCloudImageKey = "IBMCLOUD_PODVM_IMAGE_ID"
57
58
fipsCMKey = "BOOT_FIPS"
58
59
procFIPS = "/proc/sys/crypto/fips_enabled"
59
60
AWSProvider = "aws"
60
61
AzureProvider = "azure"
61
62
GCPProvider = "gcp"
62
63
LibvirtProvider = "libvirt"
64
+ IBMCloudProvider = "ibmcloud"
63
65
peerpodsImageJobsPathLocation = "/config/peerpods/podvm"
64
66
azureImageGalleryPrefix = "PodVMGallery"
65
67
)
@@ -259,6 +261,9 @@ func newImageGenerator(client client.Client) (*ImageGenerator, error) {
259
261
igLogger .Info ("libvirt is our provider" , "provider" , provider )
260
262
ig .CMimageIDKey = peerpodsLibvirtImageKey
261
263
ig .provider = provider
264
+ case IBMCloudProvider :
265
+ ig .provider = provider
266
+ ig .CMimageIDKey = peerpodsCMIBMCloudImageKey
262
267
default :
263
268
igLogger .Info ("unsupported cloud provider, image creation/deletion will be disabled" , "provider" , ig .provider )
264
269
ig .provider = unsupportedCloudProvider
@@ -415,6 +420,7 @@ func (r *ImageGenerator) getPeerPodsCM() (*corev1.ConfigMap, error) {
415
420
// azure-podvm-image-cm.yaml for Azure
416
421
// aws-podvm-image-cm.yaml for AWS
417
422
// libvirt-podvm-image-cm.yaml for Libvirt
423
+ // ibmcloud-podvm-image-cm.yaml for IBM Cloud
418
424
419
425
func (r * ImageGenerator ) imageCreateJobRunner () (int , error ) {
420
426
igLogger .Info ("imageCreateJobRunner: Start" )
@@ -617,6 +623,10 @@ func (r *ImageGenerator) validatePeerPodsConfigs() error {
617
623
libvirtSecretKeys := []string {"CLOUD_PROVIDER" , "LIBVIRT_URI" }
618
624
// libvirt ConfigMap Keys
619
625
libvirtConfigMapKeys := []string {"CLOUD_PROVIDER" , "LIBVIRT_POOL" , "LIBVIRT_VOL_NAME" , "LIBVIRT_DIR_NAME" }
626
+ // ibmcloud Secret Keys
627
+ ibmcloudSecretKeys := []string {"IBMCLOUD_IAM_PROFILE_ID" , "IBMCLOUD_API_KEY" }
628
+ // ibmcloud ConfigMap Keys
629
+ ibmcloudConfigMapKeys := []string {"CLOUD_PROVIDER" }
620
630
621
631
// Check for each cloud provider if respective ConfigMap keys are present in the peerPodsConfigMap
622
632
switch r .provider {
@@ -665,6 +675,16 @@ func (r *ImageGenerator) validatePeerPodsConfigs() error {
665
675
return fmt .Errorf ("validatePeerPodsConfigs: cannot find the required keys in peer-pods-cm ConfigMap" )
666
676
}
667
677
678
+ case IBMCloudProvider :
679
+ // Check if ibmcloud Secret Keys are present in the peerPodsSecret
680
+ if ! checkAnyKeyPresentWithValue (peerPodsSecret .Data , ibmcloudSecretKeys ) {
681
+ return fmt .Errorf ("validatePeerPodsConfigs: cannot find the required keys in peer-pods-secret Secret" )
682
+ }
683
+
684
+ // Check if ibmcloud ConfigMap Keys are present in the peerPodsConfigMap
685
+ if ! checkKeysPresentAndNotEmpty (peerPodsCM .Data , ibmcloudConfigMapKeys ) {
686
+ return fmt .Errorf ("validatePeerPodsConfigs: cannot find the required keys in peer-pods-cm ConfigMap" )
687
+ }
668
688
default :
669
689
return fmt .Errorf ("validatePeerPodsConfigs: unsupported cloud provider %s" , r .provider )
670
690
}
@@ -680,18 +700,8 @@ func (r *ImageGenerator) validatePeerPodsConfigs() error {
680
700
681
701
func checkKeysPresentAndNotEmpty (data interface {}, keys []string ) bool {
682
702
// Convert the input map to a map[string]string
683
- var strMap map [string ]string
684
-
685
- switch v := data .(type ) {
686
- case map [string ]string :
687
- strMap = v
688
- case map [string ][]byte :
689
- strMap = make (map [string ]string )
690
- for key , value := range v {
691
- strMap [key ] = string (value )
692
- }
693
- default :
694
- // Unsupported type
703
+ strMap := toStrMap (data )
704
+ if strMap == nil {
695
705
return false
696
706
}
697
707
@@ -708,6 +718,49 @@ func checkKeysPresentAndNotEmpty(data interface{}, keys []string) bool {
708
718
return true
709
719
}
710
720
721
+ // checkAnyKeyPresentWithValue checks if any of the specified keys are present in the input map
722
+ // and have non-empty string values.
723
+ // It accepts a map of type map[string][]byte or map[string]string as `data`,
724
+ // and a slice of keys to search for.
725
+ // Returns true if any key exists in the map and its value is not an empty string.
726
+ func checkAnyKeyPresentWithValue (data interface {}, keys []string ) bool {
727
+ // Convert the input to a map[string]string using a helper function.
728
+ strMap := toStrMap (data )
729
+ if strMap == nil {
730
+ return false // Return false if conversion fails.
731
+ }
732
+
733
+ // Iterate over the list of keys and check if any key exists with a non-empty value.
734
+ for _ , key := range keys {
735
+ value , ok := strMap [key ]
736
+ if ok && value != "" {
737
+ return true // Found a key with a non-empty value.
738
+ }
739
+ }
740
+
741
+ igLogger .Info ("checkAnyKeyPresentWithValue: no key is present or has non-empty value" , "searchedKeys" , keys )
742
+
743
+ return false // No matching key with a non-empty value found.
744
+ }
745
+
746
+ func toStrMap (data interface {}) map [string ]string {
747
+ var strMap map [string ]string
748
+
749
+ switch v := data .(type ) {
750
+ case map [string ]string :
751
+ strMap = v
752
+ case map [string ][]byte :
753
+ strMap = make (map [string ]string )
754
+ for key , value := range v {
755
+ strMap [key ] = string (value )
756
+ }
757
+ default :
758
+ // Unsupported type
759
+ return nil
760
+ }
761
+ return strMap
762
+ }
763
+
711
764
func (r * ImageGenerator ) getImageConfigMapName () string {
712
765
return r .provider + "-podvm-image-cm"
713
766
}
@@ -716,6 +769,7 @@ func (r *ImageGenerator) getImageConfigMapName() string {
716
769
// azure-podvm-image-cm.yaml for Azure
717
770
// aws-podvm-image-cm.yaml for AWS
718
771
// libvirt-podvm-image-cm.yaml for Libvirt
772
+ // ibmcloud-podvm-image-cm.yaml for IBM Cloud
719
773
// Returns error if the ConfigMap creation fails
720
774
721
775
func (r * ImageGenerator ) createImageConfigMapFromFile () error {
0 commit comments