Skip to content

Commit 5d7656c

Browse files
Merge pull request openstack-k8s-operators#288 from fmount/modernize
Modernize Go code with latest style conventions
2 parents 22b780f + 758c4e1 commit 5d7656c

File tree

7 files changed

+61
-68
lines changed

7 files changed

+61
-68
lines changed

controllers/barbican_common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
type conditionUpdater interface {
3838
Set(c *condition.Condition)
39-
MarkTrue(t condition.Type, messageFormat string, messageArgs ...interface{})
39+
MarkTrue(t condition.Type, messageFormat string, messageArgs ...any)
4040
}
4141

4242
type topologyHandler interface {
@@ -89,7 +89,7 @@ func GenerateConfigsGeneric(
8989
ctx context.Context, h *helper.Helper,
9090
instance client.Object,
9191
envVars *map[string]env.Setter,
92-
templateParameters map[string]interface{},
92+
templateParameters map[string]any,
9393
customData map[string]string,
9494
cmLabels map[string]string,
9595
scripts bool,
@@ -123,7 +123,7 @@ func GenerateConfigsGeneric(
123123
func GenerateSecretStoreTemplateMap(
124124
enabledSecretStores []barbicanv1beta1.SecretStore,
125125
globalDefaultSecretStore barbicanv1beta1.SecretStore,
126-
) (map[string]interface{}, error) {
126+
) (map[string]any, error) {
127127
// Log := r.GetLogger(ctx)
128128
stores := []string{}
129129
if len(enabledSecretStores) == 0 {
@@ -138,7 +138,7 @@ func GenerateSecretStoreTemplateMap(
138138
globalDefaultSecretStore = "simple_crypto"
139139
}
140140

141-
tempMap := map[string]interface{}{
141+
tempMap := map[string]any{
142142
"EnabledSecretStores": strings.Join(stores, ","),
143143
"GlobalDefaultSecretStore": globalDefaultSecretStore,
144144
"SimpleCryptoEnabled": slices.Contains(stores, "simple_crypto"),

controllers/barbican_controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
maps0 "maps"
2223
"slices"
2324
"time"
2425

@@ -687,9 +688,7 @@ func (r *BarbicanReconciler) generateServiceConfig(
687688
"my.cnf": db.GetDatabaseClientConfig(tlsCfg), //(mschuppert) for now just get the default my.cnf
688689
}
689690

690-
for key, data := range instance.Spec.DefaultConfigOverwrite {
691-
customData[key] = data
692-
}
691+
maps0.Copy(customData, instance.Spec.DefaultConfigOverwrite)
693692
keystoneAPI, err := keystonev1.GetKeystoneAPI(ctx, h, instance.Namespace, map[string]string{})
694693
// KeystoneAPI not available we should not aggregate the error and continue
695694
if err != nil {
@@ -703,7 +702,7 @@ func (r *BarbicanReconciler) generateServiceConfig(
703702
databaseAccount := db.GetAccount()
704703
databaseSecret := db.GetSecret()
705704

706-
templateParameters := map[string]interface{}{
705+
templateParameters := map[string]any{
707706
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
708707
databaseAccount.Spec.UserName,
709708
string(databaseSecret.Data[mariadbv1.DatabasePasswordSelector]),
@@ -759,9 +758,9 @@ func (r *BarbicanReconciler) generateServiceConfig(
759758
}
760759

761760
// create httpd vhost template parameters
762-
httpdVhostConfig := map[string]interface{}{}
761+
httpdVhostConfig := map[string]any{}
763762
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
764-
endptConfig := map[string]interface{}{}
763+
endptConfig := map[string]any{}
765764
endptConfig["ServerName"] = fmt.Sprintf("%s-%s.%s.svc", barbican.ServiceName, endpt.String(), instance.Namespace)
766765
endptConfig["TLS"] = false // default TLS to false, and set it bellow to true if enabled
767766
if instance.Spec.BarbicanAPI.TLS.API.Enabled(endpt) {

controllers/barbicanapi_controller.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"maps"
2223
"slices"
2324
"time"
2425

@@ -312,15 +313,10 @@ func (r *BarbicanAPIReconciler) generateServiceConfigs(
312313
if err != nil {
313314
return err
314315
}
315-
for key, data := range ownerInstance.Spec.DefaultConfigOverwrite {
316-
customData[key] = data
317-
}
316+
maps.Copy(customData, ownerInstance.Spec.DefaultConfigOverwrite)
318317
}
319318

320-
for key, data := range instance.Spec.DefaultConfigOverwrite {
321-
// can we merge here?
322-
customData[key] = data
323-
}
319+
maps.Copy(customData, instance.Spec.DefaultConfigOverwrite)
324320

325321
customSecrets := ""
326322
for _, secretName := range instance.Spec.CustomServiceConfigSecrets {
@@ -336,7 +332,7 @@ func (r *BarbicanAPIReconciler) generateServiceConfigs(
336332

337333
instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage)
338334

339-
templateParameters := map[string]interface{}{
335+
templateParameters := map[string]any{
340336
"LogFile": fmt.Sprintf("%s%s.log", barbican.BarbicanLogPath, instance.Name),
341337
}
342338

controllers/barbicankeystonelistener_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"maps"
2223
"slices"
2324
"time"
2425

@@ -289,9 +290,7 @@ func (r *BarbicanKeystoneListenerReconciler) generateServiceConfigs(
289290
// TODO(alee) Get custom config overwrites from the parent barbican
290291
}
291292

292-
for key, data := range instance.Spec.DefaultConfigOverwrite {
293-
customData[key] = data
294-
}
293+
maps.Copy(customData, instance.Spec.DefaultConfigOverwrite)
295294

296295
customSecrets := ""
297296
for _, secretName := range instance.Spec.CustomServiceConfigSecrets {
@@ -307,7 +306,7 @@ func (r *BarbicanKeystoneListenerReconciler) generateServiceConfigs(
307306

308307
instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage)
309308

310-
templateParameters := map[string]interface{}{
309+
templateParameters := map[string]any{
311310
"LogFile": fmt.Sprintf("%s%s.log", barbican.BarbicanLogPath, instance.Name),
312311
}
313312

controllers/barbicanworker_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"maps"
2223
"slices"
2324
"time"
2425

@@ -282,9 +283,7 @@ func (r *BarbicanWorkerReconciler) generateServiceConfigs(
282283
// TODO(alee) Get custom config overwrites from the parent barbican
283284
}
284285

285-
for key, data := range instance.Spec.DefaultConfigOverwrite {
286-
customData[key] = data
287-
}
286+
maps.Copy(customData, instance.Spec.DefaultConfigOverwrite)
288287

289288
customSecrets := ""
290289
for _, secretName := range instance.Spec.CustomServiceConfigSecrets {
@@ -300,7 +299,7 @@ func (r *BarbicanWorkerReconciler) generateServiceConfigs(
300299

301300
instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage)
302301

303-
templateParameters := map[string]interface{}{
302+
templateParameters := map[string]any{
304303
"LogFile": fmt.Sprintf("%s%s.log", barbican.BarbicanLogPath, instance.Name),
305304
}
306305

tests/functional/barbican_controller_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ var _ = Describe("Barbican controller", func() {
427427
spec := GetDefaultBarbicanSpec()
428428
// Update the spec and add a top-level topologyRef that points to
429429
// gloabal-topology
430-
spec["topologyRef"] = map[string]interface{}{
430+
spec["topologyRef"] = map[string]any{
431431
"name": topologyRef.Name,
432432
}
433433
DeferCleanup(k8sClient.Delete, ctx, CreateBarbicanMessageBusSecret(barbicanTest.Instance.Namespace, "rabbitmq-secret"))
@@ -723,7 +723,7 @@ var _ = Describe("Barbican controller", func() {
723723
When("A Barbican with nodeSelector is created", func() {
724724
BeforeEach(func() {
725725
spec := GetDefaultBarbicanSpec()
726-
spec["nodeSelector"] = map[string]interface{}{
726+
spec["nodeSelector"] = map[string]any{
727727
"foo": "bar",
728728
}
729729
spec["barbicanAPI"] = GetDefaultBarbicanAPISpec()
@@ -1685,18 +1685,18 @@ var _ = Describe("Barbican Webhook", func() {
16851685
It("rejects with wrong BarbicanAPI service override endpoint type", func() {
16861686
spec := GetDefaultBarbicanSpec()
16871687
apiSpec := GetDefaultBarbicanAPISpec()
1688-
apiSpec["override"] = map[string]interface{}{
1689-
"service": map[string]interface{}{
1690-
"internal": map[string]interface{}{},
1691-
"wrooong": map[string]interface{}{},
1688+
apiSpec["override"] = map[string]any{
1689+
"service": map[string]any{
1690+
"internal": map[string]any{},
1691+
"wrooong": map[string]any{},
16921692
},
16931693
}
16941694
spec["barbicanAPI"] = apiSpec
16951695

1696-
raw := map[string]interface{}{
1696+
raw := map[string]any{
16971697
"apiVersion": "barbican.openstack.org/v1beta1",
16981698
"kind": "Barbican",
1699-
"metadata": map[string]interface{}{
1699+
"metadata": map[string]any{
17001700
"name": barbicanTest.Instance.Name,
17011701
"namespace": barbicanTest.Instance.Namespace,
17021702
},
@@ -1723,24 +1723,24 @@ var _ = Describe("Barbican Webhook", func() {
17231723

17241724
// API, Worker and KeystoneListener
17251725
if component != "top-level" {
1726-
spec[component] = map[string]interface{}{
1727-
"topologyRef": map[string]interface{}{
1726+
spec[component] = map[string]any{
1727+
"topologyRef": map[string]any{
17281728
"name": "bar",
17291729
"namespace": "foo",
17301730
},
17311731
}
17321732
// top-level topologyRef
17331733
} else {
1734-
spec["topologyRef"] = map[string]interface{}{
1734+
spec["topologyRef"] = map[string]any{
17351735
"name": "bar",
17361736
"namespace": "foo",
17371737
}
17381738
}
17391739
// Build the barbican CR
1740-
raw := map[string]interface{}{
1740+
raw := map[string]any{
17411741
"apiVersion": "barbican.openstack.org/v1beta1",
17421742
"kind": "Barbican",
1743-
"metadata": map[string]interface{}{
1743+
"metadata": map[string]any{
17441744
"name": barbicanTest.Instance.Name,
17451745
"namespace": barbicanTest.Instance.Namespace,
17461746
},

tests/functional/base_test.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ func CreateCustomConfigSecret(namespace string, name string, contents map[string
5252
)
5353
}
5454

55-
func GetDefaultBarbicanSpec() map[string]interface{} {
56-
return map[string]interface{}{
55+
func GetDefaultBarbicanSpec() map[string]any {
56+
return map[string]any{
5757
"databaseInstance": "openstack",
5858
"secret": SecretName,
5959
"simpleCryptoBackendSecret": SecretName,
6060
"customServiceConfig": barbicanTest.BaseCustomServiceConfig,
6161
}
6262
}
6363

64-
func CreateBarbican(name types.NamespacedName, spec map[string]interface{}) client.Object {
65-
raw := map[string]interface{}{
64+
func CreateBarbican(name types.NamespacedName, spec map[string]any) client.Object {
65+
raw := map[string]any{
6666
"apiVersion": "barbican.openstack.org/v1beta1",
6767
"kind": "Barbican",
68-
"metadata": map[string]interface{}{
68+
"metadata": map[string]any{
6969
"name": name.Name,
7070
"namespace": name.Namespace,
7171
},
@@ -86,7 +86,7 @@ func CreateBarbicanMessageBusSecret(namespace string, name string) *corev1.Secre
8686
s := th.CreateSecret(
8787
types.NamespacedName{Namespace: namespace, Name: name},
8888
map[string][]byte{
89-
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", name)),
89+
"transport_url": fmt.Appendf(nil, "rabbit://%s/fake", name),
9090
},
9191
)
9292
logger.Info("Secret created", "name", name)
@@ -181,8 +181,8 @@ func BarbicanWorkerConditionGetter(name types.NamespacedName) condition.Conditio
181181
}
182182

183183
// ========== TLS Stuff ==============
184-
func GetTLSBarbicanSpec() map[string]interface{} {
185-
return map[string]interface{}{
184+
func GetTLSBarbicanSpec() map[string]any {
185+
return map[string]any{
186186
"databaseInstance": "openstack",
187187
"secret": SecretName,
188188
"simpleCryptoBackendSecret": SecretName,
@@ -192,15 +192,15 @@ func GetTLSBarbicanSpec() map[string]interface{} {
192192
}
193193
}
194194

195-
func GetTLSBarbicanAPISpec() map[string]interface{} {
195+
func GetTLSBarbicanAPISpec() map[string]any {
196196
spec := GetDefaultBarbicanAPISpec()
197-
maps.Copy(spec, map[string]interface{}{
198-
"tls": map[string]interface{}{
199-
"api": map[string]interface{}{
200-
"internal": map[string]interface{}{
197+
maps.Copy(spec, map[string]any{
198+
"tls": map[string]any{
199+
"api": map[string]any{
200+
"internal": map[string]any{
201201
"secretName": InternalCertSecretName,
202202
},
203-
"public": map[string]interface{}{
203+
"public": map[string]any{
204204
"secretName": PublicCertSecretName,
205205
},
206206
},
@@ -231,13 +231,13 @@ key_wrap_generate_iv = true
231231
always_set_cka_sensitive = true
232232
os_locking_ok = false`
233233

234-
func GetPKCS11BarbicanSpec() map[string]interface{} {
234+
func GetPKCS11BarbicanSpec() map[string]any {
235235
spec := GetDefaultBarbicanSpec()
236-
maps.Copy(spec, map[string]interface{}{
236+
maps.Copy(spec, map[string]any{
237237
"customServiceConfig": PKCS11CustomData,
238238
"enabledSecretStores": []string{"pkcs11"},
239239
"globalDefaultSecretStore": "pkcs11",
240-
"pkcs11": map[string]interface{}{
240+
"pkcs11": map[string]any{
241241
"clientDataPath": PKCS11ClientDataPath,
242242
"loginSecret": PKCS11LoginSecret,
243243
"clientDataSecret": PKCS11ClientDataSecret,
@@ -246,7 +246,7 @@ func GetPKCS11BarbicanSpec() map[string]interface{} {
246246
return spec
247247
}
248248

249-
func GetPKCS11BarbicanAPISpec() map[string]interface{} {
249+
func GetPKCS11BarbicanAPISpec() map[string]any {
250250
spec := GetPKCS11BarbicanSpec()
251251
maps.Copy(spec, GetDefaultBarbicanAPISpec())
252252
return spec
@@ -276,8 +276,8 @@ func CreatePKCS11ClientDataSecret(namespace string, name string) *corev1.Secret
276276

277277
// ========== End of PKCS11 Stuff ============
278278

279-
func GetDefaultBarbicanAPISpec() map[string]interface{} {
280-
return map[string]interface{}{
279+
func GetDefaultBarbicanAPISpec() map[string]any {
280+
return map[string]any{
281281
"secret": SecretName,
282282
"simpleCryptoBackendSecret": SecretName,
283283
"replicas": 1,
@@ -291,13 +291,13 @@ func GetDefaultBarbicanAPISpec() map[string]interface{} {
291291
}
292292
}
293293

294-
func CreateBarbicanAPI(name types.NamespacedName, spec map[string]interface{}) client.Object {
294+
func CreateBarbicanAPI(name types.NamespacedName, spec map[string]any) client.Object {
295295
// we get the parent CR and set ownership to the barbicanAPI CR
296-
raw := map[string]interface{}{
296+
raw := map[string]any{
297297
"apiVersion": "barbican.openstack.org/v1beta1",
298298
"kind": "BarbicanAPI",
299-
"metadata": map[string]interface{}{
300-
"annotations": map[string]interface{}{
299+
"metadata": map[string]any{
300+
"annotations": map[string]any{
301301
"keystoneEndpoint": "true",
302302
},
303303
"name": name.Name,
@@ -346,16 +346,16 @@ func GetBarbicanWorkerSpec(name types.NamespacedName) barbicanv1.BarbicanWorkerT
346346
// multi AZ, which is not applicable in this context
347347
func GetSampleTopologySpec(
348348
label string,
349-
) (map[string]interface{}, []corev1.TopologySpreadConstraint) {
349+
) (map[string]any, []corev1.TopologySpreadConstraint) {
350350
// Build the topology Spec
351-
topologySpec := map[string]interface{}{
352-
"topologySpreadConstraints": []map[string]interface{}{
351+
topologySpec := map[string]any{
352+
"topologySpreadConstraints": []map[string]any{
353353
{
354354
"maxSkew": 1,
355355
"topologyKey": corev1.LabelHostname,
356356
"whenUnsatisfiable": "ScheduleAnyway",
357-
"labelSelector": map[string]interface{}{
358-
"matchLabels": map[string]interface{}{
357+
"labelSelector": map[string]any{
358+
"matchLabels": map[string]any{
359359
"component": label,
360360
},
361361
},

0 commit comments

Comments
 (0)