@@ -22,6 +22,7 @@ import (
2222 "os"
2323 "os/exec"
2424 "reflect"
25+ "strings"
2526
2627 "github.com/pkg/errors"
2728 "github.com/sirupsen/logrus"
@@ -231,6 +232,8 @@ func DefaultedV1Beta3KubeOneCluster(versionedCluster *kubeonev1beta3.KubeOneClus
231232
232233// SetKubeOneClusterDynamicDefaults sets the dynamic defaults for a given KubeOneCluster object
233234func SetKubeOneClusterDynamicDefaults (cluster * kubeoneapi.KubeOneCluster , credentialsFile []byte ) error {
235+ // Set the default cloud config
236+ SetDefaultsCloudConfig (cluster )
234237 // Parse the credentials file
235238 credentials := make (map [string ]string )
236239
@@ -289,6 +292,42 @@ func SetKubeOneClusterDynamicDefaults(cluster *kubeoneapi.KubeOneCluster, creden
289292 return nil
290293}
291294
295+ // SetDefaultsCloudConfig sets default values for the CloudConfig field in the KubeOneCluster object.
296+ // this function assigns a default cloud configuration.
297+ func SetDefaultsCloudConfig (obj * kubeoneapi.KubeOneCluster ) {
298+ if obj .CloudProvider .AWS != nil && obj .CloudProvider .External {
299+ if obj .CloudProvider .CloudConfig == "" {
300+ obj .CloudProvider .CloudConfig = defaultAWSCCMCloudConfig (obj .Name , obj .ClusterNetwork .IPFamily )
301+ }
302+ }
303+ }
304+
305+ // defaultAWSCCMCloudConfig generates a default cloud configuration for AWS when using the Cloud Controller Manager (CCM).
306+ // The configuration includes the Kubernetes cluster ID and optionally sets NodeIPFamilies based on the IPFamily setting.
307+ func defaultAWSCCMCloudConfig (name string , ipFamily kubeoneapi.IPFamily ) string {
308+ // Initialize the configuration with the global section and cluster ID.
309+ lines := []string {
310+ "[global]" ,
311+ fmt .Sprintf ("KubernetesClusterID=%q" , name ),
312+ }
313+
314+ // Set NodeIPFamilies based on the IP family configuration.
315+ switch ipFamily {
316+ case kubeoneapi .IPFamilyIPv4 :
317+ lines = append (lines , fmt .Sprintf ("NodeIPFamilies=%q" , "ipv4" ))
318+ case kubeoneapi .IPFamilyIPv6 :
319+ lines = append (lines , fmt .Sprintf ("NodeIPFamilies=%q" , "ipv6" ))
320+ case kubeoneapi .IPFamilyIPv4IPv6 :
321+ lines = append (lines , fmt .Sprintf ("NodeIPFamilies=%q" , "ipv4" ))
322+ lines = append (lines , fmt .Sprintf ("NodeIPFamilies=%q" , "ipv6" ))
323+ case kubeoneapi .IPFamilyIPv6IPv4 :
324+ lines = append (lines , fmt .Sprintf ("NodeIPFamilies=%q" , "ipv6" ))
325+ lines = append (lines , fmt .Sprintf ("NodeIPFamilies=%q" , "ipv4" ))
326+ }
327+
328+ return strings .Join (lines , "\n " )
329+ }
330+
292331func setRegistriesAuth (cluster * kubeoneapi.KubeOneCluster , buf string ) error {
293332 var registriesAuth struct {
294333 runtime.TypeMeta `json:",inline"`
0 commit comments