Skip to content

Apply fixes suggested by modernize #4218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
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
5 changes: 2 additions & 3 deletions internal/collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
_ "embed"
"fmt"
"maps"
"math"
"strings"
"time"
Expand Down Expand Up @@ -168,9 +169,7 @@ func NewConfig(spec *v1beta1.InstrumentationSpec) *Config {

// If there are exporters defined in the spec, add them to the config.
if spec != nil && spec.Config != nil && spec.Config.Exporters != nil {
for k, v := range spec.Config.Exporters {
config.Exporters[k] = v
}
maps.Copy(config.Exporters, spec.Config.Exporters)
}

return config
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/postgrescluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ spec:
MatchFields(IgnoreExtras, Fields{
"Manager": Equal(string(test.Reconciler.Owner)),
"FieldsV1": PointTo(MatchAllFields(Fields{
"Raw": WithTransform(func(in []byte) (out map[string]interface{}) {
"Raw": WithTransform(func(in []byte) (out map[string]any) {
Expect(yaml.Unmarshal(in, &out)).To(Succeed())
return out
}, MatchAllKeys(Keys{
Expand All @@ -367,7 +367,7 @@ spec:
MatchFields(IgnoreExtras, Fields{
"Manager": Equal(string(test.Reconciler.Owner)),
"FieldsV1": PointTo(MatchAllFields(Fields{
"Raw": WithTransform(func(in []byte) (out map[string]interface{}) {
"Raw": WithTransform(func(in []byte) (out map[string]any) {
Expect(yaml.Unmarshal(in, &out)).To(Succeed())
return out
}, MatchAllKeys(Keys{
Expand All @@ -380,7 +380,7 @@ spec:
MatchFields(IgnoreExtras, Fields{
"Manager": Equal(string(test.Reconciler.Owner)),
"FieldsV1": PointTo(MatchAllFields(Fields{
"Raw": WithTransform(func(in []byte) (out map[string]interface{}) {
"Raw": WithTransform(func(in []byte) (out map[string]any) {
Expect(yaml.Unmarshal(in, &out)).To(Succeed())
return out
}, MatchAllKeys(Keys{
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/postgrescluster/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"io"
"maps"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -321,9 +322,7 @@ func (r *Reconciler) observeInstances(
if autogrow {
for _, statusIS := range cluster.Status.InstanceSets {
if statusIS.DesiredPGDataVolume != nil {
for k, v := range statusIS.DesiredPGDataVolume {
previousDesiredRequests[k] = v
}
maps.Copy(previousDesiredRequests, statusIS.DesiredPGDataVolume)
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions internal/controller/standalone_pgadmin/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"slices"
"sort"
"strconv"
Expand Down Expand Up @@ -124,9 +125,7 @@ func generateConfig(pgadmin *v1beta1.PGAdmin,
}

// Copy any specified settings over the defaults.
for k, v := range pgadmin.Spec.Config.Settings {
settings[k] = v
}
maps.Copy(settings, pgadmin.Spec.Config.Settings)

// Write mandatory settings over any specified ones.
// SERVER_MODE must always be enabled when running on a webserver.
Expand Down Expand Up @@ -246,9 +245,7 @@ func generateGunicornConfig(pgadmin *v1beta1.PGAdmin,
}

// Copy any specified settings over the defaults.
for k, v := range pgadmin.Spec.Config.Gunicorn {
settings[k] = v
}
maps.Copy(settings, pgadmin.Spec.Config.Gunicorn)

// Write mandatory settings over any specified ones.
// - https://docs.gunicorn.org/en/latest/settings.html#workers
Expand Down
6 changes: 3 additions & 3 deletions internal/kubeapi/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"k8s.io/apimachinery/pkg/types"
)

func assertJSON(t testing.TB, expected interface{}, actual []byte) {
func assertJSON(t testing.TB, expected any, actual []byte) {
t.Helper()

var e, a interface{}
var e, a any
var err error

if b, ok := expected.([]byte); ok {
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestMerge7386Equivalence(t *testing.T) {

// one call using other types
NewMergePatch().
Add("metadata")(map[string]interface{}{
Add("metadata")(map[string]any{
"labels": labels.Set{"lk": "lv"},
"annotations": map[string]string{"ak1": "av1", "ak2": "av2"},
}),
Expand Down
8 changes: 4 additions & 4 deletions internal/logging/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Logrus(out io.Writer, version string, debug, verbosity int) logr.LogSink {
return &sink{
verbosity: verbosity,

fnError: func(err error, message string, kv ...interface{}) {
fnError: func(err error, message string, kv ...any) {
entry := root.WithField("version", version)
entry = logrusFields(entry, kv...)

Expand All @@ -57,7 +57,7 @@ func Logrus(out io.Writer, version string, debug, verbosity int) logr.LogSink {
entry.Log(logrus.ErrorLevel, message)
},

fnInfo: func(level int, message string, kv ...interface{}) {
fnInfo: func(level int, message string, kv ...any) {
entry := root.WithField("version", version)
entry = logrusFields(entry, kv...)

Expand All @@ -72,15 +72,15 @@ func Logrus(out io.Writer, version string, debug, verbosity int) logr.LogSink {

// logrusFields structures and adds the key/value interface to the logrus.Entry;
// for instance, if a key is not a string, this formats the key as a string.
func logrusFields(entry *logrus.Entry, kv ...interface{}) *logrus.Entry {
func logrusFields(entry *logrus.Entry, kv ...any) *logrus.Entry {
if len(kv) == 0 {
return entry
}
if len(kv)%2 == 1 {
kv = append(kv, nil)
}

m := make(map[string]interface{}, len(kv)/2)
m := make(map[string]any, len(kv)/2)

for i := 0; i < len(kv); i += 2 {
key, ok := kv[i].(string)
Expand Down
5 changes: 2 additions & 3 deletions internal/patroni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package patroni

import (
"fmt"
"maps"
"path"
"strings"

Expand Down Expand Up @@ -237,9 +238,7 @@ func DynamicConfiguration(

// Copy the "postgresql" section over the above defaults.
if section, ok := root["postgresql"].(map[string]any); ok {
for k, v := range section {
postgresql[k] = v
}
maps.Copy(postgresql, section)
}
if m := parameters.AsMap(); m != nil {
postgresql["parameters"] = m
Expand Down
4 changes: 2 additions & 2 deletions internal/pgadmin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ if os.path.isfile('` + ldapPasswordAbsolutePath + `'):
}

// systemSettings returns pgAdmin settings as a value that can be marshaled to JSON.
func systemSettings(spec *v1beta1.PGAdminPodSpec) map[string]interface{} {
func systemSettings(spec *v1beta1.PGAdminPodSpec) map[string]any {
settings := spec.Config.Settings.DeepCopy()
if settings == nil {
settings = make(map[string]interface{})
settings = make(map[string]any)
}

// SERVER_MODE must always be enabled when running on a webserver.
Expand Down
4 changes: 2 additions & 2 deletions internal/pgadmin/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func TestSystemSettings(t *testing.T) {
SERVER_MODE: true
`))

spec.Config.Settings = map[string]interface{}{
"ALLOWED_HOSTS": []interface{}{"225.0.0.0/8", "226.0.0.0/7", "228.0.0.0/6"},
spec.Config.Settings = map[string]any{
"ALLOWED_HOSTS": []any{"225.0.0.0/8", "226.0.0.0/7", "228.0.0.0/6"},
}
assert.Assert(t, cmp.MarshalMatches(systemSettings(spec), `
ALLOWED_HOSTS:
Expand Down
2 changes: 1 addition & 1 deletion internal/pgadmin/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pgadmin-settings.json: |
t.Run("Customizations", func(t *testing.T) {
cluster.Spec.UserInterface = new(v1beta1.UserInterfaceSpec)
cluster.Spec.UserInterface.PGAdmin = new(v1beta1.PGAdminPodSpec)
cluster.Spec.UserInterface.PGAdmin.Config.Settings = map[string]interface{}{
cluster.Spec.UserInterface.PGAdmin.Config.Settings = map[string]any{
"some": "thing",
"UPPER_CASE": false,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pgadmin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ with create_app().app_context():`,
spec := users[i]

if err == nil {
err = encoder.Encode(map[string]interface{}{
err = encoder.Encode(map[string]any{
"username": spec.Name,
"password": passwords[spec.Name],
})
Expand Down
5 changes: 2 additions & 3 deletions internal/pgbouncer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package pgbouncer
import (
"context"
"fmt"
"maps"
"sort"
"strings"

Expand Down Expand Up @@ -138,9 +139,7 @@ func clusterINI(ctx context.Context, cluster *v1beta1.PostgresCluster) string {
}

// Override the above with any specified settings.
for k, v := range cluster.Spec.Proxy.PGBouncer.Config.Global {
global[k] = v
}
maps.Copy(global, cluster.Spec.Proxy.PGBouncer.Config.Global)

// Prevent the user from bypassing the main configuration file.
global["conffile"] = iniFileAbsolutePath
Expand Down
Loading