Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions helpers/utils/configmap_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// Defines a function type. Functions of the updateDataFunc type implements the
// logic to update the data of a configmap, defined by the 'data' argument.
type updateDataFunc func(obj client.Object, data map[string]interface{}) error
type updateDataFunc func(obj client.Object, data map[string]any) error

// A generic function to update an existing ConfigMap. It takes as arguments:
// * The context
Expand Down Expand Up @@ -106,8 +106,8 @@ func loadFileFromConfigMapData(
func LoadYAMLFileFromConfigMapData(
configMap corev1.ConfigMap,
filename string,
) (map[string]interface{}, error) {
yamlContent := map[string]interface{}{}
) (map[string]any, error) {
yamlContent := map[string]any{}

content, err := loadFileFromConfigMapData(configMap, filename)
if err != nil {
Expand All @@ -131,7 +131,7 @@ func writeFileToConfigMapData(
func writeYAMLFileToConfigMapData(
configMap *corev1.ConfigMap,
filename string,
yamlContent map[string]interface{},
yamlContent map[string]any,
) error {
bytesContent, err := yaml.Marshal(yamlContent)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions helpers/utils/tests_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ func BoolAddr(b bool) *bool {
return &boolVar
}

func Convert(i interface{}) interface{} {
func Convert(i any) any {
switch x := i.(type) {
case map[interface{}]interface{}:
m2 := map[string]interface{}{}
case map[any]any:
m2 := map[string]any{}
for k, v := range x {
m2[k.(string)] = Convert(v)
}
return m2
case []interface{}:
case []any:
for i, v := range x {
x[i] = Convert(v)
}
Expand Down
4 changes: 2 additions & 2 deletions helpers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package utils

import "gopkg.in/yaml.v3"

func ConvertStructToMap(in interface{}) (map[string]interface{}, error) {
func ConvertStructToMap(in any) (map[string]any, error) {
var intermediate []byte
var out map[string]interface{}
var out map[string]any
intermediate, err := yaml.Marshal(in)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *HeisenbridgeReconciler) configureHeisenbridgeConfigMap(
// bridge.
func (r *HeisenbridgeReconciler) updateHeisenbridgeWithURL(
obj client.Object,
heisenbridge map[string]interface{},
heisenbridge map[string]any,
) error {
h := obj.(*synapsev1alpha1.Heisenbridge)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ var _ = Describe("Integration tests for the Heisenbridge controller", Ordered, L
})

Context("Validating Heisenbridge CRD Schema", func() {
var obj map[string]interface{}
var obj map[string]any

BeforeEach(func() {
obj = map[string]interface{}{
obj = map[string]any{
"apiVersion": "synapse.opdev.io/v1alpha1",
"kind": "Heisenbridge",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": HeisenbridgeName,
"namespace": HeisenbridgeNamespace,
},
}
})

DescribeTable("Creating a misconfigured Heisenbridge instance",
func(heisenbridge map[string]interface{}) {
func(heisenbridge map[string]any) {
// Augment base heisenbridge obj with additional fields
for key, value := range heisenbridge {
obj[key] = value
Expand All @@ -165,38 +165,38 @@ var _ = Describe("Integration tests for the Heisenbridge controller", Ordered, L
u := unstructured.Unstructured{Object: obj}
Expect(k8sClient.Create(ctx, &u)).ShouldNot(Succeed())
},
Entry("when Heisenbridge spec is missing", map[string]interface{}{}),
Entry("when Heisenbridge spec is empty", map[string]interface{}{
"spec": map[string]interface{}{},
Entry("when Heisenbridge spec is missing", map[string]any{}),
Entry("when Heisenbridge spec is empty", map[string]any{
"spec": map[string]any{},
}),
Entry("when Heisenbridge spec is missing Synapse reference", map[string]interface{}{
"spec": map[string]interface{}{
"configMap": map[string]interface{}{
Entry("when Heisenbridge spec is missing Synapse reference", map[string]any{
"spec": map[string]any{
"configMap": map[string]any{
"name": "dummy",
},
},
}),
Entry("when Heisenbridge spec Synapse doesn't has a name", map[string]interface{}{
"spec": map[string]interface{}{
"synapse": map[string]interface{}{
Entry("when Heisenbridge spec Synapse doesn't has a name", map[string]any{
"spec": map[string]any{
"synapse": map[string]any{
"namespase": "dummy",
},
},
}),
Entry("when Heisenbridge spec ConfigMap doesn't specify a Name", map[string]interface{}{
"spec": map[string]interface{}{
"configMap": map[string]interface{}{
Entry("when Heisenbridge spec ConfigMap doesn't specify a Name", map[string]any{
"spec": map[string]any{
"configMap": map[string]any{
"namespace": "dummy",
},
"synapse": map[string]interface{}{
"synapse": map[string]any{
"name": "dummy",
},
},
}),
// This should not work but passes
PEntry("when Heisenbridge spec possesses an invalid field", map[string]interface{}{
"spec": map[string]interface{}{
"synapse": map[string]interface{}{
PEntry("when Heisenbridge spec possesses an invalid field", map[string]any{
"spec": map[string]any{
"synapse": map[string]any{
"name": "dummy",
},
"invalidSpecFiels": "random",
Expand All @@ -205,7 +205,7 @@ var _ = Describe("Integration tests for the Heisenbridge controller", Ordered, L
)

DescribeTable("Creating a correct Heisenbridge instance",
func(heisenbridge map[string]interface{}) {
func(heisenbridge map[string]any) {
// Augment base heisenbridge obj with additional fields
for key, value := range heisenbridge {
obj[key] = value
Expand All @@ -218,13 +218,13 @@ var _ = Describe("Integration tests for the Heisenbridge controller", Ordered, L
},
Entry(
"when the Configuration file is provided via a ConfigMap",
map[string]interface{}{
"spec": map[string]interface{}{
"configMap": map[string]interface{}{
map[string]any{
"spec": map[string]any{
"configMap": map[string]any{
"name": "dummy",
"namespace": "dummy",
},
"synapse": map[string]interface{}{
"synapse": map[string]any{
"name": "dummy",
"namespace": "dummy",
},
Expand All @@ -233,12 +233,12 @@ var _ = Describe("Integration tests for the Heisenbridge controller", Ordered, L
),
Entry(
"when optional Synapse Namespace and ConfigMap Namespace are missing",
map[string]interface{}{
"spec": map[string]interface{}{
"configMap": map[string]interface{}{
map[string]any{
"spec": map[string]any{
"configMap": map[string]any{
"name": "dummy",
},
"synapse": map[string]interface{}{
"synapse": map[string]any{
"name": "dummy",
},
},
Expand Down Expand Up @@ -492,7 +492,7 @@ var _ = Describe("Integration tests for the Heisenbridge controller", Ordered, L
configMapdata, ok := createdConfigMap.Data["heisenbridge.yaml"]
g.Expect(ok).Should(BeTrue())

heisenbridge := make(map[string]interface{})
heisenbridge := make(map[string]any)
g.Expect(yaml.Unmarshal([]byte(configMapdata), heisenbridge)).Should(Succeed())

_, ok = heisenbridge["url"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *MautrixSignalReconciler) configureMautrixSignalConfigMap(
// and knows the correct path to the signald socket.
func (r *MautrixSignalReconciler) updateMautrixSignalData(
obj client.Object,
config map[string]interface{},
config map[string]any,
) error {
ms := obj.(*synapsev1alpha1.MautrixSignal)

Expand All @@ -150,7 +150,7 @@ func (r *MautrixSignalReconciler) updateMautrixSignalData(
synapseServerName := ms.Status.Synapse.ServerName

// Update the homeserver section so that the bridge can reach Synapse
configHomeserver, ok := config["homeserver"].(map[string]interface{})
configHomeserver, ok := config["homeserver"].(map[string]any)
if !ok {
err := errors.New("cannot parse mautrix-signal config.yaml: error parsing 'homeserver' section")
return err
Expand All @@ -160,7 +160,7 @@ func (r *MautrixSignalReconciler) updateMautrixSignalData(
config["homeserver"] = configHomeserver

// Update the appservice section so that Synapse can reach the bridge
configAppservice, ok := config["appservice"].(map[string]interface{})
configAppservice, ok := config["appservice"].(map[string]any)
if !ok {
err := errors.New("cannot parse mautrix-signal config.yaml: error parsing 'appservice' section")
return err
Expand All @@ -169,7 +169,7 @@ func (r *MautrixSignalReconciler) updateMautrixSignalData(
config["appservice"] = configAppservice

// Update the path to the signal socket path
configSignal, ok := config["signal"].(map[string]interface{})
configSignal, ok := config["signal"].(map[string]any)
if !ok {
err := errors.New("cannot parse mautrix-signal config.yaml: error parsing 'signal' section")
return err
Expand All @@ -178,7 +178,7 @@ func (r *MautrixSignalReconciler) updateMautrixSignalData(
config["signal"] = configSignal

// Update persmissions to use the correct domain name
configBridge, ok := config["bridge"].(map[string]interface{})
configBridge, ok := config["bridge"].(map[string]any)
if !ok {
err := errors.New("cannot parse mautrix-signal config.yaml: error parsing 'bridge' section")
return err
Expand All @@ -191,17 +191,17 @@ func (r *MautrixSignalReconciler) updateMautrixSignalData(
config["bridge"] = configBridge

// Update the path to the log file
configLogging, ok := config["logging"].(map[string]interface{})
configLogging, ok := config["logging"].(map[string]any)
if !ok {
err := errors.New("cannot parse mautrix-signal config.yaml: error parsing 'logging' section")
return err
}
configLoggingHandlers, ok := configLogging["handlers"].(map[string]interface{})
configLoggingHandlers, ok := configLogging["handlers"].(map[string]any)
if !ok {
err := errors.New("cannot parse mautrix-signal config.yaml: error parsing 'logging/handlers' section")
return err
}
configLoggingHandlersFile, ok := configLoggingHandlers["file"].(map[string]interface{})
configLoggingHandlersFile, ok := configLoggingHandlers["file"].(map[string]any)
if !ok {
err := errors.New("cannot parse mautrix-signal config.yaml: error parsing 'logging/handlers/file' section")
return err
Expand Down
Loading