From b6c2c2f18953a0d36b03a4b946791485a40f1fa6 Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Tue, 13 Jan 2026 22:09:47 +0100 Subject: [PATCH] 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 --- internal/cnpgi/operator/lifecycle.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/cnpgi/operator/lifecycle.go b/internal/cnpgi/operator/lifecycle.go index 43c8ee8..8a0bbb5 100644 --- a/internal/cnpgi/operator/lifecycle.go +++ b/internal/cnpgi/operator/lifecycle.go @@ -353,30 +353,31 @@ func reconcilePodSpec( sidecarTemplate corev1.Container, config sidecarConfiguration, ) error { - envs := []corev1.EnvVar{ - { + envs := make([]corev1.EnvVar, 0, 5+len(config.env)) + envs = append(envs, + corev1.EnvVar{ Name: "NAMESPACE", Value: cluster.Namespace, }, - { + corev1.EnvVar{ Name: "CLUSTER_NAME", Value: cluster.Name, }, - { + corev1.EnvVar{ // TODO: should we really use this one? // should we mount an emptyDir volume just for that? Name: "SPOOL_DIRECTORY", Value: "/controller/wal-restore-spool", }, - { + corev1.EnvVar{ Name: "CUSTOM_CNPG_GROUP", Value: cluster.GetObjectKind().GroupVersionKind().Group, }, - { + corev1.EnvVar{ Name: "CUSTOM_CNPG_VERSION", Value: cluster.GetObjectKind().GroupVersionKind().Version, }, - } + ) envs = append(envs, config.env...)