Skip to content

Commit 2220723

Browse files
fmountclaude
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 <[email protected]>
1 parent 092fa45 commit 2220723

File tree

9 files changed

+130
-130
lines changed

9 files changed

+130
-130
lines changed

controllers/glance_common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var (
7676

7777
type conditionUpdater interface {
7878
Set(c *condition.Condition)
79-
MarkTrue(t condition.Type, messageFormat string, messageArgs ...interface{})
79+
MarkTrue(t condition.Type, messageFormat string, messageArgs ...any)
8080
}
8181

8282
// verifyServiceSecret - ensures that the Secret object exists and the expected
@@ -173,7 +173,7 @@ func GenerateConfigsGeneric(
173173
ctx context.Context, h *helper.Helper,
174174
instance client.Object,
175175
envVars *map[string]env.Setter,
176-
templateParameters map[string]interface{},
176+
templateParameters map[string]any,
177177
customData map[string]string,
178178
cmLabels map[string]string,
179179
scripts bool,

controllers/glance_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ func (r *GlanceReconciler) generateServiceConfig(
10681068

10691069
// We only need a minimal 00-config.conf that is only used by db-sync job,
10701070
// hence only passing the database related parameters
1071-
templateParameters := map[string]interface{}{
1071+
templateParameters := map[string]any{
10721072
"MinimalConfig": true, // This tells the template to generate a minimal config
10731073
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
10741074
databaseAccount.Spec.UserName,

controllers/glanceapi_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(
776776
}
777777
}
778778
// iterate over availableBackends for backend specific cases
779-
for i := 0; i < len(availableBackends); i++ {
779+
for i := range availableBackends {
780780
backendToken := strings.SplitN(availableBackends[i], ":", 2)
781781
switch backendToken[1] {
782782
case "cinder":
@@ -1226,9 +1226,9 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
12261226
if instance.Spec.APIType != glancev1.APISingle {
12271227
endptName = fmt.Sprintf("%s-api", instance.Name)
12281228
}
1229-
httpdVhostConfig := map[string]interface{}{}
1229+
httpdVhostConfig := map[string]any{}
12301230
for endpt := range glanceEndpoints {
1231-
endptConfig := map[string]interface{}{}
1231+
endptConfig := map[string]any{}
12321232
endptConfig["ServerName"] = fmt.Sprintf("glance-%s.%s.svc", endpt.String(), instance.Namespace)
12331233
endptConfig["ServerAlias"] = fmt.Sprintf("%s.%s.svc", endptName, instance.Namespace)
12341234
endptConfig["TLS"] = false // default TLS to false, and set it bellow to true if enabled
@@ -1241,7 +1241,7 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
12411241
httpdVhostConfig[endpt.String()] = endptConfig
12421242
}
12431243

1244-
templateParameters := map[string]interface{}{
1244+
templateParameters := map[string]any{
12451245
"ServiceUser": instance.Spec.ServiceUser,
12461246
"ServicePassword": string(ospSecret.Data[instance.Spec.PasswordSelectors.Service]),
12471247
"KeystoneInternalURL": keystoneInternalURL,

test/functional/base_test.go

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ func GlanceAPIConditionGetter(name types.NamespacedName) condition.Conditions {
6767
}
6868

6969
func CreateDefaultGlance(name types.NamespacedName) client.Object {
70-
raw := map[string]interface{}{
70+
raw := map[string]any{
7171
"apiVersion": "glance.openstack.org/v1beta1",
7272
"kind": "Glance",
73-
"metadata": map[string]interface{}{
73+
"metadata": map[string]any{
7474
"name": name.Name,
7575
"namespace": name.Namespace,
7676
},
77-
"spec": map[string]interface{}{
77+
"spec": map[string]any{
7878
"memcachedInstance": "memcached",
7979
"keystoneEndpoint": "default",
8080
"databaseInstance": "openstack",
8181
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
82-
"storage": map[string]interface{}{
82+
"storage": map[string]any{
8383
"storageRequest": glanceTest.GlancePVCSize,
8484
},
8585
"glanceAPIs": GetAPIList(),
@@ -90,44 +90,44 @@ func CreateDefaultGlance(name types.NamespacedName) client.Object {
9090

9191
// GetGlanceEmptySpec - the resulting map is usually assigned to the top-level
9292
// Glance spec
93-
func GetGlanceEmptySpec() map[string]interface{} {
94-
return map[string]interface{}{
93+
func GetGlanceEmptySpec() map[string]any {
94+
return map[string]any{
9595
"keystoneEndpoint": "default",
9696
"notificationBusInstance": glanceTest.NotificationsBusInstance,
9797
"secret": SecretName,
9898
"databaseInstance": "openstack",
99-
"storage": map[string]interface{}{
99+
"storage": map[string]any{
100100
"storageRequest": glanceTest.GlancePVCSize,
101101
},
102-
"glanceAPIs": map[string]interface{}{},
102+
"glanceAPIs": map[string]any{},
103103
}
104104
}
105105

106-
func GetGlanceDefaultSpec() map[string]interface{} {
107-
return map[string]interface{}{
106+
func GetGlanceDefaultSpec() map[string]any {
107+
return map[string]any{
108108
"keystoneEndpoint": "default",
109109
"databaseInstance": "openstack",
110110
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
111111
"serviceUser": glanceName.Name,
112112
"secret": SecretName,
113113
"notificationBusInstance": glanceTest.NotificationsBusInstance,
114114
"glanceAPIs": GetAPIList(),
115-
"storage": map[string]interface{}{
115+
"storage": map[string]any{
116116
"storageRequest": glanceTest.GlancePVCSize,
117117
},
118118
}
119119
}
120120

121-
func GetGlanceDefaultSpecWithQuota() map[string]interface{} {
122-
return map[string]interface{}{
121+
func GetGlanceDefaultSpecWithQuota() map[string]any {
122+
return map[string]any{
123123
"keystoneEndpoint": "default",
124124
"databaseInstance": "openstack",
125125
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
126126
"serviceUser": glanceName.Name,
127127
"notificationBusInstance": glanceTest.NotificationsBusInstance,
128128
"secret": SecretName,
129129
"glanceAPIs": GetAPIList(),
130-
"storage": map[string]interface{}{
130+
"storage": map[string]any{
131131
"storageRequest": glanceTest.GlancePVCSize,
132132
},
133133
"quotas": glanceTest.GlanceQuotas,
@@ -136,29 +136,29 @@ func GetGlanceDefaultSpecWithQuota() map[string]interface{} {
136136
}
137137

138138
// By default we're splitting here
139-
func GetAPIList() map[string]interface{} {
140-
apiList := map[string]interface{}{
139+
func GetAPIList() map[string]any {
140+
apiList := map[string]any{
141141
"default": GetDefaultGlanceAPISpec(GlanceAPITypeSingle),
142142
}
143143
return apiList
144144
}
145145

146-
func GetGlanceAPIDefaultSpec() map[string]interface{} {
147-
return map[string]interface{}{
146+
func GetGlanceAPIDefaultSpec() map[string]any {
147+
return map[string]any{
148148
"replicas": 1,
149-
"storage": map[string]interface{}{
149+
"storage": map[string]any{
150150
"storageRequest": glanceTest.GlancePVCSize,
151151
},
152152
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
153153
}
154154
}
155155

156-
func CreateGlance(name types.NamespacedName, spec map[string]interface{}) client.Object {
156+
func CreateGlance(name types.NamespacedName, spec map[string]any) client.Object {
157157

158-
raw := map[string]interface{}{
158+
raw := map[string]any{
159159
"apiVersion": "glance.openstack.org/v1beta1",
160160
"kind": "Glance",
161-
"metadata": map[string]interface{}{
161+
"metadata": map[string]any{
162162
"name": name.Name,
163163
"namespace": name.Namespace,
164164
},
@@ -167,12 +167,12 @@ func CreateGlance(name types.NamespacedName, spec map[string]interface{}) client
167167
return th.CreateUnstructured(raw)
168168
}
169169

170-
func CreateGlanceAPI(name types.NamespacedName, spec map[string]interface{}) client.Object {
171-
raw := map[string]interface{}{
170+
func CreateGlanceAPI(name types.NamespacedName, spec map[string]any) client.Object {
171+
raw := map[string]any{
172172
"apiVersion": "glance.openstack.org/v1beta1",
173173
"kind": "GlanceAPI",
174-
"metadata": map[string]interface{}{
175-
"annotations": map[string]interface{}{
174+
"metadata": map[string]any{
175+
"annotations": map[string]any{
176176
"keystoneEndpoint": "true",
177177
},
178178
"name": name.Name,
@@ -194,27 +194,27 @@ func CreateGlanceSecret(namespace string, name string) *corev1.Secret {
194194
}
195195

196196
// GetDefaultGlanceSpec - It returns a default API built for testing purposes
197-
func GetDefaultGlanceSpec() map[string]interface{} {
198-
return map[string]interface{}{
197+
func GetDefaultGlanceSpec() map[string]any {
198+
return map[string]any{
199199
"databaseInstance": glanceTest.GlanceDatabaseName.Name,
200200
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
201201
"secret": SecretName,
202202
"customServiceConfig": GlanceDummyBackend,
203203
"notificationBusInstance": glanceTest.NotificationsBusInstance,
204204
"glanceAPIs": GetAPIList(),
205-
"storage": map[string]interface{}{
205+
"storage": map[string]any{
206206
"storageRequest": glanceTest.GlancePVCSize,
207207
},
208208
}
209209
}
210210

211211
// CreateGlanceAPISpec -
212-
func CreateGlanceAPISpec(apiType APIType) map[string]interface{} {
213-
spec := map[string]interface{}{
212+
func CreateGlanceAPISpec(apiType APIType) map[string]any {
213+
spec := map[string]any{
214214
"replicas": 1,
215215
"serviceAccount": glanceTest.GlanceSA.Name,
216216
"containerImage": glanceTest.ContainerImage,
217-
"storage": map[string]interface{}{
217+
"storage": map[string]any{
218218
"storageRequest": glanceTest.GlancePVCSize,
219219
},
220220
"apiType": apiType,
@@ -230,16 +230,16 @@ func CreateGlanceAPISpec(apiType APIType) map[string]interface{} {
230230
// CreateGlanceAPIWithTopologySpec - It returns a GlanceAPISpec where a
231231
// topology is referenced. It also overrides the top-level parameter of
232232
// the top-level glance controller
233-
func CreateGlanceAPIWithTopologySpec() map[string]interface{} {
233+
func CreateGlanceAPIWithTopologySpec() map[string]any {
234234
rawSpec := GetDefaultGlanceSpec()
235235
// Add top-level topologyRef
236-
rawSpec["topologyRef"] = map[string]interface{}{
236+
rawSpec["topologyRef"] = map[string]any{
237237
"name": glanceTest.GlanceAPITopologies[0].Name,
238238
}
239239
// Override topologyRef for the subCR
240-
rawSpec["glanceAPIs"] = map[string]interface{}{
241-
"default": map[string]interface{}{
242-
"topologyRef": map[string]interface{}{
240+
rawSpec["glanceAPIs"] = map[string]any{
241+
"default": map[string]any{
242+
"topologyRef": map[string]any{
243243
"name": glanceTest.GlanceAPITopologies[1].Name,
244244
},
245245
},
@@ -248,12 +248,12 @@ func CreateGlanceAPIWithTopologySpec() map[string]interface{} {
248248
}
249249

250250
// GetDefaultGlanceAPISpec -
251-
func GetDefaultGlanceAPISpec(apiType APIType) map[string]interface{} {
252-
spec := map[string]interface{}{
251+
func GetDefaultGlanceAPISpec(apiType APIType) map[string]any {
252+
spec := map[string]any{
253253
"replicas": 1,
254254
"containerImage": glanceTest.ContainerImage,
255255
"serviceAccount": glanceTest.GlanceSA.Name,
256-
"storage": map[string]interface{}{
256+
"storage": map[string]any{
257257
"storageRequest": glanceTest.GlancePVCSize,
258258
},
259259
"type": apiType,
@@ -267,19 +267,19 @@ func GetDefaultGlanceAPISpec(apiType APIType) map[string]interface{} {
267267
}
268268

269269
// GetTLSGlanceAPISpec -
270-
func GetTLSGlanceAPISpec(apiType APIType) map[string]interface{} {
270+
func GetTLSGlanceAPISpec(apiType APIType) map[string]any {
271271
spec := CreateGlanceAPISpec(apiType)
272-
maps.Copy(spec, map[string]interface{}{
272+
maps.Copy(spec, map[string]any{
273273
"databaseHostname": "openstack",
274274
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
275275
"secret": SecretName,
276276
"notificationBusInstance": glanceTest.NotificationsBusInstance,
277-
"tls": map[string]interface{}{
278-
"api": map[string]interface{}{
279-
"internal": map[string]interface{}{
277+
"tls": map[string]any{
278+
"api": map[string]any{
279+
"internal": map[string]any{
280280
"secretName": InternalCertSecretName,
281281
},
282-
"public": map[string]interface{}{
282+
"public": map[string]any{
283283
"secretName": PublicCertSecretName,
284284
},
285285
},
@@ -346,26 +346,26 @@ func GetDummyBackend() string {
346346

347347
// GetExtraMounts - Utility function that simulates extraMounts pointing
348348
// to a Ceph secret
349-
func GetExtraMounts() []map[string]interface{} {
350-
return []map[string]interface{}{
349+
func GetExtraMounts() []map[string]any {
350+
return []map[string]any{
351351
{
352352
"name": glanceTest.Instance.Name,
353353
"region": "az0",
354-
"extraVol": []map[string]interface{}{
354+
"extraVol": []map[string]any{
355355
{
356356
"extraVolType": GlanceCephExtraMountsSecretName,
357357
"propagation": []string{
358358
"GlanceAPI",
359359
},
360-
"volumes": []map[string]interface{}{
360+
"volumes": []map[string]any{
361361
{
362362
"name": GlanceCephExtraMountsSecretName,
363-
"secret": map[string]interface{}{
363+
"secret": map[string]any{
364364
"secretName": GlanceCephExtraMountsSecretName,
365365
},
366366
},
367367
},
368-
"mounts": []map[string]interface{}{
368+
"mounts": []map[string]any{
369369
{
370370
"name": GlanceCephExtraMountsSecretName,
371371
"mountPath": GlanceCephExtraMountsPath,
@@ -389,16 +389,16 @@ func GetExtraMounts() []map[string]interface{} {
389389
// multi AZ, which is not applicable in this context
390390
func GetSampleTopologySpec(
391391
label string,
392-
) (map[string]interface{}, []corev1.TopologySpreadConstraint) {
392+
) (map[string]any, []corev1.TopologySpreadConstraint) {
393393
// Build the topology Spec
394-
topologySpec := map[string]interface{}{
395-
"topologySpreadConstraints": []map[string]interface{}{
394+
topologySpec := map[string]any{
395+
"topologySpreadConstraints": []map[string]any{
396396
{
397397
"maxSkew": 1,
398398
"topologyKey": corev1.LabelHostname,
399399
"whenUnsatisfiable": "ScheduleAnyway",
400-
"labelSelector": map[string]interface{}{
401-
"matchLabels": map[string]interface{}{
400+
"labelSelector": map[string]any{
401+
"matchLabels": map[string]any{
402402
"component": label,
403403
},
404404
},
@@ -424,10 +424,10 @@ func GetSampleTopologySpec(
424424
// CreateDefaultCinderInstance - Creates a default Cinder CR used as a
425425
// dependency when a Cinder backend is defined in glance
426426
func CreateDefaultCinderInstance(cinderName types.NamespacedName) client.Object {
427-
raw := map[string]interface{}{
427+
raw := map[string]any{
428428
"apiVersion": "cinder.openstack.org/v1beta1",
429429
"kind": "Cinder",
430-
"metadata": map[string]interface{}{
430+
"metadata": map[string]any{
431431
"name": cinderName.Name,
432432
"namespace": cinderName.Namespace,
433433
},
@@ -440,7 +440,7 @@ func CreateGlanceMessageBusSecret(namespace string, name string) *corev1.Secret
440440
s := th.CreateSecret(
441441
types.NamespacedName{Namespace: namespace, Name: name},
442442
map[string][]byte{
443-
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", name)),
443+
"transport_url": fmt.Appendf(nil, "rabbit://%s/fake", name),
444444
},
445445
)
446446
logger.Info("Secret created", "name", name)

0 commit comments

Comments
 (0)