Skip to content

Commit 3f7eac7

Browse files
fmountclaude
authored andcommitted
Modernize Go code with latest style conventions
Applied automated modernization using gopls modernize tool to update: - Replace interface{} with any type alias (Go 1.18+) - Update range loops to use idiomatic range syntax - Replace fmt.Sprintf with fmt.Appendf where appropriate These changes improve code readability and align with current Go best practices. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Francesco Pantano <fpantano@redhat.com>
1 parent efeb18e commit 3f7eac7

11 files changed

Lines changed: 99 additions & 99 deletions

controllers/watcher_common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (r *Reconcilers) OverrideRequeueTimeout(timeout time.Duration) {
217217

218218
type conditionUpdater interface {
219219
Set(c *condition.Condition)
220-
MarkTrue(t condition.Type, messageFormat string, messageArgs ...interface{})
220+
MarkTrue(t condition.Type, messageFormat string, messageArgs ...any)
221221
}
222222

223223
// ensureSecret - ensures that the Secret object exists and the expected fields
@@ -290,7 +290,7 @@ func GenerateConfigsGeneric(
290290
ctx context.Context, helper *helper.Helper,
291291
instance client.Object,
292292
envVars *map[string]env.Setter,
293-
templateParameters map[string]interface{},
293+
templateParameters map[string]any,
294294
customData map[string]string,
295295
cmLabels map[string]string,
296296
scripts bool,

controllers/watcher_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func (r *WatcherReconciler) generateServiceConfigDBJobs(
792792
labels := labels.GetLabels(instance, labels.GetGroupLabel(watcher.ServiceName), map[string]string{})
793793
databaseAccount := db.GetAccount()
794794
databaseSecret := db.GetSecret()
795-
templateParameters := map[string]interface{}{
795+
templateParameters := map[string]any{
796796
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
797797
databaseAccount.Spec.UserName,
798798
string(databaseSecret.Data[mariadbv1.DatabasePasswordSelector]),

controllers/watcherapi_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func (r *WatcherAPIReconciler) generateServiceConfigs(
444444
if instance.Spec.TLS.CaBundleSecretName != "" {
445445
CaFilePath = tls.DownstreamTLSCABundlePath
446446
}
447-
templateParameters := map[string]interface{}{
447+
templateParameters := map[string]any{
448448
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
449449
databaseUsername,
450450
databasePassword,
@@ -478,9 +478,9 @@ func (r *WatcherAPIReconciler) generateServiceConfigs(
478478
}
479479

480480
// create httpd vhost template parameters
481-
httpdVhostConfig := map[string]interface{}{}
481+
httpdVhostConfig := map[string]any{}
482482
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
483-
endptConfig := map[string]interface{}{}
483+
endptConfig := map[string]any{}
484484
endptConfig["ServerName"] = fmt.Sprintf("%s-%s.%s.svc", watcher.ServiceName, endpt.String(), instance.Namespace)
485485
endptConfig["TLS"] = false // default TLS to false, and set it below to true if enabled
486486
if instance.Spec.TLS.API.Enabled(endpt) {

controllers/watcherapplier_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (r *WatcherApplierReconciler) generateServiceConfigs(
412412
if instance.Spec.TLS.CaBundleSecretName != "" {
413413
CaFilePath = tls.DownstreamTLSCABundlePath
414414
}
415-
templateParameters := map[string]interface{}{
415+
templateParameters := map[string]any{
416416
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
417417
databaseUsername,
418418
databasePassword,

controllers/watcherdecisionengine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func (r *WatcherDecisionEngineReconciler) generateServiceConfigs(
537537
if instance.Spec.TLS.CaBundleSecretName != "" {
538538
CaFilePath = tls.DownstreamTLSCABundlePath
539539
}
540-
templateParameters := map[string]interface{}{
540+
templateParameters := map[string]any{
541541
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
542542
databaseUsername,
543543
databasePassword,

tests/functional/base_test.go

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import (
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
)
3434

35-
func GetDefaultWatcherSpec() map[string]interface{} {
36-
return map[string]interface{}{
35+
func GetDefaultWatcherSpec() map[string]any {
36+
return map[string]any{
3737
"databaseInstance": "openstack",
3838
"secret": SecretName,
3939
}
@@ -97,36 +97,36 @@ func CreateInternalTopLevelSecretQuorum() *corev1.Secret {
9797
}
9898

9999
// Second Watcher Spec to test proper parameters substitution
100-
func GetNonDefaultWatcherSpec() map[string]interface{} {
101-
return map[string]interface{}{
100+
func GetNonDefaultWatcherSpec() map[string]any {
101+
return map[string]any{
102102
"apiContainerImageURL": "fake-API-Container-URL",
103103
"secret": SecretName,
104104
"preserveJobs": true,
105105
"databaseInstance": "fakeopenstack",
106106
"serviceUser": "fakeuser",
107107
"customServiceConfig": "# Global config",
108-
"apiServiceTemplate": map[string]interface{}{
108+
"apiServiceTemplate": map[string]any{
109109
"replicas": 2,
110110
"nodeSelector": map[string]string{"foo": "bar"},
111111
"customServiceConfig": "# Service config",
112-
"tls": map[string]interface{}{
112+
"tls": map[string]any{
113113
"caBundleSecretName": "combined-ca-bundle",
114114
},
115115
},
116116
"prometheusSecret": "custom-prometheus-config",
117117
"applierContainerImageURL": "fake-Applier-Container-URL",
118-
"applierServiceTemplate": map[string]interface{}{
118+
"applierServiceTemplate": map[string]any{
119119
"replicas": 1,
120120
"nodeSelector": map[string]string{"foo": "bar"},
121121
"customServiceConfig": "# Service config Applier",
122122
},
123123
"decisionengineContainerImageURL": "fake-DecisionEngine-Container-URL",
124-
"decisionengineServiceTemplate": map[string]interface{}{
124+
"decisionengineServiceTemplate": map[string]any{
125125
"replicas": 1,
126126
"nodeSelector": map[string]string{"foo": "bar"},
127127
"customServiceConfig": "# Service config DecisionEngine",
128128
},
129-
"dbPurge": map[string]interface{}{
129+
"dbPurge": map[string]any{
130130
"schedule": "1 2 * * *",
131131
"purgeAge": 1,
132132
},
@@ -135,14 +135,14 @@ func GetNonDefaultWatcherSpec() map[string]interface{} {
135135
}
136136

137137
// Watcher Spec to test TLSe
138-
func GetTLSeWatcherSpec() map[string]interface{} {
139-
return map[string]interface{}{
138+
func GetTLSeWatcherSpec() map[string]any {
139+
return map[string]any{
140140
"secret": SecretName,
141141
"databaseInstance": "openstack",
142-
"apiServiceTemplate": map[string]interface{}{
143-
"tls": map[string]interface{}{
142+
"apiServiceTemplate": map[string]any{
143+
"tls": map[string]any{
144144
"caBundleSecretName": "combined-ca-bundle",
145-
"api": map[string]interface{}{
145+
"api": map[string]any{
146146
"internal": map[string]string{
147147
"secretName": "cert-watcher-internal-svc",
148148
},
@@ -155,26 +155,26 @@ func GetTLSeWatcherSpec() map[string]interface{} {
155155
}
156156
}
157157

158-
func GetTLSIngressWatcherSpec() map[string]interface{} {
159-
return map[string]interface{}{
158+
func GetTLSIngressWatcherSpec() map[string]any {
159+
return map[string]any{
160160
"secret": SecretName,
161161
"databaseInstance": "openstack",
162-
"apiServiceTemplate": map[string]interface{}{
163-
"tls": map[string]interface{}{
162+
"apiServiceTemplate": map[string]any{
163+
"tls": map[string]any{
164164
"caBundleSecretName": "combined-ca-bundle",
165165
},
166166
},
167167
}
168168
}
169169

170-
func GetTLSPodLevelWatcherSpec() map[string]interface{} {
171-
return map[string]interface{}{
170+
func GetTLSPodLevelWatcherSpec() map[string]any {
171+
return map[string]any{
172172
"secret": SecretName,
173173
"databaseInstance": "openstack",
174-
"apiServiceTemplate": map[string]interface{}{
175-
"tls": map[string]interface{}{
174+
"apiServiceTemplate": map[string]any{
175+
"tls": map[string]any{
176176
"caBundleSecretName": "combined-ca-bundle",
177-
"api": map[string]interface{}{
177+
"api": map[string]any{
178178
"internal": map[string]string{
179179
"secretName": "cert-watcher-internal-svc",
180180
},
@@ -187,8 +187,8 @@ func GetTLSPodLevelWatcherSpec() map[string]interface{} {
187187
}
188188
}
189189

190-
func GetDefaultWatcherAPISpec() map[string]interface{} {
191-
return map[string]interface{}{
190+
func GetDefaultWatcherAPISpec() map[string]any {
191+
return map[string]any{
192192
"databaseInstance": "openstack",
193193
"secret": SecretName,
194194
"memcachedInstance": "memcached",
@@ -197,14 +197,14 @@ func GetDefaultWatcherAPISpec() map[string]interface{} {
197197
}
198198
}
199199

200-
func GetTLSWatcherAPISpec() map[string]interface{} {
201-
return map[string]interface{}{
200+
func GetTLSWatcherAPISpec() map[string]any {
201+
return map[string]any{
202202
"databaseInstance": "openstack",
203203
"secret": SecretName,
204204
"containerImage": "test://watcher",
205-
"tls": map[string]interface{}{
205+
"tls": map[string]any{
206206
"caBundleSecretName": "combined-ca-bundle",
207-
"api": map[string]interface{}{
207+
"api": map[string]any{
208208
"internal": map[string]string{
209209
"secretName": "cert-watcher-internal-svc",
210210
},
@@ -216,35 +216,35 @@ func GetTLSWatcherAPISpec() map[string]interface{} {
216216
}
217217

218218
}
219-
func GetTLSCaWatcherAPISpec() map[string]interface{} {
220-
return map[string]interface{}{
219+
func GetTLSCaWatcherAPISpec() map[string]any {
220+
return map[string]any{
221221
"databaseInstance": "openstack",
222222
"secret": SecretName,
223223
"containerImage": "test://watcher",
224-
"tls": map[string]interface{}{
224+
"tls": map[string]any{
225225
"caBundleSecretName": "combined-ca-bundle",
226226
},
227227
}
228228
}
229229

230-
func GetServiceOverrideWatcherAPISpec() map[string]interface{} {
231-
return map[string]interface{}{
230+
func GetServiceOverrideWatcherAPISpec() map[string]any {
231+
return map[string]any{
232232
"databaseInstance": "openstack",
233233
"secret": SecretName,
234234
"memcachedInstance": "memcached",
235235
"serviceAccount": "watcher-sa",
236236
"containerImage": "test://watcher",
237-
"override": map[string]interface{}{
238-
"service": map[string]interface{}{
239-
"internal": map[string]interface{}{
240-
"metadata": map[string]interface{}{
237+
"override": map[string]any{
238+
"service": map[string]any{
239+
"internal": map[string]any{
240+
"metadata": map[string]any{
241241
"annotations": map[string]string{
242242
"metallb.universe.tf/address-pool": "osp-internalapi",
243243
"metallb.universe.tf/loadBalancerIPs": "internal-lb-ip-1,internal-lb-ip-2",
244244
"metallb.universe.tf/allow-shared-ip": "osp-internalapi",
245245
},
246246
},
247-
"spec": map[string]interface{}{
247+
"spec": map[string]any{
248248
"type": "LoadBalancer",
249249
},
250250
},
@@ -253,8 +253,8 @@ func GetServiceOverrideWatcherAPISpec() map[string]interface{} {
253253
}
254254
}
255255

256-
func GetDefaultWatcherApplierSpec() map[string]interface{} {
257-
return map[string]interface{}{
256+
func GetDefaultWatcherApplierSpec() map[string]any {
257+
return map[string]any{
258258
"databaseInstance": "openstack",
259259
"secret": SecretName,
260260
"memcachedInstance": "memcached",
@@ -263,8 +263,8 @@ func GetDefaultWatcherApplierSpec() map[string]interface{} {
263263
}
264264
}
265265

266-
func GetDefaultWatcherDecisionEngineSpec() map[string]interface{} {
267-
return map[string]interface{}{
266+
func GetDefaultWatcherDecisionEngineSpec() map[string]any {
267+
return map[string]any{
268268
"databaseInstance": "openstack",
269269
"secret": SecretName,
270270
"memcachedInstance": "memcached",
@@ -273,11 +273,11 @@ func GetDefaultWatcherDecisionEngineSpec() map[string]interface{} {
273273
}
274274
}
275275

276-
func CreateWatcher(name types.NamespacedName, spec map[string]interface{}) client.Object {
277-
raw := map[string]interface{}{
276+
func CreateWatcher(name types.NamespacedName, spec map[string]any) client.Object {
277+
raw := map[string]any{
278278
"apiVersion": "watcher.openstack.org/v1beta1",
279279
"kind": "Watcher",
280-
"metadata": map[string]interface{}{
280+
"metadata": map[string]any{
281281
"name": name.Name,
282282
"namespace": name.Namespace,
283283
},
@@ -299,11 +299,11 @@ func WatcherConditionGetter(name types.NamespacedName) condition.Conditions {
299299
return instance.Status.Conditions
300300
}
301301

302-
func CreateWatcherAPI(name types.NamespacedName, spec map[string]interface{}) client.Object {
303-
raw := map[string]interface{}{
302+
func CreateWatcherAPI(name types.NamespacedName, spec map[string]any) client.Object {
303+
raw := map[string]any{
304304
"apiVersion": "watcher.openstack.org/v1beta1",
305305
"kind": "WatcherAPI",
306-
"metadata": map[string]interface{}{
306+
"metadata": map[string]any{
307307
"name": name.Name,
308308
"namespace": name.Namespace,
309309
},
@@ -325,11 +325,11 @@ func WatcherAPIConditionGetter(name types.NamespacedName) condition.Conditions {
325325
return instance.Status.Conditions
326326
}
327327

328-
func CreateWatcherApplier(name types.NamespacedName, spec map[string]interface{}) client.Object {
329-
raw := map[string]interface{}{
328+
func CreateWatcherApplier(name types.NamespacedName, spec map[string]any) client.Object {
329+
raw := map[string]any{
330330
"apiVersion": "watcher.openstack.org/v1beta1",
331331
"kind": "WatcherApplier",
332-
"metadata": map[string]interface{}{
332+
"metadata": map[string]any{
333333
"name": name.Name,
334334
"namespace": name.Namespace,
335335
},
@@ -360,18 +360,18 @@ func CreateWatcherMessageBusSecret(namespace string, name string) *corev1.Secret
360360
s := th.CreateSecret(
361361
types.NamespacedName{Namespace: namespace, Name: name},
362362
map[string][]byte{
363-
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", name)),
363+
"transport_url": fmt.Appendf(nil, "rabbit://%s/fake", name),
364364
},
365365
)
366366
logger.Info("Secret created", "name", name)
367367
return s
368368
}
369369

370-
func CreateWatcherDecisionEngine(name types.NamespacedName, spec map[string]interface{}) client.Object {
371-
raw := map[string]interface{}{
370+
func CreateWatcherDecisionEngine(name types.NamespacedName, spec map[string]any) client.Object {
371+
raw := map[string]any{
372372
"apiVersion": "watcher.openstack.org/v1beta1",
373373
"kind": "WatcherDecisionEngine",
374-
"metadata": map[string]interface{}{
374+
"metadata": map[string]any{
375375
"name": name.Name,
376376
"namespace": name.Namespace,
377377
},
@@ -422,16 +422,16 @@ func CreateCertSecret(name types.NamespacedName) *corev1.Secret {
422422
// test Watcher components. It returns both the user input representation
423423
// in the form of map[string]string, and the Golang expected representation
424424
// used in the test asserts.
425-
func GetSampleTopologySpec(label string) (map[string]interface{}, []corev1.TopologySpreadConstraint) {
425+
func GetSampleTopologySpec(label string) (map[string]any, []corev1.TopologySpreadConstraint) {
426426
// Build the topology Spec yaml representation
427-
topologySpec := map[string]interface{}{
428-
"topologySpreadConstraints": []map[string]interface{}{
427+
topologySpec := map[string]any{
428+
"topologySpreadConstraints": []map[string]any{
429429
{
430430
"maxSkew": 1,
431431
"topologyKey": corev1.LabelHostname,
432432
"whenUnsatisfiable": "ScheduleAnyway",
433-
"labelSelector": map[string]interface{}{
434-
"matchLabels": map[string]interface{}{
433+
"labelSelector": map[string]any{
434+
"matchLabels": map[string]any{
435435
"service": label,
436436
},
437437
},

0 commit comments

Comments
 (0)