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
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A=
github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y=
github.com/lestrrat-go/blackmagic v1.0.1 h1:lS5Zts+5HIC/8og6cGHb0uCcNCa3OUt1ygh3Qz2Fe80=
github.com/lestrrat-go/blackmagic v1.0.1/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
github.com/lestrrat-go/jwx v1.2.26 h1:4iFo8FPRZGDYe1t19mQP0zTRqA7n8HnJ5lkIiDvJcB0=
github.com/lestrrat-go/jwx v1.2.26/go.mod h1:MaiCdGbn3/cckbOFSCluJlJMmp9dmZm5hDuIkx8ftpQ=
github.com/lestrrat-go/jwx v1.2.27 h1:cvnTnda/YzdyFuWdEAMkI6BsLtItSrASEVCI3C/IUEQ=
github.com/lestrrat-go/jwx v1.2.27/go.mod h1:Stob9LjSqR3lOmNdxF0/TvZo60V3hUGv8Fr7Bwzla3k=
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
Expand Down Expand Up @@ -442,7 +438,6 @@ golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWP
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
Expand Down
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 @@ -2328,6 +2328,8 @@ spec:
pools:
items:
properties:
additionalStorage:
type: string
affinity:
properties:
nodeAffinity:
Expand Down
7 changes: 7 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,13 @@ 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 update the pvc only.
// Examples: 2Gi
// Total = Request + AdditionalStorage
// +optional
AdditionalStorage *string `json:"additionalStorage"`
}

// 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
77 changes: 77 additions & 0 deletions pkg/controller/pvc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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+AdditionalStorage if set AdditionalStorage to pool
func (c *Controller) ResizePVCS(ctx context.Context, tenant *miniov2.Tenant) {
for _, pool := range tenant.Spec.Pools {
if pool.AdditionalStorage != nil {
q, err := resource.ParseQuantity(*pool.AdditionalStorage)
if err != nil {
// if parse error. Continue
fmt.Printf("ParseQuantity %s error: %s \n", *pool.AdditionalStorage, err.Error())
continue
}
storageRequest := pool.VolumeClaimTemplate.Spec.Resources.Requests.Storage()
if storageRequest != nil {
q.Add(*storageRequest)
}
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()))
}
for _, pvc := range pvcList.Items {
// if already resized with a bigger or equal size, do nothing
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()))
}
}
}
}
}
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 @@ -2328,6 +2328,8 @@ spec:
pools:
items:
properties:
additionalStorage:
type: string
affinity:
properties:
nodeAffinity:
Expand Down