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 all 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
10 changes: 10 additions & 0 deletions docs/tenant-storage-deletion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# When one-time storage is required

There are times when we need to do tests, and once the tests are done, we need to clean up the storage immediately. We can do the following configuration

```$xslt
- name: pool-0
reclaimStorage: true
```

When a tenant is deleted, the associated pvc is also deleted immediately.
14 changes: 4 additions & 10 deletions docs/tenant_crd.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ CertificateStatus keeps track of all the certificates managed by the operator
|===


[id="{anchor_prefix}-github-com-minio-operator-pkg-apis-minio-min-io-v2-customcertificateconfig"]
==== CustomCertificateConfig

CustomCertificateConfig (`customCertificateConfig`) provides attributes associated of the TLS certificates manually added to the Operator as part of tenant creation. These fields contain no data if there are no custom TLS certificates.

.Appears In:
****
- xref:{anchor_prefix}-github-com-minio-operator-pkg-apis-minio-min-io-v2-customcertificates[$$CustomCertificates$$]
****



[id="{anchor_prefix}-github-com-minio-operator-pkg-apis-minio-min-io-v2-customcertificates"]
Expand Down Expand Up @@ -454,6 +444,10 @@ Pool (`pools`) defines a MinIO server pool on a Tenant. Each pool consists of a
|*Optional* +
If provided, each pod on the Statefulset will run with the specified RuntimeClassName, for more info https://kubernetes.io/docs/concepts/containers/runtime-class/

|*`reclaimStorage`* __boolean__
|*Optional* +
If true. Will delete the storage when tenant has been deleted.

|===


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 @@ -2768,6 +2768,8 @@ spec:
additionalProperties:
type: string
type: object
reclaimStorage:
type: boolean
resources:
properties:
claims:
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 storage when tenant has been deleted.
// +optional
ReclaimStorage *bool `json:"reclaimStorage,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 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()))
}
}
}
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"
// ReclaimStorageLabel - pvc with this label and the value is `true` means when tenant is being deleted the pvc will be deleted.
ReclaimStorageLabel = "reclaimStorage"
)

// 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.ReclaimStorage != nil && *pool.ReclaimStorage {
if len(pvClaim.Labels) == 0 {
pvClaim.Labels = make(map[string]string)
}
pvClaim.Labels[ReclaimStorageLabel] = "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 @@ -2768,6 +2768,8 @@ spec:
additionalProperties:
type: string
type: object
reclaimStorage:
type: boolean
resources:
properties:
claims:
Expand Down