Skip to content

Commit 01613c4

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 <[email protected]> Signed-off-by: Francesco Pantano <[email protected]>
1 parent ab65224 commit 01613c4

File tree

4 files changed

+45
-46
lines changed

4 files changed

+45
-46
lines changed

controllers/placementapi_controller.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package controllers
2020
import (
2121
"context"
2222
"fmt"
23+
"maps"
2324
"time"
2425

2526
"k8s.io/apimachinery/pkg/fields"
@@ -69,7 +70,7 @@ import (
6970

7071
type conditionUpdater interface {
7172
Set(c *condition.Condition)
72-
MarkTrue(t condition.Type, messageFormat string, messageArgs ...interface{})
73+
MarkTrue(t condition.Type, messageFormat string, messageArgs ...any)
7374
}
7475

7576
// GetSecret interface defines methods for objects that can provide secret names
@@ -1336,9 +1337,7 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps(
13361337
common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig,
13371338
"my.cnf": db.GetDatabaseClientConfig(tlsCfg), //(mschuppert) for now just get the default my.cnf
13381339
}
1339-
for key, data := range instance.Spec.DefaultConfigOverwrite {
1340-
customData[key] = data
1341-
}
1340+
maps.Copy(customData, instance.Spec.DefaultConfigOverwrite)
13421341

13431342
keystoneAPI, err := keystonev1.GetKeystoneAPI(ctx, h, instance.Namespace, map[string]string{})
13441343
if err != nil {
@@ -1356,7 +1355,7 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps(
13561355
databaseAccount := db.GetAccount()
13571356
dbSecret := db.GetSecret()
13581357

1359-
templateParameters := map[string]interface{}{
1358+
templateParameters := map[string]any{
13601359
"ServiceUser": instance.Spec.ServiceUser,
13611360
"KeystoneInternalURL": keystoneInternalURL,
13621361
"KeystonePublicURL": keystonePublicURL,
@@ -1371,9 +1370,9 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps(
13711370
}
13721371

13731372
// create httpd vhost template parameters
1374-
httpdVhostConfig := map[string]interface{}{}
1373+
httpdVhostConfig := map[string]any{}
13751374
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
1376-
endptConfig := map[string]interface{}{}
1375+
endptConfig := map[string]any{}
13771376
endptConfig["ServerName"] = fmt.Sprintf("placement-%s.%s.svc", endpt.String(), instance.Namespace)
13781377
endptConfig["TLS"] = false // default TLS to false, and set it bellow to true if enabled
13791378
if instance.Spec.TLS.API.Enabled(endpt) {

tests/functional/base_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,26 @@ func CreateNames(placementAPIName types.NamespacedName) Names {
112112
}
113113
}
114114

115-
func GetDefaultPlacementAPISpec() map[string]interface{} {
116-
return map[string]interface{}{
115+
func GetDefaultPlacementAPISpec() map[string]any {
116+
return map[string]any{
117117
"databaseInstance": "openstack",
118118
"secret": SecretName,
119119
"databaseAccount": AccountName,
120120
}
121121
}
122122

123-
func GetTLSPlacementAPISpec(names Names) map[string]interface{} {
124-
return map[string]interface{}{
123+
func GetTLSPlacementAPISpec(names Names) map[string]any {
124+
return map[string]any{
125125
"databaseInstance": "openstack",
126126
"replicas": 1,
127127
"secret": SecretName,
128128
"databaseAccount": AccountName,
129-
"tls": map[string]interface{}{
130-
"api": map[string]interface{}{
131-
"internal": map[string]interface{}{
129+
"tls": map[string]any{
130+
"api": map[string]any{
131+
"internal": map[string]any{
132132
"secretName": names.InternalCertSecretName.Name,
133133
},
134-
"public": map[string]interface{}{
134+
"public": map[string]any{
135135
"secretName": names.PublicCertSecretName.Name,
136136
},
137137
},
@@ -140,12 +140,12 @@ func GetTLSPlacementAPISpec(names Names) map[string]interface{} {
140140
}
141141
}
142142

143-
func CreatePlacementAPI(name types.NamespacedName, spec map[string]interface{}) client.Object {
143+
func CreatePlacementAPI(name types.NamespacedName, spec map[string]any) client.Object {
144144

145-
raw := map[string]interface{}{
145+
raw := map[string]any{
146146
"apiVersion": "placement.openstack.org/v1beta1",
147147
"kind": "PlacementAPI",
148-
"metadata": map[string]interface{}{
148+
"metadata": map[string]any{
149149
"name": name.Name,
150150
"namespace": name.Namespace,
151151
},
@@ -185,16 +185,16 @@ func PlacementConditionGetter(name types.NamespacedName) condition.Conditions {
185185
// want to avoid by default
186186
// 2. Usually a topologySpreadConstraints is used to take care about
187187
// multi AZ, which is not applicable in this context
188-
func GetSampleTopologySpec(label string) (map[string]interface{}, []corev1.TopologySpreadConstraint) {
188+
func GetSampleTopologySpec(label string) (map[string]any, []corev1.TopologySpreadConstraint) {
189189
// Build the topology Spec
190-
topologySpec := map[string]interface{}{
191-
"topologySpreadConstraints": []map[string]interface{}{
190+
topologySpec := map[string]any{
191+
"topologySpreadConstraints": []map[string]any{
192192
{
193193
"maxSkew": 1,
194194
"topologyKey": corev1.LabelHostname,
195195
"whenUnsatisfiable": "ScheduleAnyway",
196-
"labelSelector": map[string]interface{}{
197-
"matchLabels": map[string]interface{}{
196+
"labelSelector": map[string]any{
197+
"matchLabels": map[string]any{
198198
"service": placement.ServiceName,
199199
"topology": label,
200200
},

tests/functional/placementapi_controller_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ var _ = Describe("PlacementAPI controller", func() {
248248
BeforeEach(func() {
249249
spec := GetDefaultPlacementAPISpec()
250250
spec["customServiceConfig"] = "foo = bar"
251-
spec["defaultConfigOverwrite"] = map[string]interface{}{
251+
spec["defaultConfigOverwrite"] = map[string]any{
252252
"policy.yaml": "\"placement:resource_providers:list\": \"!\"",
253253
}
254254
DeferCleanup(th.DeleteInstance, CreatePlacementAPI(names.PlacementAPIName, spec))
@@ -667,8 +667,8 @@ var _ = Describe("PlacementAPI controller", func() {
667667
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))
668668

669669
spec := GetDefaultPlacementAPISpec()
670-
serviceOverride := map[string]interface{}{}
671-
serviceOverride["internal"] = map[string]interface{}{
670+
serviceOverride := map[string]any{}
671+
serviceOverride["internal"] = map[string]any{
672672
"metadata": map[string]map[string]string{
673673
"annotations": {
674674
"dnsmasq.network.openstack.org/hostname": "placement-internal.openstack.svc",
@@ -681,12 +681,12 @@ var _ = Describe("PlacementAPI controller", func() {
681681
"service": "placement",
682682
},
683683
},
684-
"spec": map[string]interface{}{
684+
"spec": map[string]any{
685685
"type": "LoadBalancer",
686686
},
687687
}
688688

689-
spec["override"] = map[string]interface{}{
689+
spec["override"] = map[string]any{
690690
"service": serviceOverride,
691691
}
692692

@@ -754,12 +754,12 @@ var _ = Describe("PlacementAPI controller", func() {
754754
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))
755755

756756
spec := GetDefaultPlacementAPISpec()
757-
serviceOverride := map[string]interface{}{}
758-
serviceOverride["public"] = map[string]interface{}{
757+
serviceOverride := map[string]any{}
758+
serviceOverride["public"] = map[string]any{
759759
"endpointURL": "http://placement-openstack.apps-crc.testing",
760760
}
761761

762-
spec["override"] = map[string]interface{}{
762+
spec["override"] = map[string]any{
763763
"service": serviceOverride,
764764
}
765765

@@ -996,7 +996,7 @@ var _ = Describe("PlacementAPI controller", func() {
996996
When("A PlacementAPI is created with a wrong topologyref", func() {
997997
BeforeEach(func() {
998998
spec := GetDefaultPlacementAPISpec()
999-
spec["topologyRef"] = map[string]interface{}{
999+
spec["topologyRef"] = map[string]any{
10001000
"name": "foo",
10011001
}
10021002
placement := CreatePlacementAPI(names.PlacementAPIName, spec)
@@ -1041,7 +1041,7 @@ var _ = Describe("PlacementAPI controller", func() {
10411041
infra.CreateTopology(t, topologySpec)
10421042
}
10431043
spec := GetDefaultPlacementAPISpec()
1044-
spec["topologyRef"] = map[string]interface{}{
1044+
spec["topologyRef"] = map[string]any{
10451045
"name": topologyRef.Name,
10461046
}
10471047
placement := CreatePlacementAPI(names.PlacementAPIName, spec)
@@ -1166,7 +1166,7 @@ var _ = Describe("PlacementAPI controller", func() {
11661166
When("A PlacementAPI is created with nodeSelector", func() {
11671167
BeforeEach(func() {
11681168
spec := GetDefaultPlacementAPISpec()
1169-
spec["nodeSelector"] = map[string]interface{}{
1169+
spec["nodeSelector"] = map[string]any{
11701170
"foo": "bar",
11711171
}
11721172

tests/functional/placementapi_webhook_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ var _ = Describe("PlacementAPI Webhook", func() {
8282

8383
It("rejects PlacementAPI with wrong defaultConfigOverwrite", func() {
8484
spec := GetDefaultPlacementAPISpec()
85-
spec["defaultConfigOverwrite"] = map[string]interface{}{
85+
spec["defaultConfigOverwrite"] = map[string]any{
8686
"policy.yaml": "support",
8787
"api-paste.ini": "not supported",
8888
}
89-
raw := map[string]interface{}{
89+
raw := map[string]any{
9090
"apiVersion": "placement.openstack.org/v1beta1",
9191
"kind": "PlacementAPI",
92-
"metadata": map[string]interface{}{
92+
"metadata": map[string]any{
9393
"name": placementAPIName.Name,
9494
"namespace": placementAPIName.Namespace,
9595
},
@@ -114,17 +114,17 @@ var _ = Describe("PlacementAPI Webhook", func() {
114114

115115
It("rejects with wrong service override endpoint type", func() {
116116
spec := GetDefaultPlacementAPISpec()
117-
spec["override"] = map[string]interface{}{
118-
"service": map[string]interface{}{
119-
"internal": map[string]interface{}{},
120-
"wrooong": map[string]interface{}{},
117+
spec["override"] = map[string]any{
118+
"service": map[string]any{
119+
"internal": map[string]any{},
120+
"wrooong": map[string]any{},
121121
},
122122
}
123123

124-
raw := map[string]interface{}{
124+
raw := map[string]any{
125125
"apiVersion": "placement.openstack.org/v1beta1",
126126
"kind": "PlacementAPI",
127-
"metadata": map[string]interface{}{
127+
"metadata": map[string]any{
128128
"name": placementAPIName.Name,
129129
"namespace": placementAPIName.Namespace,
130130
},
@@ -194,14 +194,14 @@ var _ = Describe("PlacementAPI Webhook", func() {
194194
It("rejects a wrong TopologyRef on a different namespace", func() {
195195
spec := GetDefaultPlacementAPISpec()
196196
// Inject a topologyRef that points to a different namespace
197-
spec["topologyRef"] = map[string]interface{}{
197+
spec["topologyRef"] = map[string]any{
198198
"name": "foo",
199199
"namespace": "bar",
200200
}
201-
raw := map[string]interface{}{
201+
raw := map[string]any{
202202
"apiVersion": "placement.openstack.org/v1beta1",
203203
"kind": "PlacementAPI",
204-
"metadata": map[string]interface{}{
204+
"metadata": map[string]any{
205205
"name": placementAPIName.Name,
206206
"namespace": placementAPIName.Namespace,
207207
},

0 commit comments

Comments
 (0)