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: add support pvc deletion when need #1828

Merged
merged 12 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
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
Next Next commit
feat: add support pvc deletion when need
guozhi.li committed Oct 23, 2023
commit efa9c38d4dc942ee3dca902dcefba2e5bdc9c58f
2 changes: 2 additions & 0 deletions helm/operator/templates/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
@@ -2868,6 +2868,8 @@ spec:
servers:
format: int32
type: integer
stroageDeletion:
type: boolean
tolerations:
items:
properties:
5 changes: 5 additions & 0 deletions pkg/apis/minio.min.io/v2/types.go
Original file line number Diff line number Diff line change
@@ -702,6 +702,11 @@ type Pool struct {
// If provided, each pod on the Statefulset will run with the specified RuntimeClassName, for more info https://kubernetes.io/docs/concepts/containers/runtime-class/
// +optional
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
// *Optional* +
//
// If true. Will delete the stroage when tenant has been deleted.
jiuker marked this conversation as resolved.
Show resolved Hide resolved
// +optional
StorageDeletion *bool `json:"stroageDeletion,omitempty"`
}

// EqualImage returns true if config image and current input image are same
20 changes: 20 additions & 0 deletions pkg/controller/main-controller.go
Original file line number Diff line number Diff line change
@@ -752,6 +752,26 @@ 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 StroageDeletionLabel: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.StroageDeletionLabel] == "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()))
}
}
}
return WrapResult(Result{}, nil)
}
// will retry after 5sec
9 changes: 8 additions & 1 deletion pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
@@ -33,7 +33,8 @@ import (
)

const (
bucketDNSEnv = "MINIO_DNS_WEBHOOK_ENDPOINT"
bucketDNSEnv = "MINIO_DNS_WEBHOOK_ENDPOINT"
StroageDeletionLabel = "stroageDeletion"
)

// Returns the MinIO environment variables set in configuration.
@@ -854,6 +855,12 @@ func NewPool(args *NewPoolArgs) *appsv1.StatefulSet {

if pool.VolumeClaimTemplate != nil {
pvClaim := *pool.VolumeClaimTemplate
if pool.StorageDeletion != nil && *pool.StorageDeletion {
if len(pvClaim.Labels) == 0 {
pvClaim.Labels = make(map[string]string)
}
pvClaim.Labels[StroageDeletionLabel] = "true"
}
name := pvClaim.Name
for i := 0; i < int(pool.VolumesPerServer); i++ {
pvClaim.Name = name + strconv.Itoa(i)
2 changes: 2 additions & 0 deletions resources/base/crds/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
@@ -2868,6 +2868,8 @@ spec:
servers:
format: int32
type: integer
stroageDeletion:
type: boolean
tolerations:
items:
properties: