Skip to content

Commit

Permalink
Merge pull request #155 from red-hat-storage/sync_us--main
Browse files Browse the repository at this point in the history
Syncing latest changes from upstream main for kubernetes-csi-addons
  • Loading branch information
openshift-merge-bot[bot] committed Jun 20, 2024
2 parents dbffe27 + 650ffb2 commit 2aaf4b0
Show file tree
Hide file tree
Showing 63 changed files with 887 additions and 725 deletions.
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ rules:
- volumereplications/status
verbs:
- update
- apiGroups:
- storage.k8s.io
resources:
- storageclasses
verbs:
- get
- list
- watch
- apiGroups:
- storage.k8s.io
resources:
Expand Down
15 changes: 15 additions & 0 deletions controllers/csiaddons/persistentvolumeclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/go-logr/logr"
"github.com/robfig/cron/v3"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -68,6 +69,7 @@ const (
//+kubebuilder:rbac:groups=core,resources=persistentvolumeclaims/finalizers,verbs=update
//+kubebuilder:rbac:groups=csiaddons.openshift.io,resources=reclaimspacecronjobs,verbs=get;list;watch;create;delete;update
//+kubebuilder:rbac:groups=core,resources=namespaces,verbs=get;list;watch
//+kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=get;list;watch

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state. This is
Expand Down Expand Up @@ -260,6 +262,7 @@ func (r *PersistentVolumeClaimReconciler) determineScheduleAndRequeue(
if scheduleFound {
return schedule, nil
}

// check for namespace schedule annotation.
// We cannot have a generic solution for all CSI drivers to get the driver
// name from PV and check if driver supports space reclamation or not and
Expand Down Expand Up @@ -294,6 +297,18 @@ func (r *PersistentVolumeClaimReconciler) determineScheduleAndRequeue(
return "", ErrConnNotFoundRequeueNeeded
}

// check for storageclass schedule annotation.
sc := &storagev1.StorageClass{}
err = r.Client.Get(ctx, types.NamespacedName{Name: *pvc.Spec.StorageClassName}, sc)
if err != nil {
logger.Error(err, "Failed to get StorageClass", "StorageClass", *pvc.Spec.StorageClassName)
return "", err
}
schedule, scheduleFound = getScheduleFromAnnotation(logger, sc.Annotations)
if scheduleFound {
return schedule, nil
}

return "", ErrScheduleNotFound
}

Expand Down
8 changes: 8 additions & 0 deletions deploy/controller/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ rules:
- volumereplications/status
verbs:
- update
- apiGroups:
- storage.k8s.io
resources:
- storageclasses
verbs:
- get
- list
- watch
- apiGroups:
- storage.k8s.io
resources:
Expand Down
33 changes: 28 additions & 5 deletions docs/reclaimspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,31 @@ $ kubectl annotate namespace default "reclaimspace.csiaddons.openshift.io/schedu
namespace/default annotated
```

**Note** Please note that the PersistentVolumeClaim annotation takes priority
over Namespace annotation. The kubernetes-csi-addons only generate a
`ReclaimSpaceCronJob` if the annotation exists on the Namespace. If an admin
needs to modify or delete the annotation on the Namespace, they must perform
the same action on all the PersistentVolumeClaims within that Namespace.
**Note** Please note that the PersistentVolumeClaim annotation takes priority over Namespace
annotation. The kubernetes-csi-addons only generate a `ReclaimSpaceCronJob` if the annotation
exists on the Namespace. If an admin needs to modify or delete the annotation on the Namespace,
they must perform the same action on all the PersistentVolumeClaims within that Namespace.

## Annotating StorageClass

You can create `ReclaimSpaceCronJob` CR automatically by adding the
`reclaimspace.csiaddons.openshift.io/schedule: "@midnight"` annotations to the StorageClass object.
This will only affect new PersistentVolumeClaims created from this StorageClass for ReclaimSpace
operations. To include existing PersistentVolumeClaims for ReclaimSpace operations, you must restart
the controller. This will ensure that reclaimspace annotations are added to the existing
PersistentVolumeClaims and `ReclaimSpaceCronJob` resources are created for them.

```console
$ kubectl get storageclass rbd-sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rbd-sc rbd.csi.ceph.com Delete Immediate true 5d2h

$ kubectl annotate storageclass rbd-sc "reclaimspace.csiaddons.openshift.io/schedule=@midnight"
storageclass.storage.k8s.io/rbd-sc annotated
```

**Note** Please note that the PersistentVolumeClaim and Namespace annotation takes priority
over StorageClass annotation. The kubernetes-csi-addons only generate a `ReclaimSpaceCronJob`
if the annotation exists on the StorageClass. If an admin needs to modify or delete the
annotation on the StorageClass, they must perform the same action on all the PersistentVolumeClaims
created from this StorageClass.
8 changes: 4 additions & 4 deletions internal/proto/networkfence.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions internal/proto/reclaimspace.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions internal/proto/replication.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
require (
github.com/operator-framework/operator-sdk v1.34.2
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240102165319-7f316f1309b1
sigs.k8s.io/controller-tools v0.15.0
sigs.k8s.io/kustomize/kustomize/v5 v5.4.2
Expand Down
4 changes: 2 additions & 2 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2aaf4b0

Please sign in to comment.