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
Show file tree
Hide file tree
Changes from 6 commits
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
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 @@ -2868,6 +2868,8 @@ spec:
servers:
format: int32
type: integer
storageDeletion:
type: boolean
tolerations:
items:
properties:
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/operator-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rules:
- get
- update
- list
- delete
- apiGroups:
- ""
resources:
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/minio.min.io/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"storageDeletion,omitempty"`
}

// EqualImage returns true if config image and current input image are same
Expand Down
20 changes: 20 additions & 0 deletions pkg/controller/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 StorageDeletionLabel: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.StorageDeletionLabel] == "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
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (

const (
bucketDNSEnv = "MINIO_DNS_WEBHOOK_ENDPOINT"
// StorageDeletionLabel - pvc with this label and the value is `true` means when tenant is being deleted the pvc will be deleted.
StorageDeletionLabel = "storageDeletion"
)

// Returns the MinIO environment variables set in configuration.
Expand Down Expand Up @@ -854,6 +856,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[StorageDeletionLabel] = "true"
}
name := pvClaim.Name
for i := 0; i < int(pool.VolumesPerServer); i++ {
pvClaim.Name = name + strconv.Itoa(i)
Expand Down
1 change: 1 addition & 0 deletions resources/base/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rules:
- get
- update
- list
- delete
- apiGroups:
- ""
resources:
Expand Down
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 @@ -2868,6 +2868,8 @@ spec:
servers:
format: int32
type: integer
storageDeletion:
type: boolean
tolerations:
items:
properties:
Expand Down