Skip to content

Commit b6c2c2f

Browse files
committed
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>
1 parent ad03222 commit b6c2c2f

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

internal/cnpgi/operator/lifecycle.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,30 +353,31 @@ func reconcilePodSpec(
353353
sidecarTemplate corev1.Container,
354354
config sidecarConfiguration,
355355
) error {
356-
envs := []corev1.EnvVar{
357-
{
356+
envs := make([]corev1.EnvVar, 0, 5+len(config.env))
357+
envs = append(envs,
358+
corev1.EnvVar{
358359
Name: "NAMESPACE",
359360
Value: cluster.Namespace,
360361
},
361-
{
362+
corev1.EnvVar{
362363
Name: "CLUSTER_NAME",
363364
Value: cluster.Name,
364365
},
365-
{
366+
corev1.EnvVar{
366367
// TODO: should we really use this one?
367368
// should we mount an emptyDir volume just for that?
368369
Name: "SPOOL_DIRECTORY",
369370
Value: "/controller/wal-restore-spool",
370371
},
371-
{
372+
corev1.EnvVar{
372373
Name: "CUSTOM_CNPG_GROUP",
373374
Value: cluster.GetObjectKind().GroupVersionKind().Group,
374375
},
375-
{
376+
corev1.EnvVar{
376377
Name: "CUSTOM_CNPG_VERSION",
377378
Value: cluster.GetObjectKind().GroupVersionKind().Version,
378379
},
379-
}
380+
)
380381

381382
envs = append(envs, config.env...)
382383

0 commit comments

Comments
 (0)