-
Notifications
You must be signed in to change notification settings - Fork 2
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
EVEREST-1874 | support volume expansion for PXC #688
base: main
Are you sure you want to change the base?
Changes from all commits
dfd743f
95f93e3
97ef5ee
daf3155
f7f9c32
7b93834
64fc1b4
c3d5a1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -793,3 +793,37 @@ | |
} | ||
return ud, nil | ||
} | ||
|
||
const ( | ||
storageClassDefaultAnnotation = "storageclass.kubernetes.io/is-default-class" | ||
) | ||
|
||
// StorageClassSupportsVolumeExpansion returns true if the storage class supports volume expansion. | ||
// If className is unspecified, uses the default storage class | ||
func StorageClassSupportsVolumeExpansion(c client.Client, ctx context.Context, className *string) (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||
storageClass, err := getStorageClassOrDefault(c, ctx, className) | ||
if err != nil { | ||
return false, fmt.Errorf("getStorageClassOrDefault failed: %w", err) | ||
} | ||
return *storageClass.AllowVolumeExpansion, nil | ||
} | ||
|
||
func getStorageClassOrDefault(c client.Client, ctx context.Context, scName *string) (*storagev1.StorageClass, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||
storageClass := &storagev1.StorageClass{} | ||
if scName == nil { | ||
storageClasses := &storagev1.StorageClassList{} | ||
if err := c.List(ctx, storageClasses); err != nil { | ||
return nil, err | ||
} | ||
for _, sc := range storageClasses.Items { | ||
if sc.Annotations[storageClassDefaultAnnotation] == "true" { | ||
return &sc, nil | ||
} | ||
} | ||
return nil, fmt.Errorf("no default storage class found") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||
} | ||
if err := c.Get(ctx, types.NamespacedName{Name: *scName}, storageClass); err != nil { | ||
return nil, err | ||
} | ||
return storageClass, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,12 @@ | |
pxcv1 "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
|
||
everestv1alpha1 "github.com/percona/everest-operator/api/v1alpha1" | ||
|
@@ -73,6 +75,63 @@ | |
} | ||
} | ||
|
||
func configureStorage( | ||
c client.Client, | ||
ctx context.Context, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||
desired *pxcv1.PerconaXtraDBClusterSpec, | ||
current *pxcv1.PerconaXtraDBClusterSpec, | ||
db *everestv1alpha1.DatabaseCluster, | ||
) error { | ||
meta.RemoveStatusCondition(&db.Status.Conditions, everestv1alpha1.ConditionTypeCannotExpandStorage) | ||
|
||
var currentSize resource.Quantity | ||
desiredSize := db.Spec.Engine.Storage.Size | ||
|
||
if db.Status.Status != everestv1alpha1.AppStateNew { | ||
currentSize = current.PXC.PodSpec.VolumeSpec.PersistentVolumeClaim.Resources.Requests[corev1.ResourceStorage] | ||
} | ||
|
||
hasStorageExpanded := currentSize.Cmp(desiredSize) < 0 && !currentSize.IsZero() | ||
allowedByStorageClass, err := common.StorageClassSupportsVolumeExpansion(c, ctx, db.Spec.Engine.Storage.Class) | ||
if err != nil { | ||
return fmt.Errorf("failed to check if storage class supports volume expansion: %w", err) | ||
} | ||
|
||
if hasStorageExpanded && db.Spec.Engine.Storage.DisableVolumeExpansion { | ||
meta.SetStatusCondition(&db.Status.Conditions, metav1.Condition{ | ||
Type: everestv1alpha1.ConditionTypeCannotExpandStorage, | ||
Status: metav1.ConditionTrue, | ||
Reason: everestv1alpha1.ReasonStorageExpasionDisabled, | ||
LastTransitionTime: metav1.Now(), | ||
ObservedGeneration: db.GetGeneration(), | ||
}) | ||
desiredSize = currentSize | ||
} | ||
|
||
if hasStorageExpanded && !allowedByStorageClass { | ||
meta.SetStatusCondition(&db.Status.Conditions, metav1.Condition{ | ||
Type: everestv1alpha1.ConditionTypeCannotExpandStorage, | ||
Status: metav1.ConditionTrue, | ||
Reason: everestv1alpha1.ReasonStorageClassDoesNotSupportExpansion, | ||
LastTransitionTime: metav1.Now(), | ||
ObservedGeneration: db.GetGeneration(), | ||
}) | ||
desiredSize = currentSize | ||
} | ||
|
||
desired.PXC.PodSpec.VolumeSpec = &pxcv1.VolumeSpec{ | ||
PersistentVolumeClaim: &corev1.PersistentVolumeClaimSpec{ | ||
StorageClassName: db.Spec.Engine.Storage.Class, | ||
Resources: corev1.VolumeResourceRequirements{ | ||
Requests: corev1.ResourceList{ | ||
corev1.ResourceStorage: desiredSize, | ||
}, | ||
}, | ||
}, | ||
} | ||
return nil | ||
} | ||
|
||
func (p *applier) Engine() error { | ||
engine := p.DBEngine | ||
if p.DB.Spec.Engine.Version == "" { | ||
|
@@ -97,15 +156,12 @@ | |
} | ||
pxc.Spec.PXC.Image = pxcEngineVersion.ImagePath | ||
|
||
pxc.Spec.PXC.PodSpec.VolumeSpec = &pxcv1.VolumeSpec{ | ||
PersistentVolumeClaim: &corev1.PersistentVolumeClaimSpec{ | ||
StorageClassName: p.DB.Spec.Engine.Storage.Class, | ||
Resources: corev1.VolumeResourceRequirements{ | ||
Requests: corev1.ResourceList{ | ||
corev1.ResourceStorage: p.DB.Spec.Engine.Storage.Size, | ||
}, | ||
}, | ||
}, | ||
if !p.DB.Spec.Engine.Storage.DisableVolumeExpansion { | ||
pxc.Spec.VolumeExpansionEnabled = true | ||
} | ||
|
||
if err := configureStorage(p.C, p.ctx, &pxc.Spec, &p.currentPerconaXtraDBClusterSpec, p.DB); err != nil { | ||
return err | ||
} | ||
|
||
if !p.DB.Spec.Engine.Resources.CPU.IsZero() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
Comment should end in a period (godot)