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 Nov 5, 2024
1 parent 64a0317 commit 66dca4f
Show file tree
Hide file tree
Showing 10 changed files with 730 additions and 6 deletions.
3 changes: 0 additions & 3 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,8 @@ rules:
resources:
- drclusterconfigs
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- security.openshift.io
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.5
replace (
github.com/portworx/sched-ops => github.com/portworx/sched-ops v0.20.4-openstorage-rc3 // required by Rook v1.12
github.com/red-hat-storage/ocs-client-operator/api => ./api
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
)

Expand All @@ -19,18 +20,21 @@ exclude (

require (
github.com/ceph/ceph-csi-operator/api v0.0.0-20240812072523-4d50cf3a32a0
github.com/csi-addons/kubernetes-csi-addons v0.8.0
github.com/go-logr/logr v1.4.2
github.com/kubernetes-csi/external-snapshotter/client/v6 v6.3.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.34.1
github.com/openshift/api v0.0.0-20240828125535-01b3675ba7b3
github.com/operator-framework/api v0.27.0
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.76.0
github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237
github.com/red-hat-storage/ocs-client-operator/api v0.0.0-00010101000000-000000000000
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241015071140-98c8184c6eec
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.66.0
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.31.0
k8s.io/apiextensions-apiserver v0.31.0
k8s.io/apimachinery v0.31.0
Expand All @@ -45,10 +49,8 @@ require (
github.com/klauspost/compress v1.17.9 // indirect
github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20221122204822-d1a8c34382f1 // indirect
github.com/openshift/custom-resource-status v1.1.3-0.20220503160415-f2fdb4999d87 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/component-base v0.31.0 // indirect
sigs.k8s.io/container-object-storage-interface-api v0.1.0 // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
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: 40 additions & 1 deletion internal/controller/storageclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ import (
"strings"
"time"

"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/event"

v1alpha1 "github.com/red-hat-storage/ocs-client-operator/api/v1alpha1"
"github.com/red-hat-storage/ocs-client-operator/pkg/templates"
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"

csiopv1a1 "github.com/ceph/ceph-csi-operator/api/v1alpha1"
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"
Expand Down Expand Up @@ -112,6 +116,39 @@ 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.ReplicationSchedules, newObj.Spec.ReplicationSchedules)
},
}
generationChangePredicate := predicate.GenerationChangedPredicate{}
bldr := ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.StorageClaim{}, builder.WithPredicates(generationChangePredicate)).
Expand All @@ -129,7 +166,8 @@ func (r *StorageClaimReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&csiopv1a1.ClientProfile{}, builder.WithPredicates(generationChangePredicate))

if r.AvailableCrds[drClusterConfigCRDName] {
bldr = bldr.Owns(&ramenv1alpha1.DRClusterConfig{}, builder.WithPredicates(generationChangePredicate))
bldr = bldr.Watches(&ramenv1alpha1.DRClusterConfig{}, enqueueVolumeReplicationClass,
builder.WithPredicates(drClusterConfigPredicate))
}

return bldr.Complete(r)
Expand All @@ -143,6 +181,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
//+kubebuilder:rbac:groups=csi.ceph.io,resources=clientprofiles,verbs=get;list;update;create;watch;delete
//+kubebuilder:rbac:groups=ramendr.openshift.io,resources=drclusterconfigs,verbs=get;list;update;create;watch;delete

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 66dca4f

Please sign in to comment.