Skip to content

Commit

Permalink
K8SPXC-1451: disable pvc resize by default
Browse files Browse the repository at this point in the history
  • Loading branch information
pooknull committed Sep 20, 2024
1 parent 318e7d7 commit 7023d9b
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 51 deletions.
2 changes: 2 additions & 0 deletions config/crd/bases/pxc.percona.com_perconaxtradbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,8 @@ spec:
type: string
enableCRValidationWebhook:
type: boolean
enableVolumeExpansion:
type: boolean
haproxy:
properties:
affinity:
Expand Down
2 changes: 2 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,8 @@ spec:
type: string
enableCRValidationWebhook:
type: boolean
enableVolumeExpansion:
type: boolean
haproxy:
properties:
affinity:
Expand Down
1 change: 1 addition & 0 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ metadata:
# percona.com/issue-vault-token: "true"
spec:
crVersion: 1.16.0
# enableVolumeExpansion: true
# ignoreAnnotations:
# - iam.amazonaws.com/role
# ignoreLabels:
Expand Down
2 changes: 2 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,8 @@ spec:
type: string
enableCRValidationWebhook:
type: boolean
enableVolumeExpansion:
type: boolean
haproxy:
properties:
affinity:
Expand Down
2 changes: 2 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,8 @@ spec:
type: string
enableCRValidationWebhook:
type: boolean
enableVolumeExpansion:
type: boolean
haproxy:
properties:
affinity:
Expand Down
105 changes: 54 additions & 51 deletions e2e-tests/pvc-resize/run
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function ensure_default_sc_allows_expansion() {

local allowVolumeExpansion=$(kubectl_bin get sc -o jsonpath='{.items[?(@.metadata.name=="'"${default_sc}"'")].allowVolumeExpansion}')

if [[ "${allowVolumeExpansion}" != "true" ]]; then
if [[ ${allowVolumeExpansion} != "true" ]]; then
echo "Default storageclass ${default_sc} does not allow volume expansion"
exit 0
fi
Expand All @@ -41,10 +41,10 @@ function apply_resourcequota() {

echo "Applying resourcequota for default storageclass ${sc} with quota ${quota}"

cat ${test_dir}/conf/resourcequota.yml |
sed "s/STORAGECLASS/${sc}/" |
sed "s/QUOTA/${quota}/" |
kubectl_bin apply -f -
cat ${test_dir}/conf/resourcequota.yml \
| sed "s/STORAGECLASS/${sc}/" \
| sed "s/QUOTA/${quota}/" \
| kubectl_bin apply -f -
}

function wait_cluster_status() {
Expand All @@ -68,6 +68,43 @@ function wait_cluster_status() {
echo "pxc/${cluster} status is ${expected}"
}

function wait_all_pvc_resize() {
local expected_size=$1
local max_retry=${2:-120}
local sleep_time=${3:-5}

for pvc in $(kubectl_bin get pvc -l app.kubernetes.io/component=pxc -o name); do
if ! wait_pvc_resize "$pvc" "$expected_size" "$max_retry" "$sleep_time"; then
return 1
fi
done
return 0
}

function wait_pvc_resize() {
local pvc=$1
local expected_size=$2
local max_retry=${3:-120}
local sleep_time=${4:-5}

local retry=0
echo "Waiting for $pvc to be resized"
until [[ $(kubectl_bin get "$pvc" -o jsonpath='{.status.capacity.storage}') == "$expected_size" ]]; do
if [[ $retry -ge $max_retry ]]; then
echo
echo "$pvc was not resized, max retries exceeded"
return 1
fi
echo -n "."
sleep "$sleep_time"

retry=$((retry + 1))
done
echo
echo "${pvc} was resized"
return 0
}

set_debug

if [ "$EKS" == 1 -o -n "$OPENSHIFT" ]; then
Expand All @@ -93,24 +130,17 @@ desc "test scaling"
patch_pvc_request "${cluster}" "3G"
wait_cluster_consistency "$cluster" 3 2

for pvc in $(kubectl_bin get pvc -l app.kubernetes.io/component=pxc -o name); do
retry=0
echo -n "Waiting for ${pvc} to be resized"
until [[ $(kubectl_bin get ${pvc} -o jsonpath={.status.capacity.storage}) == "3Gi" ]]; do
if [[ $retry -ge 60 ]]; then
echo
echo "pvc/${pvc} was not resized, max retries exceeded"
exit 1
fi
if wait_all_pvc_resize "3Gi" 120 1; then
echo "PVC was resized, but resize.expansion is disabled"
exit 1
fi

echo -n "."
sleep 5
echo "Enabling PVC resize"
kubectl_bin patch pxc "${cluster}" --type=json -p='[{"op": "add", "path": "/spec/enableVolumeExpansion", "value":true }]'
sleep 10

retry=$((retry + 1))
done
echo
echo "${pvc} was resized"
done
wait_cluster_consistency "$cluster" 3 2
wait_all_pvc_resize "3Gi"

if [ "$EKS" == 1 -o -n "$OPENSHIFT" ]; then
# EKS rate limits PVC expansion for the same EBS volume (1 expand operation in every 6 hours),
Expand All @@ -130,43 +160,16 @@ patch_pvc_request "${cluster}" "4G"
wait_cluster_consistency "$cluster" 3 2
echo

echo -n "Waiting for pvc/datadir-some-name-pxc-0 to be resized"
until [[ $(kubectl_bin get pvc datadir-some-name-pxc-0 -o jsonpath={.status.capacity.storage}) == "4Gi" ]]; do
if [[ $retry -ge 60 ]]; then
echo
echo "pvc/datadir-some-name-pxc-0 was not resized, max retries exceeded"
exit 1
fi
echo -n "."
sleep 5

retry=$((retry + 1))
done
echo
echo "Waiting for pvc/datadir-some-name-pxc-0 to be resized"
wait_pvc_resize "persistentvolumeclaim/datadir-some-name-pxc-0" "4Gi"
echo "pvc/datadir-some-name-pxc-0 was resized"

# We're setting the quota to 16Gi, so we can resize all PVCs to 4Gi
apply_resourcequota 12Gi
patch_pvc_request "${cluster}" "4G"
wait_cluster_consistency "$cluster" 3 2
echo
for pvc in $(kubectl_bin get pvc -l app.kubernetes.io/component=pxc -o name); do
retry=0
echo -n "Waiting for pvc/${pvc} to be resized"
until [[ $(kubectl_bin get ${pvc} -o jsonpath={.status.capacity.storage}) == "4Gi" ]]; do
if [[ $retry -ge 60 ]]; then
echo
echo "pvc/${pvc} was not resized, max retries exceeded"
exit 1
fi
echo -n "."
sleep 5

retry=$((retry + 1))
done
echo
echo "pvc/${pvc} was resized"
done
wait_all_pvc_resize "4Gi"

desc "test downscale"

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/pxc/v1/pxc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type PerconaXtraDBClusterSpec struct {
UpgradeOptions UpgradeOptions `json:"upgradeOptions,omitempty"`
AllowUnsafeConfig bool `json:"allowUnsafeConfigurations,omitempty"`
Unsafe UnsafeFlags `json:"unsafeFlags,omitempty"`
VolumeExpansionEnabled bool `json:"enableVolumeExpansion,omitempty"`

// Deprecated, should be removed in the future. Use InitContainer.Image instead
InitImage string `json:"initImage,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/pxc/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ func (r *ReconcilePerconaXtraDBCluster) reconcilePersistentVolumes(ctx context.C
return nil
}

if cr.CompareVersionWith("1.16.0") >= 0 && !cr.Spec.VolumeExpansionEnabled {
// If expansion is disabled we should keep the old value
cr.Spec.PXC.VolumeSpec.PersistentVolumeClaim.Resources.Requests[corev1.ResourceStorage] = configured
return nil
}

err = k8s.AnnotateObject(ctx, r.client, cr, map[string]string{pxcv1.AnnotationPVCResizeInProgress: metav1.Now().Format(time.RFC3339)})
if err != nil {
return errors.Wrap(err, "annotate pxc")
Expand Down

0 comments on commit 7023d9b

Please sign in to comment.