fix(lint): preallocate envs slice to avoid reallocations

The golangci-lint v2.8.0 upgrade introduced a prealloc linter finding
suggesting to preallocate the envs slice with capacity 5 + len(config.env)
to avoid reallocations when appending config.env elements.

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
This commit is contained in:
Marco Nenciarini 2026-01-13 22:09:47 +01:00
parent ad03222d87
commit b6c2c2f189
No known key found for this signature in database
GPG Key ID: 589F03F01BA55038

View File

@ -353,30 +353,31 @@ func reconcilePodSpec(
sidecarTemplate corev1.Container, sidecarTemplate corev1.Container,
config sidecarConfiguration, config sidecarConfiguration,
) error { ) error {
envs := []corev1.EnvVar{ envs := make([]corev1.EnvVar, 0, 5+len(config.env))
{ envs = append(envs,
corev1.EnvVar{
Name: "NAMESPACE", Name: "NAMESPACE",
Value: cluster.Namespace, Value: cluster.Namespace,
}, },
{ corev1.EnvVar{
Name: "CLUSTER_NAME", Name: "CLUSTER_NAME",
Value: cluster.Name, Value: cluster.Name,
}, },
{ corev1.EnvVar{
// TODO: should we really use this one? // TODO: should we really use this one?
// should we mount an emptyDir volume just for that? // should we mount an emptyDir volume just for that?
Name: "SPOOL_DIRECTORY", Name: "SPOOL_DIRECTORY",
Value: "/controller/wal-restore-spool", Value: "/controller/wal-restore-spool",
}, },
{ corev1.EnvVar{
Name: "CUSTOM_CNPG_GROUP", Name: "CUSTOM_CNPG_GROUP",
Value: cluster.GetObjectKind().GroupVersionKind().Group, Value: cluster.GetObjectKind().GroupVersionKind().Group,
}, },
{ corev1.EnvVar{
Name: "CUSTOM_CNPG_VERSION", Name: "CUSTOM_CNPG_VERSION",
Value: cluster.GetObjectKind().GroupVersionKind().Version, Value: cluster.GetObjectKind().GroupVersionKind().Version,
}, },
} )
envs = append(envs, config.env...) envs = append(envs, config.env...)