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 b395965

Browse files
committed
Additional events, update tests, update script, add comment and
refactor for repo-host autogrow Issue: PGO-1427
1 parent 3e8f64f commit b395965

File tree

6 files changed

+66
-38
lines changed

6 files changed

+66
-38
lines changed

‎internal/controller/postgrescluster/autogrow.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// status. If the value has grown, create an Event.
2222
func (r *Reconciler) storeDesiredRequest(
2323
ctx context.Context, cluster *v1beta1.PostgresCluster,
24-
volumeType, instanceSetName, desiredRequest, desiredRequestBackup string,
24+
volumeType, host, desiredRequest, desiredRequestBackup string,
2525
) string {
2626
var current resource.Quantity
2727
var previous resource.Quantity
@@ -33,7 +33,7 @@ func (r *Reconciler) storeDesiredRequest(
3333
current, err = resource.ParseQuantity(desiredRequest)
3434
if err != nil {
3535
log.Error(err, "Unable to parse "+volumeType+" volume request from status ("+
36-
desiredRequest+") for "+cluster.Name+"/"+instanceSetName)
36+
desiredRequest+") for "+cluster.Name+"/"+host)
3737
// If there was an error parsing the value, treat as unset (equivalent to zero).
3838
desiredRequest = ""
3939
current, _ = resource.ParseQuantity("")
@@ -46,7 +46,7 @@ func (r *Reconciler) storeDesiredRequest(
4646
previous, err = resource.ParseQuantity(desiredRequestBackup)
4747
if err != nil {
4848
log.Error(err, "Unable to parse "+volumeType+" volume request from status backup ("+
49-
desiredRequestBackup+") for "+cluster.Name+"/"+instanceSetName)
49+
desiredRequestBackup+") for "+cluster.Name+"/"+host)
5050
// If there was an error parsing the value, treat as unset (equivalent to zero).
5151
desiredRequestBackup = ""
5252
previous, _ = resource.ParseQuantity("")
@@ -55,12 +55,12 @@ func (r *Reconciler) storeDesiredRequest(
5555
}
5656

5757
// determine if the appropriate volume limit is set
58-
limitSet := limitIsSet(cluster, volumeType, instanceSetName)
58+
limitSet := limitIsSet(cluster, volumeType, host)
5959

6060
if limitSet && current.Value() > previous.Value() {
6161
r.Recorder.Eventf(cluster, corev1.EventTypeNormal, "VolumeAutoGrow",
6262
"%s volume expansion to %v requested for %s/%s.",
63-
volumeType, current.String(), cluster.Name, instanceSetName)
63+
volumeType, current.String(), cluster.Name, host)
6464
}
6565

6666
// If the desired size was not observed, update with previously stored value.

‎internal/controller/postgrescluster/instance_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
559559
manageAutogrowAnnotation() {
560560
local volume=1ドル
561561
562-
size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
562+
size=$(df --block-size=M "/pgbackrest/${volume}")
563563
read -r _ size _ <<< "${size#*$'\n'}"
564-
use=$(df --human-readable "/pgbackrest/${volume}")
564+
use=$(df "/pgbackrest/${volume}")
565565
read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
566566
sizeInt="${size//M/}"
567567
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
@@ -725,9 +725,9 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
725725
manageAutogrowAnnotation() {
726726
local volume=1ドル
727727
728-
size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
728+
size=$(df --block-size=M "/pgbackrest/${volume}")
729729
read -r _ size _ <<< "${size#*$'\n'}"
730-
use=$(df --human-readable "/pgbackrest/${volume}")
730+
use=$(df "/pgbackrest/${volume}")
731731
read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
732732
sizeInt="${size//M/}"
733733
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.

‎internal/controller/postgrescluster/pgbackrest.go‎

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

2778-
// get the autogrow annotations so that the correct volume size values can be
2779-
// used and the cluster status can be updated
2780-
errors = append(errors, r.getRepoHostVolumeRequests(ctx, postgresCluster))
2778+
autogrow := feature.Enabled(ctx, feature.AutoGrowVolumes)
2779+
if autogrow {
2780+
// get the autogrow annotations so that the correct volume size values can be
2781+
// used and the cluster status can be updated
2782+
errors = append(errors, r.getRepoHostVolumeRequests(ctx, postgresCluster))
2783+
}
27812784

27822785
for i, repo := range postgresCluster.Spec.Backups.PGBackRest.Repos {
27832786
// the repo at index 0 is the replica creation repo
@@ -2833,15 +2836,22 @@ func (r *Reconciler) getRepoHostVolumeRequests(ctx context.Context,
28332836
Selector: naming.PGBackRestDedicatedLabels(cluster.Name).AsSelector()},
28342837
))
28352838

2836-
if len(pods.Items) >0 {
2839+
if len(pods.Items) ==1 {
28372840
// there should only ever be one repo host Pod
28382841
repoHost := pods.Items[0]
28392842

28402843
if cluster.Status.PGBackRest != nil {
2844+
var backupRequest string
28412845
for i := range cluster.Status.PGBackRest.Repos {
28422846
if repoHost.Annotations["suggested-"+cluster.Status.PGBackRest.Repos[i].Name+"-pvc-size"] != "" {
2843-
cluster.Status.PGBackRest.Repos[i].DesiredRepoVolume =
2844-
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+
}
28452855
}
28462856
}
28472857
}

‎internal/controller/postgrescluster/pgbackrest_test.go‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,6 +4405,7 @@ func TestGetRepoHostVolumeRequests(t *testing.T) {
44054405
tcName string
44064406
repoHostExists bool
44074407
annotations map[string]string
4408+
repoStatus []v1beta1.RepoStatus
44084409
results map[string]string
44094410
}{{
44104411
tcName: "no repo host",
@@ -4414,19 +4415,31 @@ func TestGetRepoHostVolumeRequests(t *testing.T) {
44144415
repoHostExists: true,
44154416
annotations: map[string]string{
44164417
"suggested-repo1-pvc-size": "2Gi"},
4418+
repoStatus: []v1beta1.RepoStatus{
4419+
{Name: "repo1", DesiredRepoVolume: "1Gi"}},
44174420
results: map[string]string{
44184421
"repo1": "2Gi"},
44194422
}, {
44204423
tcName: "multiple repo volumes",
44214424
repoHostExists: true,
44224425
annotations: map[string]string{
44234426
"suggested-repo2-pvc-size": "2Gi",
4424-
"suggested-repo3-pvc-size": "3Gi",
4425-
"suggested-repo4-pvc-size": "4Gi"},
4427+
"suggested-repo3-pvc-size": "3Gi"},
4428+
repoStatus: []v1beta1.RepoStatus{
4429+
{Name: "repo2", DesiredRepoVolume: "1Gi"},
4430+
{Name: "repo3", DesiredRepoVolume: "1Gi"}},
44264431
results: map[string]string{
44274432
"repo2": "2Gi",
4428-
"repo3": "3Gi",
4429-
"repo4": "4Gi"},
4433+
"repo3": "3Gi"},
4434+
}, {
4435+
tcName: "bad annotation use backup from status",
4436+
repoHostExists: true,
4437+
annotations: map[string]string{
4438+
"suggested-repo4-pvc-size": "seagull"},
4439+
repoStatus: []v1beta1.RepoStatus{
4440+
{Name: "repo4", DesiredRepoVolume: "8Gi"}},
4441+
results: map[string]string{
4442+
"repo4": "8Gi"},
44304443
}}
44314444

44324445
for _, tc := range testCases {
@@ -4465,26 +4478,22 @@ func TestGetRepoHostVolumeRequests(t *testing.T) {
44654478
Namespace: namespace,
44664479
},
44674480
Status: v1beta1.PostgresClusterStatus{
4468-
PGBackRest: &v1beta1.PGBackRestStatus{
4469-
Repos: []v1beta1.RepoStatus{{
4470-
Name: "repo1",
4471-
}, {
4472-
Name: "repo2",
4473-
}, {
4474-
Name: "repo3",
4475-
}, {
4476-
Name: "repo4",
4477-
}},
4478-
},
4481+
PGBackRest: &v1beta1.PGBackRestStatus{},
44794482
},
44804483
}
44814484

4485+
// only add a status if the repo host exists
4486+
if tc.repoHostExists {
4487+
cluster.Status.PGBackRest.Repos = tc.repoStatus
4488+
}
4489+
44824490
err := reconciler.getRepoHostVolumeRequests(ctx, cluster)
44834491
assert.NilError(t, err)
44844492
assert.Assert(t, cluster.Status.PGBackRest != nil)
44854493

44864494
var i int
44874495
for _, repo := range cluster.Status.PGBackRest.Repos {
4496+
44884497
assert.Assert(t, tc.results[repo.Name] == repo.DesiredRepoVolume)
44894498
if tc.results[repo.Name] == repo.DesiredRepoVolume && repo.DesiredRepoVolume != "" {
44904499
i++

‎internal/pgbackrest/config.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,15 @@ func reloadCommand(name string) []string {
621621
// descriptor gets closed and reopened to use the builtin `[ -nt` to check
622622
// mtimes.
623623
// - https://unix.stackexchange.com/a/407383
624+
625+
// In the manageAutogrowAnnotation function below, df is used to return the
626+
// relevant volume size in Mebibytes. The 'read' variable gets the value from
627+
// the '1M-blocks' output (second column) and the 'use' variable gets the value
628+
// from the 'Use%' column (fifth column). This value is grabbed after stripping
629+
// 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.
624633
const script = `
625634
# Parameters for curl when managing autogrow annotation.
626635
APISERVER="https://kubernetes.default.svc"
@@ -634,9 +643,9 @@ CACERT=${SERVICEACCOUNT}/ca.crt
634643
manageAutogrowAnnotation() {
635644
local volume=1ドル
636645
637-
size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
646+
size=$(df --block-size=M "/pgbackrest/${volume}")
638647
read -r _ size _ <<< "${size#*$'\n'}"
639-
use=$(df --human-readable "/pgbackrest/${volume}")
648+
use=$(df "/pgbackrest/${volume}")
640649
read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
641650
sizeInt="${size//M/}"
642651
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.

‎internal/pgbackrest/reconcile_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,9 @@ func TestAddServerToInstancePod(t *testing.T) {
746746
manageAutogrowAnnotation() {
747747
local volume=1ドル
748748
749-
size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
749+
size=$(df --block-size=M "/pgbackrest/${volume}")
750750
read -r _ size _ <<< "${size#*$'\n'}"
751-
use=$(df --human-readable "/pgbackrest/${volume}")
751+
use=$(df "/pgbackrest/${volume}")
752752
read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
753753
sizeInt="${size//M/}"
754754
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
@@ -924,9 +924,9 @@ func TestAddServerToInstancePod(t *testing.T) {
924924
manageAutogrowAnnotation() {
925925
local volume=1ドル
926926
927-
size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
927+
size=$(df --block-size=M "/pgbackrest/${volume}")
928928
read -r _ size _ <<< "${size#*$'\n'}"
929-
use=$(df --human-readable "/pgbackrest/${volume}")
929+
use=$(df "/pgbackrest/${volume}")
930930
read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
931931
sizeInt="${size//M/}"
932932
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
@@ -1091,9 +1091,9 @@ func TestAddServerToRepoPod(t *testing.T) {
10911091
manageAutogrowAnnotation() {
10921092
local volume=1ドル
10931093
1094-
size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
1094+
size=$(df --block-size=M "/pgbackrest/${volume}")
10951095
read -r _ size _ <<< "${size#*$'\n'}"
1096-
use=$(df --human-readable "/pgbackrest/${volume}")
1096+
use=$(df "/pgbackrest/${volume}")
10971097
read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
10981098
sizeInt="${size//M/}"
10991099
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.

0 commit comments

Comments
(0)

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