Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions pkg/cloud/aws/aws_config_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
}
}

for _, section := range file.Sections() {
for key, value := range section.KeysHash() {
// Ignore anything that is the zero value for its type.
// Everything appears as a string in the INI file, so 0 and false are also considered zero values.
if value == "" {
section.DeleteKey(key)
}
}
}

// Ensure service override sections are last and ordered numerically.
// We need to create a new file with sorted sections because file.Sections()
// returns a new slice each time, so sorting it doesn't modify the original.
Expand All @@ -85,7 +75,8 @@ func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
})

// Create a new INI file with sections in sorted order
sortedFile := ini.Empty()
// Configure iniv1 to allow shadow fields to enable multiple entries of NodeIPFamilies.
sortedFile := ini.Empty(ini.LoadOptions{AllowShadows: true})
for _, section := range sections {
newSection, err := sortedFile.NewSection(section.Name())
if err != nil {
Expand All @@ -96,6 +87,35 @@ func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
}
}

// In dual-stack environment, the CCM expects NodeIPFamilies to be in the format:
//
// NodeIPFamilies=ipv4
// NodeIPFamilies=ipv6
//
// However, iniv1 is serializing go slices as comma-separated list, for example:
//
// NodeIPFamilies=ipv4,ipv6
//
// Below logic ensures the original NodeIPFamilies field is kept as-is after transforming.
nodeIPKey := sortedFile.Section("Global").Key("NodeIPFamilies")
for i, ipFamily := range cfg.Global.NodeIPFamilies {
if i == 0 {
nodeIPKey.SetValue(ipFamily)
} else if err := nodeIPKey.AddShadow(ipFamily); err != nil {
return "", fmt.Errorf("failed to set NodeIPFamilies: %w", err)
}
}

for _, section := range sortedFile.Sections() {
for key, value := range section.KeysHash() {
// Ignore anything that is the zero value for its type.
// Everything appears as a string in the INI file, so 0 and false are also considered zero values.
if value == "" {
section.DeleteKey(key)
}
}
}

buf := &bytes.Buffer{}

if _, err := sortedFile.WriteTo(buf); err != nil {
Expand Down
28 changes: 28 additions & 0 deletions pkg/cloud/aws/aws_config_transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,34 @@ ClusterServiceSharedLoadBalancerHealthProbePort = 0
`,
features: mockDisabledFeatureGates,
},
{
name: "with NodeIPFamilies with ipv4 first",
source: `[Global]
NodeIPFamilies = ipv4
NodeIPFamilies = ipv6
`,
expected: `[Global]
DisableSecurityGroupIngress = false
NodeIPFamilies = ipv4
NodeIPFamilies = ipv6
ClusterServiceLoadBalancerHealthProbeMode = Shared
ClusterServiceSharedLoadBalancerHealthProbePort = 0
`,
},
{
name: "with NodeIPFamilies with ipv6 first",
source: `[Global]
NodeIPFamilies = ipv6
NodeIPFamilies = ipv4
`,
expected: `[Global]
DisableSecurityGroupIngress = false
NodeIPFamilies = ipv6
NodeIPFamilies = ipv4
ClusterServiceLoadBalancerHealthProbeMode = Shared
ClusterServiceSharedLoadBalancerHealthProbePort = 0
`,
},
}

for _, tc := range testCases {
Expand Down