Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7b7739a

Browse files
committed
updates from PR feedback
1 parent 3d00636 commit 7b7739a

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

‎internal/controller/postgrescluster/pgbackrest.go‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,8 +2775,7 @@ func (r *Reconciler) reconcileRepos(ctx context.Context,
27752775
repoVols := []*corev1.PersistentVolumeClaim{}
27762776
var replicaCreateRepo v1beta1.PGBackRestRepo
27772777

2778-
autogrow := feature.Enabled(ctx, feature.AutoGrowVolumes)
2779-
if autogrow {
2778+
if feature.Enabled(ctx, feature.AutoGrowVolumes) {
27802779
// get the autogrow annotations so that the correct volume size values can be
27812780
// used and the cluster status can be updated
27822781
errors = append(errors, r.getRepoHostVolumeRequests(ctx, postgresCluster))
@@ -2829,34 +2828,37 @@ func (r *Reconciler) getRepoHostVolumeRequests(ctx context.Context,
28292828
cluster *v1beta1.PostgresCluster) error {
28302829

28312830
pods := &corev1.PodList{}
2832-
err := errors.WithStack(
2831+
iferr := errors.WithStack(
28332832
r.Client.List(ctx, pods,
28342833
client.InNamespace(cluster.Namespace),
28352834
client.MatchingLabelsSelector{
28362835
Selector: naming.PGBackRestDedicatedLabels(cluster.Name).AsSelector()},
2837-
))
2838-
2839-
if len(pods.Items) == 1 {
2840-
// there should only ever be one repo host Pod
2841-
repoHost := pods.Items[0]
2842-
2843-
if cluster.Status.PGBackRest != nil {
2844-
var backupRequest string
2845-
for i := range cluster.Status.PGBackRest.Repos {
2846-
if repoHost.Annotations["suggested-"+cluster.Status.PGBackRest.Repos[i].Name+"-pvc-size"] != "" {
2847-
// get the backup request from the status, if it is set
2848-
backupRequest = cluster.Status.PGBackRest.Repos[i].DesiredRepoVolume
2849-
2850-
value := r.storeDesiredRequest(ctx, cluster, cluster.Status.PGBackRest.Repos[i].Name, "repo-host",
2851-
repoHost.Annotations["suggested-"+cluster.Status.PGBackRest.Repos[i].Name+"-pvc-size"], backupRequest)
2852-
if err == nil {
2853-
cluster.Status.PGBackRest.Repos[i].DesiredRepoVolume = value
2854-
}
2855-
}
2836+
)); err != nil {
2837+
return err
2838+
}
2839+
2840+
// there should only ever be one repo host Pod
2841+
if len(pods.Items) != 1 {
2842+
return errors.Errorf("Found %d pgBackRest repo host Pods. Expected 1.", len(pods.Items))
2843+
}
2844+
repoHost := pods.Items[0]
2845+
2846+
if cluster.Status.PGBackRest != nil {
2847+
var backupRequest string
2848+
for i := range cluster.Status.PGBackRest.Repos {
2849+
if repoHost.Annotations["suggested-"+cluster.Status.PGBackRest.Repos[i].Name+"-pvc-size"] != "" {
2850+
// get the backup request from the status, if it is set
2851+
backupRequest = cluster.Status.PGBackRest.Repos[i].DesiredRepoVolume
2852+
2853+
value := r.storeDesiredRequest(ctx, cluster, cluster.Status.PGBackRest.Repos[i].Name, "repo-host",
2854+
repoHost.Annotations["suggested-"+cluster.Status.PGBackRest.Repos[i].Name+"-pvc-size"], backupRequest)
2855+
2856+
cluster.Status.PGBackRest.Repos[i].DesiredRepoVolume = value
28562857
}
28572858
}
28582859
}
2859-
return err
2860+
2861+
return nil
28602862
}
28612863

28622864
// +kubebuilder:rbac:groups="",resources="pods",verbs={get,list}

‎internal/controller/postgrescluster/pgbackrest_test.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4515,7 +4515,13 @@ func TestGetRepoHostVolumeRequests(t *testing.T) {
45154515
}
45164516

45174517
err := reconciler.getRepoHostVolumeRequests(ctx, cluster)
4518-
assert.NilError(t, err)
4518+
4519+
if tc.repoHostExists {
4520+
assert.NilError(t, err)
4521+
} else {
4522+
assert.ErrorContains(t, err, "Found 0 pgBackRest repo host Pods. Expected 1.")
4523+
}
4524+
45194525
assert.Assert(t, cluster.Status.PGBackRest != nil)
45204526

45214527
var i int

‎internal/pgbackrest/config.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,11 @@ func reloadCommand(name string) []string {
627627
// the '1M-blocks' output (second column) and the 'use' variable gets the value
628628
// from the 'Use%' column (fifth column). This value is grabbed after stripping
629629
// out the column headers (before the '\n') and then getting the respective
630-
// value delimited by the white spaces. The percent value is stripped of the
631-
// '%' and then used to determine if a expansion should be triggered by setting
632-
// the calculated volume size using the 'size' variable.
630+
// value delimited by the white spaces by using the 'read -r' command.
631+
// The underscores (_) discard fields and the variables store them. This allows
632+
// for selective parsing of the provided lines. The percent value is stripped of
633+
// the '%' and then used to determine if a expansion should be triggered by
634+
// setting the calculated volume size using the 'size' variable.
633635
const script = `
634636
# Parameters for curl when managing autogrow annotation.
635637
APISERVER="https://kubernetes.default.svc"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /