@@ -66,16 +66,6 @@ func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
6666 }
6767 }
6868
69- for _ , section := range file .Sections () {
70- for key , value := range section .KeysHash () {
71- // Ignore anything that is the zero value for its type.
72- // Everything appears as a string in the INI file, so 0 and false are also considered zero values.
73- if value == "" {
74- section .DeleteKey (key )
75- }
76- }
77- }
78-
7969 // Ensure service override sections are last and ordered numerically.
8070 // We need to create a new file with sorted sections because file.Sections()
8171 // returns a new slice each time, so sorting it doesn't modify the original.
@@ -85,7 +75,8 @@ func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
8575 })
8676
8777 // Create a new INI file with sections in sorted order
88- sortedFile := ini .Empty ()
78+ // Configure iniv1 to allow shadow fields to enable multiple entries of NodeIPFamilies.
79+ sortedFile := ini .Empty (ini.LoadOptions {AllowShadows : true })
8980 for _ , section := range sections {
9081 newSection , err := sortedFile .NewSection (section .Name ())
9182 if err != nil {
@@ -96,6 +87,35 @@ func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
9687 }
9788 }
9889
90+ // In dual-stack environment, the CCM expects NodeIPFamilies to be in the format:
91+ //
92+ // NodeIPFamilies=ipv4
93+ // NodeIPFamilies=ipv6
94+ //
95+ // However, iniv1 is serializing go slices as comma-separated list, for example:
96+ //
97+ // NodeIPFamilies=ipv4,ipv6
98+ //
99+ // Below logic ensures the original NodeIPFamilies field is kept as-is after transforming.
100+ nodeIPKey := sortedFile .Section ("Global" ).Key ("NodeIPFamilies" )
101+ for i , ipFamily := range cfg .Global .NodeIPFamilies {
102+ if i == 0 {
103+ nodeIPKey .SetValue (ipFamily )
104+ } else if err := nodeIPKey .AddShadow (ipFamily ); err != nil {
105+ return "" , fmt .Errorf ("failed to set NodeIPFamilies: %w" , err )
106+ }
107+ }
108+
109+ for _ , section := range sortedFile .Sections () {
110+ for key , value := range section .KeysHash () {
111+ // Ignore anything that is the zero value for its type.
112+ // Everything appears as a string in the INI file, so 0 and false are also considered zero values.
113+ if value == "" {
114+ section .DeleteKey (key )
115+ }
116+ }
117+ }
118+
99119 buf := & bytes.Buffer {}
100120
101121 if _ , err := sortedFile .WriteTo (buf ); err != nil {
0 commit comments