Skip to content

Commit 5b23139

Browse files
committed
CORS-4209: ensure NodeIPFamilies field is kept as-is after transforming
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 This commit ensures the original NodeIPFamilies field is kept as-is after transforming.
1 parent 040e5a5 commit 5b23139

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pkg/cloud/aws/aws_config_transformer.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func readAWSConfig(source string) (*awsconfig.CloudConfig, error) {
5454
}
5555

5656
func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
57-
file := ini.Empty()
57+
// Configure iniv1 to allow shadow fields to enable multiple entries of NodeIPFamilies.
58+
file := ini.Empty(ini.LoadOptions{AllowShadows: true})
5859
if err := file.Section("Global").ReflectFrom(&cfg.Global); err != nil {
5960
return "", fmt.Errorf("failed to reflect global config: %w", err)
6061
}
@@ -65,6 +66,25 @@ func marshalAWSConfig(cfg *awsconfig.CloudConfig) (string, error) {
6566
}
6667
}
6768

69+
// In dual-stack environment, the CCM expects NodeIPFamilies to be in the format:
70+
//
71+
// NodeIPFamilies=ipv4
72+
// NodeIPFamilies=ipv6
73+
//
74+
// However, iniv1 is serializing go slices as comma-separated list, for example:
75+
//
76+
// NodeIPFamilies=ipv4,ipv6
77+
//
78+
// Below logic ensures the original NodeIPFamilies field is kept as-is after transforming.
79+
nodeIPKey := file.Section("Global").Key("NodeIPFamilies")
80+
for i, ipFamily := range cfg.Global.NodeIPFamilies {
81+
if i == 0 {
82+
nodeIPKey.SetValue(ipFamily)
83+
} else if err := nodeIPKey.AddShadow(ipFamily); err != nil {
84+
return "", fmt.Errorf("failed to set NodeIPFamilies: %w", err)
85+
}
86+
}
87+
6888
for _, section := range file.Sections() {
6989
for key, value := range section.KeysHash() {
7090
// Ignore anything that is the zero value for its type.

pkg/cloud/aws/aws_config_transformer_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ URL = https://s3.foo.bar
8383
SigningRegion = signing_region
8484
`, // Ordered based on the order of fields in the AWS CloudConfig struct.
8585
},
86+
{
87+
name: "with NodeIPFamilies",
88+
source: `[Global]
89+
NodeIPFamilies = ipv4
90+
NodeIPFamilies = ipv6
91+
`, // This is the default that gets created for any OpenShift Cluster.
92+
expected: `[Global]
93+
DisableSecurityGroupIngress = false
94+
NodeIPFamilies = ipv4
95+
NodeIPFamilies = ipv6
96+
ClusterServiceLoadBalancerHealthProbeMode = Shared
97+
ClusterServiceSharedLoadBalancerHealthProbePort = 0
98+
`,
99+
},
86100
}
87101

88102
for _, tc := range testCases {

0 commit comments

Comments
 (0)