Skip to content

K8SPG-768 skip log creation #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 25 additions & 16 deletions internal/postgres/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func Environment(cluster *v1beta1.PostgresCluster) []corev1.EnvVar {
// reloadCommand returns an entrypoint that convinces PostgreSQL to reload
// certificate files when they change. The process will appear as name in `ps`
// and `top`.
func reloadCommand(name string, post250 bool) []string {
func reloadCommand(name string, post250 bool, AutoGrowVolumes bool) []string {
// Use a Bash loop to periodically check the mtime of the mounted
// certificate volume. When it changes, copy the replication certificate,
// signal PostgreSQL, and print the observed timestamp.
Expand All @@ -193,6 +193,7 @@ func reloadCommand(name string, post250 bool) []string {
// descriptor gets closed and reopened to use the builtin `[ -nt` to check
// mtimes.
// - https://unix.stackexchange.com/a/407383

script := fmt.Sprintf(`
declare -r directory=%q
exec {fd}<> <(:)
Expand All @@ -214,6 +215,27 @@ done
)

if post250 {
// Only add annotation update logic if AutoGrowVolumes is true
autogrowScript := ""
if AutoGrowVolumes {
autogrowScript = `
# Manage autogrow annotation.
# Return size in Mebibytes.
size=$(df --human-readable --block-size=M /pgdata | awk 'FNR == 2 {print $2}')
use=$(df --human-readable /pgdata | awk 'FNR == 2 {print $5}')
sizeInt="${size//M/}"
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
useInt=$(echo $use | sed 's/[[:punct:]]//g')
triggerExpansion="$((useInt > 75))"
if [ $triggerExpansion -eq 1 ]; then
newSize="$(((sizeInt / 2)+sizeInt))"
newSizeMi="${newSize}Mi"
d='[{"op": "add", "path": "/metadata/annotations/suggested-pgdata-pvc-size", "value": "'"$newSizeMi"'"}]'
curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "$d"
fi
`
}

script = fmt.Sprintf(`
# Parameters for curl when managing autogrow annotation.
APISERVER="https://kubernetes.default.svc"
Expand All @@ -233,28 +255,15 @@ while read -r -t 5 -u "${fd}" ||:; do
exec {fd}>&- && exec {fd}<> <(:||:)
stat --format='Loaded certificates dated %%y' "${directory}"
fi

# Manage autogrow annotation.
# Return size in Mebibytes.
size=$(df --human-readable --block-size=M /pgdata | awk 'FNR == 2 {print $2}')
use=$(df --human-readable /pgdata | awk 'FNR == 2 {print $5}')
sizeInt="${size//M/}"
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
useInt=$(echo $use | sed 's/[[:punct:]]//g')
triggerExpansion="$((useInt > 75))"
if [ $triggerExpansion -eq 1 ]; then
newSize="$(((sizeInt / 2)+sizeInt))"
newSizeMi="${newSize}Mi"
d='[{"op": "add", "path": "/metadata/annotations/suggested-pgdata-pvc-size", "value": "'"$newSizeMi"'"}]'
curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "$d"
fi
%s
done
`,
naming.CertMountPath,
naming.ReplicationTmp,
naming.ReplicationCertPath,
naming.ReplicationPrivateKeyPath,
naming.ReplicationCACertPath,
autogrowScript, // This will be empty if AutoGrowVolumes is false
)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/postgres/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func InstancePod(ctx context.Context,
reloader := corev1.Container{
Name: naming.ContainerClientCertCopy,

Command: reloadCommand(naming.ContainerClientCertCopy, inCluster.CompareVersion("2.5.0") >= 0),
Command: reloadCommand(naming.ContainerClientCertCopy, inCluster.CompareVersion("2.5.0") >= 0, feature.Enabled(ctx, feature.AutoGrowVolumes)),

Image: container.Image,
ImagePullPolicy: container.ImagePullPolicy,
Expand Down
14 changes: 0 additions & 14 deletions internal/postgres/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,6 @@ containers:
stat --format='Loaded certificates dated %y' "${directory}"
fi

# Manage autogrow annotation.
# Return size in Mebibytes.
size=$(df --human-readable --block-size=M /pgdata | awk 'FNR == 2 {print $2}')
use=$(df --human-readable /pgdata | awk 'FNR == 2 {print $5}')
sizeInt="${size//M/}"
# Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
useInt=$(echo $use | sed 's/[[:punct:]]//g')
triggerExpansion="$((useInt > 75))"
if [ $triggerExpansion -eq 1 ]; then
newSize="$(((sizeInt / 2)+sizeInt))"
newSizeMi="${newSize}Mi"
d='[{"op": "add", "path": "/metadata/annotations/suggested-pgdata-pvc-size", "value": "'"$newSizeMi"'"}]'
curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "$d"
fi
done
}; export -f monitor; exec -a "$0" bash -ceu monitor
- replication-cert-copy
Expand Down
Loading