@@ -8,15 +8,13 @@ import (
8
8
. "github.com/onsi/gomega"
9
9
"github.com/onsi/gomega/format"
10
10
configv1 "github.com/openshift/api/config/v1"
11
+ "github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
11
12
"github.com/stretchr/testify/assert"
12
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
- azureconsts "sigs.k8s.io/cloud-provider-azure/pkg/consts"
14
- azure "sigs.k8s.io/cloud-provider-azure/pkg/provider"
15
13
14
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
15
"sigs.k8s.io/cloud-provider-azure/pkg/azclient"
17
- ratelimitconfig "sigs.k8s.io/cloud-provider-azure/pkg/provider/config"
18
-
19
- "github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
16
+ azureconsts "sigs.k8s.io/cloud-provider-azure/pkg/consts"
17
+ azconfig "sigs.k8s.io/cloud-provider-azure/pkg/provider/config"
20
18
)
21
19
22
20
const (
@@ -126,7 +124,7 @@ func makeInfrastructureResource(platform configv1.PlatformType, cloudName config
126
124
}
127
125
128
126
// makeExpectedConfig sets some repetitive default fields for tests, assuming that they are not already set.
129
- func makeExpectedConfig (config * azure .Config , cloud configv1.AzureCloudEnvironment ) azure .Config {
127
+ func makeExpectedConfig (config * azconfig .Config , cloud configv1.AzureCloudEnvironment ) azconfig .Config {
130
128
if config .ClusterServiceLoadBalancerHealthProbeMode == "" {
131
129
config .ClusterServiceLoadBalancerHealthProbeMode = azureconsts .ClusterServiceLoadBalancerHealthProbeModeShared
132
130
}
@@ -135,7 +133,7 @@ func makeExpectedConfig(config *azure.Config, cloud configv1.AzureCloudEnvironme
135
133
config .VMType = "standard"
136
134
}
137
135
138
- config .AzureAuthConfig = ratelimitconfig. AzureAuthConfig {
136
+ config .AzureClientConfig = azconfig. AzureClientConfig {
139
137
ARMClientConfig : azclient.ARMClientConfig {
140
138
Cloud : string (cloud ),
141
139
},
@@ -153,95 +151,99 @@ func makeExpectedConfig(config *azure.Config, cloud configv1.AzureCloudEnvironme
153
151
func TestCloudConfigTransformer (t * testing.T ) {
154
152
tc := []struct {
155
153
name string
156
- source azure .Config
157
- expected azure .Config
154
+ source azconfig .Config
155
+ expected azconfig .Config
158
156
infra * configv1.Infrastructure
159
157
errMsg string
160
158
}{
161
159
{
162
160
name : "Non Azure returns an error" ,
163
- source : azure .Config {},
161
+ source : azconfig .Config {},
164
162
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureStackCloud ),
165
163
errMsg : fmt .Sprintf ("invalid platform, expected CloudName to be %s" , configv1 .AzurePublicCloud ),
166
164
},
167
165
{
168
166
name : "Azure sets the vmType to standard and cloud to AzurePublicCloud when neither is set" ,
169
- source : azure .Config {},
170
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzurePublicCloud ),
167
+ source : azconfig .Config {},
168
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzurePublicCloud ),
171
169
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
172
170
},
173
171
{
174
172
name : "Azure doesn't modify vmType if user set" ,
175
- source : azure .Config {VMType : "vmss" },
176
- expected : makeExpectedConfig (& azure .Config {VMType : "vmss" }, configv1 .AzurePublicCloud ),
173
+ source : azconfig .Config {VMType : "vmss" },
174
+ expected : makeExpectedConfig (& azconfig .Config {VMType : "vmss" }, configv1 .AzurePublicCloud ),
177
175
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
178
176
},
179
177
{
180
178
name : "Azure sets the cloud to AzurePublicCloud and keeps existing fields" ,
181
- source : azure .Config {
179
+ source : azconfig .Config {
182
180
ResourceGroup : "test-rg" ,
183
181
},
184
- expected : makeExpectedConfig (& azure .Config {ResourceGroup : "test-rg" }, configv1 .AzurePublicCloud ),
182
+ expected : makeExpectedConfig (& azconfig .Config {ResourceGroup : "test-rg" }, configv1 .AzurePublicCloud ),
185
183
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
186
184
},
187
185
{
188
186
name : "Azure keeps the cloud set to AzurePublicCloud" ,
189
- source : azure .Config {AzureAuthConfig : ratelimitconfig. AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzurePublicCloud )}}},
190
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzurePublicCloud ),
187
+ source : azconfig .Config {AzureClientConfig : azconfig. AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzurePublicCloud )}}},
188
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzurePublicCloud ),
191
189
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
192
190
},
193
191
{
194
192
name : "Azure keeps the cloud set to US Gov cloud" ,
195
- source : azure .Config {AzureAuthConfig : ratelimitconfig. AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzureUSGovernmentCloud )}}},
196
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzureUSGovernmentCloud ),
193
+ source : azconfig .Config {AzureClientConfig : azconfig. AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzureUSGovernmentCloud )}}},
194
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzureUSGovernmentCloud ),
197
195
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureUSGovernmentCloud ),
198
196
},
199
197
{
200
198
name : "Azure keeps the cloud set to China cloud" ,
201
- source : azure .Config {AzureAuthConfig : ratelimitconfig. AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzureChinaCloud )}}},
202
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzureChinaCloud ),
199
+ source : azconfig .Config {AzureClientConfig : azconfig. AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzureChinaCloud )}}},
200
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzureChinaCloud ),
203
201
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureChinaCloud ),
204
202
},
205
203
{
206
204
name : "Azure keeps the cloud set to German cloud" ,
207
- source : azure .Config {AzureAuthConfig : ratelimitconfig. AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzureGermanCloud )}}},
208
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzureGermanCloud ),
205
+ source : azconfig .Config {AzureClientConfig : azconfig. AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzureGermanCloud )}}},
206
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzureGermanCloud ),
209
207
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureGermanCloud ),
210
208
},
211
209
{
212
210
name : "Azure throws an error if the infra has an invalid cloud" ,
213
- source : azure .Config {},
211
+ source : azconfig .Config {},
214
212
infra : makeInfrastructureResource (configv1 .AzurePlatformType , "AzureAnotherCloud" ),
215
213
errMsg : "status.platformStatus.azure.cloudName: Unsupported value: \" AzureAnotherCloud\" : supported values: \" AzureChinaCloud\" , \" AzureGermanCloud\" , \" AzurePublicCloud\" , \" AzureStackCloud\" , \" AzureUSGovernmentCloud\" " ,
216
214
},
217
215
{
218
216
name : "Azure keeps the cloud set in the source when there is not one set in infrastructure" ,
219
- source : azure .Config {AzureAuthConfig : ratelimitconfig. AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzurePublicCloud )}}},
220
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzurePublicCloud ),
217
+ source : azconfig .Config {AzureClientConfig : azconfig. AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzurePublicCloud )}}},
218
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzurePublicCloud ),
221
219
infra : makeInfrastructureResource (configv1 .AzurePlatformType , "" ),
222
220
},
223
221
{
224
222
name : "Azure sets the cloud to match the infrastructure if an empty string is provided in source" ,
225
- source : azure .Config {AzureAuthConfig : ratelimitconfig. AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : "" }}},
226
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzurePublicCloud ),
223
+ source : azconfig .Config {AzureClientConfig : azconfig. AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : "" }}},
224
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzurePublicCloud ),
227
225
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
228
226
},
229
227
{
230
228
name : "Azure sets the cloud to match the infrastructure if an empty string is provided in source and the infrastructure is non standard" ,
231
- source : azure .Config {AzureAuthConfig : ratelimitconfig. AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : "" }}},
232
- expected : makeExpectedConfig (& azure .Config {}, configv1 .AzureUSGovernmentCloud ),
229
+ source : azconfig .Config {AzureClientConfig : azconfig. AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : "" }}},
230
+ expected : makeExpectedConfig (& azconfig .Config {}, configv1 .AzureUSGovernmentCloud ),
233
231
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureUSGovernmentCloud ),
234
232
},
235
233
{
236
- name : "Azure returns an error if the source config conflicts with the infrastructure" ,
237
- source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : string (configv1 .AzurePublicCloud )}}},
234
+ name : "Azure returns an error if the source config conflicts with the infrastructure" ,
235
+ source : azconfig.Config {AzureClientConfig : azconfig.AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {
236
+ Cloud : string (configv1 .AzurePublicCloud )}},
237
+ },
238
238
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureUSGovernmentCloud ),
239
239
errMsg : "invalid user-provided cloud.conf: \\ \" cloud\\ \" field in user-provided\n \t \t \t \t cloud.conf conflicts with infrastructure object" ,
240
240
},
241
241
{
242
- name : "Azure keeps the cloud set to AzurePublicCloud if the source is upper case" ,
243
- source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {ARMClientConfig : azclient.ARMClientConfig {Cloud : "AZUREPUBLICCLOUD" }}},
244
- expected : makeExpectedConfig (& azure.Config {}, configv1 .AzurePublicCloud ),
242
+ name : "Azure keeps the cloud set to AzurePublicCloud if the source is upper case" ,
243
+ source : azconfig.Config {AzureClientConfig : azconfig.AzureClientConfig {ARMClientConfig : azclient.ARMClientConfig {
244
+ Cloud : "AZUREPUBLICCLOUD" }},
245
+ },
246
+ expected : makeExpectedConfig (& azconfig.Config {}, configv1 .AzurePublicCloud ),
245
247
infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
246
248
},
247
249
}
@@ -262,7 +264,7 @@ func TestCloudConfigTransformer(t *testing.T) {
262
264
g .Expect (err ).Should (MatchError (tc .errMsg ))
263
265
g .Expect (actual ).Should (Equal ("" ))
264
266
} else {
265
- var observed azure .Config
267
+ var observed azconfig .Config
266
268
g .Expect (json .Unmarshal ([]byte (actual ), & observed )).To (Succeed (), "Unmarshal of observed data should succeed" )
267
269
g .Expect (observed ).Should (Equal (tc .expected ))
268
270
}
0 commit comments