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
22 changes: 21 additions & 1 deletion pkg/cloud/aws/aws_config_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func readAWSConfig(source string) (*awsconfig.CloudConfig, error) {
}

func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
file := ini.Empty()
// Configure iniv1 to allow shadow fields to enable multiple entries of NodeIPFamilies.
file := ini.Empty(ini.LoadOptions{AllowShadows: true})
if err := file.Section("Global").ReflectFrom(&cfg.Global); err != nil {
return "", fmt.Errorf("failed to reflect global config: %w", err)
}
Expand All @@ -65,6 +66,25 @@ 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 := file.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 file.Sections() {
for key, value := range section.KeysHash() {
// Ignore anything that is the zero value for its type.
Expand Down
14 changes: 14 additions & 0 deletions pkg/cloud/aws/aws_config_transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ URL = https://s3.foo.bar
SigningRegion = signing_region
`, // Ordered based on the order of fields in the AWS CloudConfig struct.
},
{
name: "with NodeIPFamilies",
source: `[Global]
NodeIPFamilies = ipv4
NodeIPFamilies = ipv6
`,
expected: `[Global]
DisableSecurityGroupIngress = false
NodeIPFamilies = ipv4
NodeIPFamilies = ipv6
ClusterServiceLoadBalancerHealthProbeMode = Shared
ClusterServiceSharedLoadBalancerHealthProbePort = 0
`,
},
}

for _, tc := range testCases {
Expand Down