Skip to content

Commit 3cc98ad

Browse files
Merge pull request #629 from fmount/modernize
Modernize Go code with latest style conventions
2 parents f73c5ec + 867e084 commit 3cc98ad

File tree

5 files changed

+59
-60
lines changed

5 files changed

+59
-60
lines changed

controllers/keystoneapi_controller.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23+
"maps"
2324
"sort"
2425
"strconv"
2526
"time"
@@ -1325,9 +1326,7 @@ func (r *KeystoneAPIReconciler) generateServiceConfigMaps(
13251326
common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig,
13261327
"my.cnf": db.GetDatabaseClientConfig(tlsCfg), //(mschuppert) for now just get the default my.cnf
13271328
}
1328-
for key, data := range instance.Spec.DefaultConfigOverwrite {
1329-
customData[key] = data
1330-
}
1329+
maps.Copy(customData, instance.Spec.DefaultConfigOverwrite)
13311330

13321331
transportURLSecret, _, err := oko_secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace)
13331332
if err != nil {
@@ -1337,7 +1336,7 @@ func (r *KeystoneAPIReconciler) generateServiceConfigMaps(
13371336
databaseAccount := db.GetAccount()
13381337
dbSecret := db.GetSecret()
13391338

1340-
templateParameters := map[string]interface{}{
1339+
templateParameters := map[string]any{
13411340
"MemcachedServers": mc.GetMemcachedServerListString(),
13421341
"MemcachedServersWithInet": mc.GetMemcachedServerListWithInetString(),
13431342
"MemcachedTLS": mc.GetMemcachedTLSSupport(),
@@ -1376,9 +1375,9 @@ func (r *KeystoneAPIReconciler) generateServiceConfigMaps(
13761375

13771376
// create httpd vhost template parameters
13781377
customTemplates := map[string]string{}
1379-
httpdVhostConfig := map[string]interface{}{}
1378+
httpdVhostConfig := map[string]any{}
13801379
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
1381-
endptConfig := map[string]interface{}{}
1380+
endptConfig := map[string]any{}
13821381
endptConfig["ServerName"] = fmt.Sprintf("%s-%s.%s.svc", instance.Name, endpt.String(), instance.Namespace)
13831382
endptConfig["TLS"] = false // default TLS to false, and set it bellow to true if enabled
13841383
if instance.Spec.TLS.API.Enabled(endpt) {
@@ -1441,7 +1440,7 @@ func (r *KeystoneAPIReconciler) reconcileCloudConfig(
14411440
) error {
14421441
// clouds.yaml
14431442
var openStackConfig keystone.OpenStackConfig
1444-
templateParameters := make(map[string]interface{})
1443+
templateParameters := make(map[string]any)
14451444
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(keystone.ServiceName), map[string]string{})
14461445

14471446
authURL, err := instance.GetEndpoint(endpoint.EndpointPublic)
@@ -1740,7 +1739,7 @@ func (r *KeystoneAPIReconciler) ensureFederationRealmConfig(
17401739
}
17411740
newSecretData["_filenames.json"] = string(filenamesJSON)
17421741

1743-
templateParameters := make(map[string]interface{})
1742+
templateParameters := make(map[string]any)
17441743
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(keystone.ServiceName), map[string]string{})
17451744
newSecret := []util.Template{
17461745
{

pkg/keystone/volumes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func getVolumes(
3535
fernetKeys := []corev1.KeyToPath{}
3636
numberKeys := int(*instance.Spec.FernetMaxActiveKeys)
3737

38-
for i := 0; i < numberKeys; i++ {
38+
for i := range numberKeys {
3939
fernetKeys = append(
4040
fernetKeys,
4141
corev1.KeyToPath{

tests/functional/base_test.go

Lines changed: 24 additions & 24 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 GetKeystoneAPISpec(fernetMaxKeys int32) map[string]interface{} {
36-
return map[string]interface{}{
35+
func GetKeystoneAPISpec(fernetMaxKeys int32) map[string]any {
36+
return map[string]any{
3737
"databaseInstance": "openstack",
3838
"replicas": 1,
3939
"secret": SecretName,
@@ -42,22 +42,22 @@ func GetKeystoneAPISpec(fernetMaxKeys int32) map[string]interface{} {
4242
}
4343
}
4444

45-
func GetDefaultKeystoneAPISpec() map[string]interface{} {
45+
func GetDefaultKeystoneAPISpec() map[string]any {
4646
return GetKeystoneAPISpec(5)
4747
}
4848

49-
func GetTLSKeystoneAPISpec() map[string]interface{} {
50-
return map[string]interface{}{
49+
func GetTLSKeystoneAPISpec() map[string]any {
50+
return map[string]any{
5151
"databaseInstance": "openstack",
5252
"replicas": 1,
5353
"secret": SecretName,
5454
"databaseAccount": AccountName,
55-
"tls": map[string]interface{}{
56-
"api": map[string]interface{}{
57-
"internal": map[string]interface{}{
55+
"tls": map[string]any{
56+
"api": map[string]any{
57+
"internal": map[string]any{
5858
"secretName": InternalCertSecretName,
5959
},
60-
"public": map[string]interface{}{
60+
"public": map[string]any{
6161
"secretName": PublicCertSecretName,
6262
},
6363
},
@@ -66,12 +66,12 @@ func GetTLSKeystoneAPISpec() map[string]interface{} {
6666
}
6767
}
6868

69-
func CreateKeystoneAPI(name types.NamespacedName, spec map[string]interface{}) client.Object {
69+
func CreateKeystoneAPI(name types.NamespacedName, spec map[string]any) client.Object {
7070

71-
raw := map[string]interface{}{
71+
raw := map[string]any{
7272
"apiVersion": "keystone.openstack.org/v1beta1",
7373
"kind": "KeystoneAPI",
74-
"metadata": map[string]interface{}{
74+
"metadata": map[string]any{
7575
"name": name.Name,
7676
"namespace": name.Namespace,
7777
},
@@ -114,7 +114,7 @@ func CreateKeystoneMessageBusSecret(namespace string, name string) *corev1.Secre
114114
s := th.CreateSecret(
115115
types.NamespacedName{Namespace: namespace, Name: name},
116116
map[string][]byte{
117-
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", name)),
117+
"transport_url": fmt.Appendf(nil, "rabbit://%s/fake", name),
118118
},
119119
)
120120
logger.Info("Secret created", "name", name)
@@ -129,16 +129,16 @@ func CreateKeystoneMessageBusSecret(namespace string, name string) *corev1.Secre
129129
// want to avoid by default
130130
// 2. Usually a topologySpreadConstraints is used to take care about
131131
// multi AZ, which is not applicable in this context
132-
func GetSampleTopologySpec(label string) (map[string]interface{}, []corev1.TopologySpreadConstraint) {
132+
func GetSampleTopologySpec(label string) (map[string]any, []corev1.TopologySpreadConstraint) {
133133
// Build the topology Spec
134-
topologySpec := map[string]interface{}{
135-
"topologySpreadConstraints": []map[string]interface{}{
134+
topologySpec := map[string]any{
135+
"topologySpreadConstraints": []map[string]any{
136136
{
137137
"maxSkew": 1,
138138
"topologyKey": corev1.LabelHostname,
139139
"whenUnsatisfiable": "ScheduleAnyway",
140-
"labelSelector": map[string]interface{}{
141-
"matchLabels": map[string]interface{}{
140+
"labelSelector": map[string]any{
141+
"matchLabels": map[string]any{
142142
"service": keystone_base.ServiceName,
143143
"component": label,
144144
},
@@ -165,26 +165,26 @@ func GetSampleTopologySpec(label string) (map[string]interface{}, []corev1.Topol
165165

166166
// GetExtraMounts - Utility function that simulates extraMounts pointing
167167
// to a secret
168-
func GetExtraMounts(kemName string, kemPath string) []map[string]interface{} {
169-
return []map[string]interface{}{
168+
func GetExtraMounts(kemName string, kemPath string) []map[string]any {
169+
return []map[string]any{
170170
{
171171
"name": kemName,
172172
"region": "az0",
173-
"extraVol": []map[string]interface{}{
173+
"extraVol": []map[string]any{
174174
{
175175
"extraVolType": kemName,
176176
"propagation": []string{
177177
"Keystone",
178178
},
179-
"volumes": []map[string]interface{}{
179+
"volumes": []map[string]any{
180180
{
181181
"name": kemName,
182-
"secret": map[string]interface{}{
182+
"secret": map[string]any{
183183
"secretName": kemName,
184184
},
185185
},
186186
},
187-
"mounts": []map[string]interface{}{
187+
"mounts": []map[string]any{
188188
{
189189
"name": kemName,
190190
"mountPath": kemPath,

tests/functional/keystoneapi_controller_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,8 @@ var _ = Describe("Keystone controller", func() {
801801
When("A KeystoneAPI is created with service override", func() {
802802
BeforeEach(func() {
803803
spec := GetDefaultKeystoneAPISpec()
804-
serviceOverride := map[string]interface{}{}
805-
serviceOverride["internal"] = map[string]interface{}{
804+
serviceOverride := map[string]any{}
805+
serviceOverride["internal"] = map[string]any{
806806
"metadata": map[string]map[string]string{
807807
"annotations": {
808808
"dnsmasq.network.openstack.org/hostname": "keystone-internal.openstack.svc",
@@ -815,12 +815,12 @@ var _ = Describe("Keystone controller", func() {
815815
"service": "keystone",
816816
},
817817
},
818-
"spec": map[string]interface{}{
818+
"spec": map[string]any{
819819
"type": "LoadBalancer",
820820
},
821821
}
822822

823-
spec["override"] = map[string]interface{}{
823+
spec["override"] = map[string]any{
824824
"service": serviceOverride,
825825
}
826826

@@ -889,12 +889,12 @@ var _ = Describe("Keystone controller", func() {
889889
When("A KeystoneAPI is created with service override endpointURL set", func() {
890890
BeforeEach(func() {
891891
spec := GetDefaultKeystoneAPISpec()
892-
serviceOverride := map[string]interface{}{}
893-
serviceOverride["public"] = map[string]interface{}{
892+
serviceOverride := map[string]any{}
893+
serviceOverride["public"] = map[string]any{
894894
"endpointURL": "http://keystone-openstack.apps-crc.testing",
895895
}
896896

897-
spec["override"] = map[string]interface{}{
897+
spec["override"] = map[string]any{
898898
"service": serviceOverride,
899899
}
900900

@@ -1173,12 +1173,12 @@ var _ = Describe("Keystone controller", func() {
11731173
When("A KeystoneAPI is created with TLS and service override endpointURL set", func() {
11741174
BeforeEach(func() {
11751175
spec := GetTLSKeystoneAPISpec()
1176-
serviceOverride := map[string]interface{}{}
1177-
serviceOverride["public"] = map[string]interface{}{
1176+
serviceOverride := map[string]any{}
1177+
serviceOverride["public"] = map[string]any{
11781178
"endpointURL": "https://keystone-openstack.apps-crc.testing",
11791179
}
11801180

1181-
spec["override"] = map[string]interface{}{
1181+
spec["override"] = map[string]any{
11821182
"service": serviceOverride,
11831183
}
11841184

@@ -1287,7 +1287,7 @@ var _ = Describe("Keystone controller", func() {
12871287
}
12881288

12891289
g.Expect(numberFernetKeys).Should(BeNumerically("==", 3))
1290-
for i := 0; i < 3; i++ {
1290+
for i := range 3 {
12911291
g.Expect(secret.Data["FernetKeys"+strconv.Itoa(i)]).NotTo(BeNil())
12921292
}
12931293
}, timeout, interval).Should(Succeed())
@@ -1340,7 +1340,7 @@ var _ = Describe("Keystone controller", func() {
13401340
}
13411341

13421342
g.Expect(numberFernetKeys).Should(BeNumerically("==", 100))
1343-
for i := 0; i < 100; i++ {
1343+
for i := range 100 {
13441344
g.Expect(secret.Data["FernetKeys"+strconv.Itoa(i)]).NotTo(BeNil())
13451345
}
13461346
}, timeout, interval).Should(Succeed())
@@ -1403,7 +1403,7 @@ var _ = Describe("Keystone controller", func() {
14031403
}
14041404

14051405
g.Expect(numberFernetKeys).Should(BeNumerically("==", 4))
1406-
for i := 0; i < 4; i++ {
1406+
for i := range 4 {
14071407
g.Expect(secret.Data["FernetKeys"+strconv.Itoa(i)]).NotTo(BeNil())
14081408
}
14091409
}, timeout, interval).Should(Succeed())
@@ -1466,7 +1466,7 @@ var _ = Describe("Keystone controller", func() {
14661466
}
14671467

14681468
g.Expect(numberFernetKeys).Should(BeNumerically("==", 6))
1469-
for i := 0; i < 6; i++ {
1469+
for i := range 6 {
14701470
g.Expect(secret.Data["FernetKeys"+strconv.Itoa(i)]).NotTo(BeNil())
14711471
}
14721472
}, timeout, interval).Should(Succeed())
@@ -1530,7 +1530,7 @@ var _ = Describe("Keystone controller", func() {
15301530
updatedSecret := th.GetSecret(types.NamespacedName{Namespace: keystoneAPIName.Namespace, Name: "keystone"})
15311531
g.Expect(updatedSecret).ToNot(BeNil())
15321532

1533-
for i := 0; i < 4; i++ {
1533+
for i := range 4 {
15341534

15351535
// old idx 0 > new 4
15361536
if i == 0 {
@@ -1575,7 +1575,7 @@ var _ = Describe("Keystone controller", func() {
15751575
infra.CreateTopology(t, topologySpec)
15761576
}
15771577
spec := GetDefaultKeystoneAPISpec()
1578-
spec["topologyRef"] = map[string]interface{}{
1578+
spec["topologyRef"] = map[string]any{
15791579
"name": topologyRef.Name,
15801580
}
15811581
DeferCleanup(
@@ -1698,7 +1698,7 @@ var _ = Describe("Keystone controller", func() {
16981698
When("A KeystoneAPI is created with nodeSelector", func() {
16991699
BeforeEach(func() {
17001700
spec := GetDefaultKeystoneAPISpec()
1701-
spec["nodeSelector"] = map[string]interface{}{
1701+
spec["nodeSelector"] = map[string]any{
17021702
"foo": "bar",
17031703
}
17041704
DeferCleanup(
@@ -1836,7 +1836,7 @@ OIDCRedirectURI "{{ .KeystoneEndpointPublic }}/v3/auth/OS-FEDERATION/websso/open
18361836
)
18371837

18381838
spec := GetDefaultKeystoneAPISpec()
1839-
spec["httpdCustomization"] = map[string]interface{}{
1839+
spec["httpdCustomization"] = map[string]any{
18401840
"customConfigSecret": customServiceConfigSecretName.Name,
18411841
}
18421842

tests/functional/keystoneapi_webhook_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ var _ = Describe("KeystoneAPI Webhook", func() {
109109

110110
It("rejects with wrong service override endpoint type", func() {
111111
spec := GetDefaultKeystoneAPISpec()
112-
spec["override"] = map[string]interface{}{
113-
"service": map[string]interface{}{
114-
"internal": map[string]interface{}{},
115-
"wrooong": map[string]interface{}{},
112+
spec["override"] = map[string]any{
113+
"service": map[string]any{
114+
"internal": map[string]any{},
115+
"wrooong": map[string]any{},
116116
},
117117
}
118118

119-
raw := map[string]interface{}{
119+
raw := map[string]any{
120120
"apiVersion": "keystone.openstack.org/v1beta1",
121121
"kind": "KeystoneAPI",
122-
"metadata": map[string]interface{}{
122+
"metadata": map[string]any{
123123
"name": keystoneAPIName.Name,
124124
"namespace": keystoneAPIName.Namespace,
125125
},
@@ -198,14 +198,14 @@ var _ = Describe("KeystoneAPI Webhook", func() {
198198
It("rejects a wrong TopologyRef on a different namespace", func() {
199199
keystoneSpec := GetDefaultKeystoneAPISpec()
200200
// Inject a topologyRef that points to a different namespace
201-
keystoneSpec["topologyRef"] = map[string]interface{}{
201+
keystoneSpec["topologyRef"] = map[string]any{
202202
"name": "foo",
203203
"namespace": "bar",
204204
}
205-
raw := map[string]interface{}{
205+
raw := map[string]any{
206206
"apiVersion": "keystone.openstack.org/v1beta1",
207207
"kind": "KeystoneAPI",
208-
"metadata": map[string]interface{}{
208+
"metadata": map[string]any{
209209
"name": "keystoneapi",
210210
"namespace": namespace,
211211
},

0 commit comments

Comments
 (0)