Skip to content

Commit 06bc1b7

Browse files
committed
fix: resolve linting issues
- Replace string literals with testNamespaceName constant - Reduce complexity in addConfigMapToHash function - Add blank lines before return statements - Fix whitespace/cuddling issues per wsl linter
1 parent dd34613 commit 06bc1b7

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

internal/controller/configmap_changes_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func TestConfigMapChangesAreAppliedToTheProvider(t *testing.T) {
8383
if err := env.Get(ctx, client.ObjectKeyFromObject(coreProvider), coreProvider); err != nil {
8484
return false
8585
}
86+
8687
return conditions.IsTrue(coreProvider, operatorv1.ProviderInstalledCondition)
8788
}, timeout).Should(BeTrue())
8889

@@ -135,6 +136,7 @@ func TestConfigMapChangesAreAppliedToTheProvider(t *testing.T) {
135136
return false
136137
}
137138
hash := provider.GetAnnotations()[appliedSpecHashAnnotation]
139+
138140
return hash != ""
139141
}, timeout).Should(BeTrue(), "Provider should have a hash annotation after reconciliation")
140142

@@ -159,6 +161,7 @@ func TestConfigMapChangesAreAppliedToTheProvider(t *testing.T) {
159161
}
160162

161163
currentHash := provider.GetAnnotations()[appliedSpecHashAnnotation]
164+
162165
return currentHash != "" && currentHash != initialHash
163166
}, 30*time.Second).Should(BeTrue())
164167

internal/controller/configmaps_to_providers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func newConfigMapToProviderFuncMapForProviderList(k8sClient client.Client, provi
6565

6666
if selector.Matches(configMapLabels) {
6767
log.V(1).Info("ConfigMap matches provider selector, enqueueing reconcile request")
68+
6869
requests = append(requests, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(provider)})
6970
}
7071
}

internal/controller/configmaps_to_providers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
func TestProviderConfigMapMapper(t *testing.T) {
3232
g := NewWithT(t)
3333

34-
namespace := "test-namespace"
34+
namespace := testNamespaceName
3535
configMapLabels := map[string]string{
3636
"provider-components": "edge",
3737
"version": "v0.1.19",
@@ -138,7 +138,7 @@ func TestProviderConfigMapMapper(t *testing.T) {
138138
func TestProviderConfigMapMapperWithExpressions(t *testing.T) {
139139
g := NewWithT(t)
140140

141-
namespace := "test-namespace"
141+
namespace := testNamespaceName
142142
configMapLabels := map[string]string{
143143
"provider-components": "edge",
144144
"version": "v0.1.19",
@@ -193,7 +193,7 @@ func TestProviderConfigMapMapperWithExpressions(t *testing.T) {
193193
func TestProviderConfigMapMapperNoMatches(t *testing.T) {
194194
g := NewWithT(t)
195195

196-
namespace := "test-namespace"
196+
namespace := testNamespaceName
197197
configMapLabels := map[string]string{
198198
"provider-components": "azure",
199199
"version": "v1.9.3",

internal/controller/genericprovider_controller.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -292,37 +292,43 @@ func addConfigSecretToHash(ctx context.Context, k8sClient client.Client, hash ha
292292

293293
func addConfigMapToHash(ctx context.Context, k8sClient client.Client, hash hash.Hash, provider genericprovider.GenericProvider) error {
294294
spec := provider.GetSpec()
295-
if spec.FetchConfig != nil && spec.FetchConfig.Selector != nil {
296-
// List ConfigMaps that match the provider's selector
297-
selector, err := metav1.LabelSelectorAsSelector(spec.FetchConfig.Selector)
298-
if err != nil {
299-
return err
300-
}
295+
if spec.FetchConfig == nil || spec.FetchConfig.Selector == nil {
296+
return nil
297+
}
301298

302-
configMapList := &corev1.ConfigMapList{}
303-
listOpts := []client.ListOption{
304-
client.MatchingLabelsSelector{Selector: selector},
305-
client.InNamespace(provider.GetNamespace()),
306-
}
299+
return processProviderConfigMaps(ctx, k8sClient, hash, provider, spec.FetchConfig.Selector)
300+
}
307301

308-
if err := k8sClient.List(ctx, configMapList, listOpts...); err != nil {
309-
return err
310-
}
302+
func processProviderConfigMaps(ctx context.Context, k8sClient client.Client, hash hash.Hash, provider genericprovider.GenericProvider, selector *metav1.LabelSelector) error {
303+
// List ConfigMaps that match the provider's selector
304+
labelSelector, err := metav1.LabelSelectorAsSelector(selector)
305+
if err != nil {
306+
return err
307+
}
311308

312-
// Ensure only one ConfigMap matches the selector
313-
if len(configMapList.Items) > 1 {
314-
return fmt.Errorf("multiple ConfigMaps match the provider selector, only one ConfigMap per provider is allowed")
315-
}
309+
configMapList := &corev1.ConfigMapList{}
310+
listOpts := []client.ListOption{
311+
client.MatchingLabelsSelector{Selector: labelSelector},
312+
client.InNamespace(provider.GetNamespace()),
313+
}
316314

317-
// Add the ConfigMap's data to the hash (if any ConfigMap exists)
318-
if len(configMapList.Items) == 1 {
319-
cm := configMapList.Items[0]
320-
if err := addObjectToHash(hash, cm.Data); err != nil {
321-
return err
322-
}
323-
if err := addObjectToHash(hash, cm.BinaryData); err != nil {
324-
return err
325-
}
315+
if err := k8sClient.List(ctx, configMapList, listOpts...); err != nil {
316+
return err
317+
}
318+
319+
// Ensure only one ConfigMap matches the selector
320+
if len(configMapList.Items) > 1 {
321+
return fmt.Errorf("multiple ConfigMaps match the provider selector, only one ConfigMap per provider is allowed")
322+
}
323+
324+
// Add the ConfigMap's data to the hash (if any ConfigMap exists)
325+
if len(configMapList.Items) == 1 {
326+
cm := configMapList.Items[0]
327+
if err := addObjectToHash(hash, cm.Data); err != nil {
328+
return err
329+
}
330+
if err := addObjectToHash(hash, cm.BinaryData); err != nil {
331+
return err
326332
}
327333
}
328334

0 commit comments

Comments
 (0)