Skip to content

Commit 1a28380

Browse files
Merge pull request #10257 from tthvo/CORS-4328
CORS-4328: configure AWS CCM NodeIPFamilies for dual-stack support
2 parents e10bd06 + edb4e5a commit 1a28380

3 files changed

Lines changed: 150 additions & 5 deletions

File tree

pkg/asset/manifests/cloudproviderconfig.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
externaltypes "github.com/openshift/installer/pkg/types/external"
3434
gcptypes "github.com/openshift/installer/pkg/types/gcp"
3535
ibmcloudtypes "github.com/openshift/installer/pkg/types/ibmcloud"
36+
networktypes "github.com/openshift/installer/pkg/types/network"
3637
nonetypes "github.com/openshift/installer/pkg/types/none"
3738
nutanixtypes "github.com/openshift/installer/pkg/types/nutanix"
3839
openstacktypes "github.com/openshift/installer/pkg/types/openstack"
@@ -113,12 +114,27 @@ func (cpc *CloudProviderConfig) Generate(ctx context.Context, dependencies asset
113114
cm.Data[cloudProviderConfigCABundleDataKey] = trustBundle
114115
}
115116

116-
// Include a non-empty kube config to appease components--such as the kube-apiserver--that
117-
// expect there to be a kube config if the cloud-provider-config ConfigMap exists. See
118-
// https://bugzilla.redhat.com/show_bug.cgi?id=1926975.
119-
// Note that the newline is required in order to be valid yaml.
120-
cm.Data[cloudProviderConfigDataKey] = `[Global]
117+
var cloudCfg string
118+
switch installConfig.Config.AWS.IPFamily {
119+
case networktypes.DualStackIPv4Primary:
120+
cloudCfg = `[Global]
121+
NodeIPFamilies=ipv4
122+
NodeIPFamilies=ipv6
121123
`
124+
case networktypes.DualStackIPv6Primary:
125+
cloudCfg = `[Global]
126+
NodeIPFamilies=ipv6
127+
NodeIPFamilies=ipv4
128+
`
129+
default:
130+
// Include a non-empty kube config to appease components--such as the kube-apiserver--that
131+
// expect there to be a kube config if the cloud-provider-config ConfigMap exists. See
132+
// https://bugzilla.redhat.com/show_bug.cgi?id=1926975.
133+
// Note that the newline is required in order to be valid yaml.
134+
cloudCfg = `[Global]
135+
`
136+
}
137+
cm.Data[cloudProviderConfigDataKey] = cloudCfg
122138
case openstacktypes.Name, powervctypes.Name:
123139
cloudProviderConfigData, cloudProviderConfigCABundleData, err := openstackmanifests.GenerateCloudProviderConfig(ctx, *installConfig.Config)
124140
if err != nil {
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package manifests
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
corev1 "k8s.io/api/core/v1"
9+
"sigs.k8s.io/yaml"
10+
11+
"github.com/openshift/installer/pkg/asset"
12+
"github.com/openshift/installer/pkg/asset/installconfig"
13+
"github.com/openshift/installer/pkg/types"
14+
"github.com/openshift/installer/pkg/types/network"
15+
)
16+
17+
func TestGenerateCloudProviderConfig(t *testing.T) {
18+
cases := []struct {
19+
name string
20+
installConfig *types.InstallConfig
21+
expectedCloudCfg map[string]string
22+
}{
23+
{
24+
name: "aws: empty ipFamily - default IPv4",
25+
installConfig: icBuild.build(
26+
icBuild.forAWS(),
27+
icBuild.withAWSRegion("us-east-1"),
28+
),
29+
expectedCloudCfg: map[string]string{
30+
cloudProviderConfigDataKey: `[Global]
31+
`,
32+
},
33+
},
34+
{
35+
name: "aws: ipFamily IPv4",
36+
installConfig: icBuild.build(
37+
icBuild.forAWS(),
38+
icBuild.withAWSRegion("us-east-1"),
39+
icBuild.withAWSIPFamily(network.IPv4),
40+
),
41+
expectedCloudCfg: map[string]string{
42+
cloudProviderConfigDataKey: `[Global]
43+
`,
44+
},
45+
},
46+
{
47+
name: "aws: ipFamily DualStackIPv4Primary",
48+
installConfig: icBuild.build(
49+
icBuild.forAWS(),
50+
icBuild.withAWSRegion("us-east-1"),
51+
icBuild.withAWSIPFamily(network.DualStackIPv4Primary),
52+
),
53+
expectedCloudCfg: map[string]string{
54+
cloudProviderConfigDataKey: `[Global]
55+
NodeIPFamilies=ipv4
56+
NodeIPFamilies=ipv6
57+
`,
58+
},
59+
},
60+
{
61+
name: "aws: ipFamily DualStackIPv6Primary",
62+
installConfig: icBuild.build(
63+
icBuild.forAWS(),
64+
icBuild.withAWSRegion("us-east-1"),
65+
icBuild.withAWSIPFamily(network.DualStackIPv6Primary),
66+
),
67+
expectedCloudCfg: map[string]string{
68+
cloudProviderConfigDataKey: `[Global]
69+
NodeIPFamilies=ipv6
70+
NodeIPFamilies=ipv4
71+
`,
72+
},
73+
},
74+
}
75+
76+
for _, tc := range cases {
77+
t.Run(tc.name, func(t *testing.T) {
78+
parents := asset.Parents{}
79+
parents.Add(
80+
installconfig.MakeAsset(tc.installConfig),
81+
&installconfig.ClusterID{
82+
InfraID: "test-infra-id",
83+
},
84+
)
85+
86+
cloudConfig := &CloudProviderConfig{}
87+
88+
err := cloudConfig.Generate(context.Background(), parents)
89+
if !assert.NoError(t, err, "failed to generate asset") {
90+
return
91+
}
92+
93+
if tc.expectedCloudCfg == nil {
94+
assert.Nil(t, cloudConfig.ConfigMap)
95+
assert.Len(t, cloudConfig.Files(), 0)
96+
return
97+
}
98+
99+
if !assert.NotNil(t, cloudConfig.ConfigMap) {
100+
return
101+
}
102+
103+
assert.Equal(t, "openshift-config", cloudConfig.ConfigMap.Namespace)
104+
assert.Equal(t, "cloud-provider-config", cloudConfig.ConfigMap.Name)
105+
assert.Equal(t, tc.expectedCloudCfg, cloudConfig.ConfigMap.Data)
106+
107+
if !assert.Len(t, cloudConfig.Files(), 1, "expected 1 file to be generated") {
108+
return
109+
}
110+
111+
assert.Equal(t, cloudConfig.Files()[0].Filename, cloudProviderConfigFileName)
112+
113+
var actualCloudConfig corev1.ConfigMap
114+
err = yaml.Unmarshal(cloudConfig.Files()[0].Data, &actualCloudConfig)
115+
if !assert.NoError(t, err, "failed to unmarshal cloud-provider-config manifest") {
116+
return
117+
}
118+
119+
assert.Equal(t, tc.expectedCloudCfg, actualCloudConfig.Data)
120+
})
121+
}
122+
}

pkg/asset/manifests/infrastructure_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ func (b icBuildNamespace) withAWSIPFamily(ipFamily network.IPFamily) icOption {
450450
}
451451
}
452452

453+
func (b icBuildNamespace) withAWSRegion(region string) icOption {
454+
return func(ic *types.InstallConfig) {
455+
b.forAWS()(ic)
456+
ic.Platform.AWS.Region = region
457+
}
458+
}
459+
453460
func (b icBuildNamespace) withVSphereAPIVIP(vip string) icOption {
454461
return func(ic *types.InstallConfig) {
455462
b.forVSphere()(ic)

0 commit comments

Comments
 (0)