Skip to content

Commit e82e1b3

Browse files
committed
Address review comments
Signed-off-by: Nolan Brubaker <nolan@nbrubaker.com>
1 parent e135317 commit e82e1b3

5 files changed

Lines changed: 36 additions & 21 deletions

File tree

pkg/cloud/aws/aws_config_transformer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
awsconfig "k8s.io/cloud-provider-aws/pkg/providers/v1/config"
1414
)
1515

16+
// defaultConfig is a string holding the absolute bare minimum INI string that the AWS CCM needs to start.
17+
// The value will be further customized for OCP in the CloudConfigTransformer.
1618
const defaultConfig = `[Global]
1719
`
1820

pkg/cloud/aws/aws_config_transformer_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ func TestCloudConfigTransformer(t *testing.T) {
1313
expected string
1414
}{
1515
{
16-
name: "empty source",
16+
name: "default source",
1717
source: `[Global]
1818
`, // This is the default that gets created for any OpenShift Cluster.
1919
expected: `[Global]
2020
DisableSecurityGroupIngress = false
2121
ClusterServiceLoadBalancerHealthProbeMode = Shared
2222
ClusterServiceSharedLoadBalancerHealthProbePort = 0
23+
`,
24+
},
25+
{
26+
name: "completely empty source",
27+
source: "", // This could happen in cases where the cluster was born prior to a cloud.conf being required.
28+
expected: `[Global]
29+
DisableSecurityGroupIngress = false
30+
ClusterServiceLoadBalancerHealthProbeMode = Shared
31+
ClusterServiceSharedLoadBalancerHealthProbePort = 0
2332
`,
2433
},
2534
{

pkg/cloud/cloud.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import (
2525
// consumer of the transformer.
2626
type cloudConfigTransformer func(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error)
2727

28-
// defaultCloudConfig returns a default cloud configuration in the event that a cluster does not have a source config map.
29-
// Clusters created prior to 4.14 do not always have a source config map.
30-
type defaultCloudConfig func(platform configv1.PlatformType) (string, error)
31-
3228
// GetCloudConfigTransformer returns the function that should be used to transform
3329
// the cloud configuration config map, and a boolean to indicate if the config should
3430
// be synced from the CCO namespace before applying the transformation.

pkg/controllers/cloud_config_sync_controller.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ func (r *CloudConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
115115
Namespace: OpenshiftConfigNamespace,
116116
}
117117
if err := r.Get(ctx, openshiftUnmanagedCMKey, sourceCM); errors.IsNotFound(err) {
118-
klog.Warningf("unmanaged cloud-config is not found, falling back to default cloud config.")
118+
klog.Warningf("managed cloud-config is not found, falling back to default cloud config.")
119119
} else if err != nil {
120-
klog.Errorf("unable to get cloud-config for sync")
120+
klog.Errorf("unable to get cloud-config for sync: %v", err)
121121
if err := r.setDegradedCondition(ctx); err != nil {
122122
return ctrl.Result{}, fmt.Errorf("failed to set conditions for cloud config controller: %v", err)
123123
}
124+
return ctrl.Result{}, err
124125
}
125126
}
126127

@@ -206,6 +207,9 @@ func (r *CloudConfigReconciler) isCloudConfigSyncNeeded(platformStatus *configv1
206207

207208
// prepareSourceConfigMap creates a usable ConfigMap for further processing into a cloud.conf file.
208209
func (r *CloudConfigReconciler) prepareSourceConfigMap(source *corev1.ConfigMap, infra *configv1.Infrastructure) (*corev1.ConfigMap, error) {
210+
if source == nil {
211+
return nil, fmt.Errorf("received empty configmap for cloud config")
212+
}
209213
cloudConfCm := source.DeepCopy()
210214
// We might have an empty ConfigMap in clusters created before 4.14.
211215
if cloudConfCm.Data == nil {
@@ -216,24 +220,27 @@ func (r *CloudConfigReconciler) prepareSourceConfigMap(source *corev1.ConfigMap,
216220
// Always use "cloud.conf" which is default one across openshift
217221
if _, ok := cloudConfCm.Data[defaultConfigKey]; ok {
218222
return cloudConfCm, nil
223+
} else {
224+
// Make an entry for the default key even if it didn't exist.
225+
cloudConfCm.Data[defaultConfigKey] = ""
219226
}
220227

221-
// If a user provides their own cloud config, copy that over into the default key.
228+
// If a user provides their own cloud config...
222229
infraConfigKey := infra.Spec.CloudConfig.Key
223-
if val, ok := cloudConfCm.Data[infraConfigKey]; ok {
224-
cloudConfCm.Data[defaultConfigKey] = val
225-
delete(cloudConfCm.Data, infraConfigKey)
226-
return cloudConfCm, nil
227-
} else if !ok && len(cloudConfCm.Data) > 0 {
228-
// Return an error if they provided a non-existent one and there was a cloud.conf specified.
229-
return nil, fmt.Errorf("key %s specified in infra resource does not exist in source configmap %s",
230-
infraConfigKey, client.ObjectKeyFromObject(source),
231-
)
230+
if infraConfigKey != "" {
231+
if val, ok := cloudConfCm.Data[infraConfigKey]; ok {
232+
// ..., copy that over into the default key.
233+
cloudConfCm.Data[defaultConfigKey] = val
234+
delete(cloudConfCm.Data, infraConfigKey)
235+
return cloudConfCm, nil
236+
} else if !ok {
237+
// Return an error if they provided a non-existent one and there was a cloud.conf specified.
238+
return nil, fmt.Errorf("key %s specified in infra resource does not exist in source configmap %s",
239+
infraConfigKey, client.ObjectKeyFromObject(source),
240+
)
241+
}
232242
}
233243

234-
// If there was no data in the configmap and the user didn't specify their own make a default entry for it.
235-
cloudConfCm.Data[defaultConfigKey] = ""
236-
237244
return cloudConfCm, nil
238245
}
239246

pkg/controllers/cloud_config_sync_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ var _ = Describe("Cloud config sync reconciler", func() {
462462
It("should sync a default config AWS platform if there is no reference in infra resource", func() {
463463
infraResource := makeInfrastructureResource(configv1.AWSPlatformType)
464464
infraResource.Spec.CloudConfig.Name = ""
465+
infraResource.Spec.CloudConfig.Key = ""
465466
Expect(cl.Create(ctx, infraResource)).To(Succeed())
466467

467468
infraResource.Status = makeInfraStatus(infraResource.Spec.PlatformSpec.Type)
@@ -509,7 +510,7 @@ var _ = Describe("Cloud config sync reconciler", func() {
509510
Expect(cl.Status().Update(ctx, infraResource.DeepCopy())).To(Succeed())
510511

511512
_, err := reconciler.Reconcile(context.TODO(), ctrl.Request{})
512-
Expect(err).To(Not(BeNil()))
513+
Expect(err.Error()).To(ContainSubstring("specified in infra resource does not exist in source configmap"))
513514

514515
})
515516
})

0 commit comments

Comments
 (0)