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
6 changes: 4 additions & 2 deletions internal/controller/postgrescluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,12 @@ func (r *Reconciler) reconcileDataSource(ctx context.Context,
var configs []string
switch {
case dataSource != nil:
configs = []string{dataSource.ClusterName, dataSource.RepoName}
configs = make([]string, 0, 2+len(dataSource.Options))
configs = append(configs, dataSource.ClusterName, dataSource.RepoName)
configs = append(configs, dataSource.Options...)
Comment on lines +407 to 408
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
configs = append(configs, dataSource.ClusterName, dataSource.RepoName)
configs = append(configs, dataSource.Options...)
configs = append(configs, dataSource.ClusterName, dataSource.RepoName, dataSource.Options...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the first two elements being appended are strings and the last one is a string slice utilizing a variadic spread , you unfortunately can't do this in a single append call.

case cloudDataSource != nil:
configs = []string{cloudDataSource.Stanza, cloudDataSource.Repo.Name}
configs = make([]string, 0, 2+len(cloudDataSource.Options))
configs = append(configs, cloudDataSource.Stanza, cloudDataSource.Repo.Name)
configs = append(configs, cloudDataSource.Options...)
Comment on lines +411 to 412
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
configs = append(configs, cloudDataSource.Stanza, cloudDataSource.Repo.Name)
configs = append(configs, cloudDataSource.Options...)
configs = append(configs, cloudDataSource.Stanza, cloudDataSource.Repo.Name, cloudDataSource.Options...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

}
configHash, err := hashFunc(configs)
Expand Down
9 changes: 7 additions & 2 deletions internal/controller/postgrescluster/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,11 @@ func (r *Reconciler) scaleDownInstances(
}

// grab all pods for the cluster using the observed instances
pods := []corev1.Pod{}
var podCount int
for i := range observedInstances.forCluster {
podCount += len(observedInstances.forCluster[i].Pods)
}
pods := make([]corev1.Pod, 0, podCount)
for instanceIndex := range observedInstances.forCluster {
for podIndex := range observedInstances.forCluster[instanceIndex].Pods {
pods = append(pods, *observedInstances.forCluster[instanceIndex].Pods[podIndex])
Expand Down Expand Up @@ -1003,7 +1007,8 @@ func podsToKeep(instances []corev1.Pod, want map[string]int) []corev1.Pod {
return keep
}

keepPodList := []corev1.Pod{}
// preallocate with the total number of instance Pods
keepPodList := make([]corev1.Pod, 0, len(instances))
for name, num := range want {
list := []corev1.Pod{}
for _, instance := range instances {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/standalone_pgadmin/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func generateClusterConfig(
// which we can do by
// a) sorting the ServerGroup name used as a key; and
// b) sorting the clusters by name;
keys := []string{}
keys := make([]string, 0, len(clusters))
for key := range clusters {
keys = append(keys, key)
}
Expand Down
23 changes: 12 additions & 11 deletions internal/pgbouncer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,20 @@ func podConfigFiles(
// Start with an empty file at /etc/pgbouncer/pgbouncer.ini. This file can
// be overridden by the user, but it must exist because our configuration
// file refers to it.
projections := []corev1.VolumeProjection{
{
ConfigMap: &corev1.ConfigMapProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: configmap.Name,
},
Items: []corev1.KeyToPath{{
Key: emptyConfigMapKey,
Path: emptyFileProjectionPath,
}},
// Preallocate: 3 (empty ini file + configmap projection + secret projection)
// plus the number of specified files, len(config.Files)
projections := make([]corev1.VolumeProjection, 0, 3+len(config.Files))
projections = append(projections, corev1.VolumeProjection{
ConfigMap: &corev1.ConfigMapProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: configmap.Name,
},
Items: []corev1.KeyToPath{{
Key: emptyConfigMapKey,
Path: emptyFileProjectionPath,
}},
},
}
})

// Add any specified projections. These may override the files above.
// - https://docs.k8s.io/concepts/storage/volumes/#projected
Expand Down
6 changes: 5 additions & 1 deletion internal/postgres/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func (exec Executor) ExecInDatabasesFromQuery(
// database is passed via standard input while the database query is passed
// as the first argument. Remaining arguments are passed through to `psql`.
stdin := strings.NewReader(sql)
args := []string{databases}

// Using make to preallocate args (using 1 (databases) + len(variables)) triggered
// a CodeQL scanning error that a potentially large value might cause an overflow.
// To address this, don't preallocate args and have the linter ignore this line.
args := []string{databases} //nolint:prealloc
for k, v := range variables {
args = append(args, "--set="+k+"="+v)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/util/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func AddCloudLogVolumeToPod(podSpec *corev1.PodSpec, pvcName string) {
}

func addVolumesAndMounts(pod *corev1.PodSpec, volumes []v1beta1.AdditionalVolume, namer func(string, bool) corev1.VolumeMount) []string {
missingContainers := []string{}
var containerRefCount int
for _, v := range volumes {
containerRefCount += len(v.Containers)
}
missingContainers := make([]string, 0, containerRefCount)

for _, spec := range volumes {
// If it is an image volume, override readOnly to true
Expand Down
Loading