Skip to content
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

feat: resize pvc #1904

Closed
wants to merge 16 commits into from
2 changes: 2 additions & 0 deletions helm/operator/templates/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,8 @@ spec:
type: string
type: object
type: object
expansionStorage:
jiuker marked this conversation as resolved.
Show resolved Hide resolved
type: string
labels:
additionalProperties:
type: string
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/minio.min.io/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,12 @@ type Pool struct {
// If true. Will delete the storage when tenant has been deleted.
// +optional
ReclaimStorage *bool `json:"reclaimStorage,omitempty"`
// *Optional* +
//
// If set. Operator will try to expansion storage. And statefulset will not restart. We just patch the pvc only.
// Total = Request + ExpansionStorage
// +optional
ExpansionStorage *string `json:"expansionStorage"`
}

// EqualImage returns true if config image and current input image are same
Expand Down
23 changes: 2 additions & 21 deletions pkg/controller/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,26 +773,7 @@ func (c *Controller) syncHandler(key string) (Result, error) {
// Just output the error. Will not retry.
runtime.HandleError(fmt.Errorf("DeletePrometheusAddlConfig '%s/%s' error:%s", namespace, tenantName, err.Error()))
}
// try to delete pvc if set ReclaimStorageLabel:true
pvcList := corev1.PersistentVolumeClaimList{}
listOpt := client.ListOptions{
Namespace: namespace,
}
client.MatchingLabels{
"v1.min.io/tenant": tenantName,
}.ApplyToList(&listOpt)
err := c.k8sClient.List(ctx, &pvcList, &listOpt)
if err != nil {
runtime.HandleError(fmt.Errorf("PersistentVolumeClaimList '%s/%s' error:%s", namespace, tenantName, err.Error()))
}
for _, pvc := range pvcList.Items {
if pvc.Labels[statefulsets.ReclaimStorageLabel] == "true" {
err := c.k8sClient.Delete(ctx, &pvc)
if err != nil {
runtime.HandleError(fmt.Errorf("Delete PersistentVolumeClaim '%s/%s/%s' error:%s", namespace, tenantName, pvc.Name, err.Error()))
}
}
}
c.TryToDeletePVCS(ctx, namespace, tenantName)
return WrapResult(Result{}, nil)
}
// will retry after 5sec
Expand Down Expand Up @@ -1432,7 +1413,7 @@ func (c *Controller) syncHandler(key string) (Result, error) {
if err != nil {
return WrapResult(Result{}, err)
}

c.ResizePVCS(ctx, tenant)
return WrapResult(Result{}, err)
}

Expand Down
76 changes: 76 additions & 0 deletions pkg/controller/pvc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package controller
jiuker marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"
"fmt"

miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
"github.com/minio/operator/pkg/resources/statefulsets"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// TryToDeletePVCS - try to delete pvc if set ReclaimStorageLabel:true
func (c *Controller) TryToDeletePVCS(ctx context.Context, namespace string, tenantName string) {
pvcList := corev1.PersistentVolumeClaimList{}
listOpt := client.ListOptions{
Namespace: namespace,
}
client.MatchingLabels{
"v1.min.io/tenant": tenantName,
}.ApplyToList(&listOpt)
err := c.k8sClient.List(ctx, &pvcList, &listOpt)
if err != nil {
runtime.HandleError(fmt.Errorf("PersistentVolumeClaimList '%s/%s' error:%s", namespace, tenantName, err.Error()))
}
for _, pvc := range pvcList.Items {
if pvc.Labels[statefulsets.ReclaimStorageLabel] == "true" {
err := c.k8sClient.Delete(ctx, &pvc)
if err != nil {
runtime.HandleError(fmt.Errorf("Delete PersistentVolumeClaim '%s/%s/%s' error:%s", namespace, tenantName, pvc.Name, err.Error()))
}
}
}
}

// ResizePVCS - try to resize pvc to Request+ExpansionStorage if set ExpansionStorage to pool
func (c *Controller) ResizePVCS(ctx context.Context, tenant *miniov2.Tenant) {
for _, pool := range tenant.Spec.Pools {
if pool.ExpansionStorage != nil {
q, err := resource.ParseQuantity(*pool.ExpansionStorage)
if err != nil {
// if parse error. Continue
continue
}
storageReqeset := pool.VolumeClaimTemplate.Spec.Resources.Requests.Storage()
jiuker marked this conversation as resolved.
Show resolved Hide resolved
if storageReqeset != nil {
q.Add(*storageReqeset)
}
pvcList := corev1.PersistentVolumeClaimList{}
listOpt := client.ListOptions{
Namespace: tenant.Namespace,
}
client.MatchingLabels{
"v1.min.io/tenant": tenant.Name,
"v1.min.io/pool": pool.Name,
}.ApplyToList(&listOpt)
err = c.k8sClient.List(ctx, &pvcList, &listOpt)
if err != nil {
runtime.HandleError(fmt.Errorf("PersistentVolumeClaimList '%s/%s/%s' error:%s", tenant.Namespace, tenant.Name, pool.Name, err.Error()))
jiuker marked this conversation as resolved.
Show resolved Hide resolved
}
for _, pvc := range pvcList.Items {
// if already resize the pvc to be a bigger or equal. do nothing.
jiuker marked this conversation as resolved.
Show resolved Hide resolved
if pvc.Spec.Resources.Requests.Storage().Cmp(q) != 1 {
continue
}
pvc.Spec.Resources.Requests[corev1.ResourceStorage] = q
err := c.k8sClient.Update(ctx, &pvc)
if err != nil {
runtime.HandleError(fmt.Errorf("Update PersistentVolumeClaim '%s/%s' to %s error:%s", tenant.Namespace, pvc.Name, q.String(), err.Error()))
jiuker marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
2 changes: 2 additions & 0 deletions resources/base/crds/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,8 @@ spec:
type: string
type: object
type: object
expansionStorage:
type: string
labels:
additionalProperties:
type: string
Expand Down
Loading