Skip to content

Commit

Permalink
controllers: create VRCs
Browse files Browse the repository at this point in the history
Signed-off-by: raaizik <[email protected]>
  • Loading branch information
raaizik committed Jul 28, 2024
1 parent e9adefa commit 626d539
Show file tree
Hide file tree
Showing 21 changed files with 3,387 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ rules:
- list
- update
- watch
- apiGroups:
- ramendr.openshift.io
resources:
- drclusterconfigs
verbs:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ toolchain go1.22.3

replace (
github.com/portworx/sched-ops => github.com/portworx/sched-ops v0.20.4-openstorage-rc3 // required by Rook v1.12
k8s.io/client-go v12.0.0+incompatible => k8s.io/client-go v0.29.0
vbom.ml/util => github.com/fvbommel/util v0.0.0-20180919145318-efcd4e0f9787
)

exclude github.com/kubernetes-incubator/external-storage v0.20.4-openstorage-rc2

require (
github.com/csi-addons/kubernetes-csi-addons v0.8.0
github.com/go-logr/logr v1.4.1
github.com/kubernetes-csi/external-snapshotter/client/v6 v6.3.0
github.com/onsi/ginkgo v1.16.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/csi-addons/kubernetes-csi-addons v0.8.0 h1:zvYGp4DM6KdQzEX3dQSYKykqJdLZlxpVBJjtpbaqFjs=
github.com/csi-addons/kubernetes-csi-addons v0.8.0/go.mod h1:dvinzoiXlqdOGDpKkYx8Jxl507BzVEEEO+SI0OmBaRI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down
41 changes: 41 additions & 0 deletions internal/controller/storageclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"context"
"encoding/json"
"fmt"
"k8s.io/apimachinery/pkg/types"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"slices"
"strings"
"time"
Expand All @@ -29,8 +32,10 @@ import (
"github.com/red-hat-storage/ocs-client-operator/pkg/csi"
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"

replicationv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/apis/replication.storage/v1alpha1"
"github.com/go-logr/logr"
snapapi "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
ramenv1alpha1 "github.com/ramendr/ramen/api/v1alpha1"
providerclient "github.com/red-hat-storage/ocs-operator/v4/services/provider/client"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
Expand Down Expand Up @@ -104,8 +109,43 @@ func (r *StorageClaimReconciler) SetupWithManager(mgr ctrl.Manager) error {
return fmt.Errorf("unable to set up FieldIndexer for VSC csi driver name: %v", err)
}

enqueueVolumeReplicationClass := handler.EnqueueRequestsFromMapFunc(
func(context context.Context, obj client.Object) []reconcile.Request {
vrcs := &replicationv1alpha1.VolumeReplicationClassList{}
err := r.Client.List(context, vrcs, &client.ListOptions{Namespace: obj.GetNamespace()})
if err != nil {
r.log.Error(err, "Unable to list VolumeReplicationClass objects")
return []reconcile.Request{}
}

// Return name and namespace of the VolumeReplicationClass object
request := []reconcile.Request{}
for _, vrc := range vrcs.Items {
request = append(request, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: vrc.Namespace,
Name: vrc.Name,
},
})
}
return request
},
)

drClusterConfigPredicate := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
if e.ObjectOld == nil || e.ObjectNew == nil {
return false
}
oldObj := e.ObjectOld.(*ramenv1alpha1.DRClusterConfig)
newObj := e.ObjectNew.(*ramenv1alpha1.DRClusterConfig)
return !reflect.DeepEqual(oldObj.Spec, newObj.Spec)
},
}
return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.StorageClaim{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&ramenv1alpha1.DRClusterConfig{}, enqueueVolumeReplicationClass,
builder.WithPredicates(drClusterConfigPredicate)).
Owns(&storagev1.StorageClass{}).
Owns(&snapapi.VolumeSnapshotClass{}).
Complete(r)
Expand All @@ -119,6 +159,7 @@ func (r *StorageClaimReconciler) SetupWithManager(mgr ctrl.Manager) error {
//+kubebuilder:rbac:groups=snapshot.storage.k8s.io,resources=volumesnapshotclasses,verbs=get;list;watch;create;delete
//+kubebuilder:rbac:groups=core,resources=persistentvolumes,verbs=get;list;watch
//+kubebuilder:rbac:groups=snapshot.storage.k8s.io,resources=volumesnapshotcontents,verbs=get;list;watch
//+kubebuilder:rbac:groups=ramendr.openshift.io,resources=drclusterconfigs,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.
Expand Down
202 changes: 202 additions & 0 deletions vendor/github.com/csi-addons/kubernetes-csi-addons/LICENSE

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

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

Loading

0 comments on commit 626d539

Please sign in to comment.