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 Aug 26, 2024
1 parent bd029bb commit 38586a8
Show file tree
Hide file tree
Showing 35 changed files with 4,779 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ rules:
- list
- update
- watch
- apiGroups:
- ramendr.openshift.io
resources:
- drclusterconfigs
verbs:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
Expand Down
4 changes: 4 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/ceph/ceph-csi-operator/api v0.0.0-20240807110810-f92ddf7cc527
github.com/go-logr/logr v1.4.1
github.com/kubernetes-csi/external-snapshotter/client/v6 v6.3.0
Expand All @@ -21,6 +23,7 @@ require (
github.com/operator-framework/api v0.22.0
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.72.0
github.com/ramendr/ramen/api v0.0.0-20240726141352-b1af569f057c
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20240422111920-faced96485bc
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.62.1
Expand Down Expand Up @@ -86,6 +89,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.30.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/ceph/ceph-csi-operator/api v0.0.0-20240807110810-f92ddf7cc527 h1:ORTR
github.com/ceph/ceph-csi-operator/api v0.0.0-20240807110810-f92ddf7cc527/go.mod h1:odEUoarG26wXBCC2l4O4nMWhAz6VTKr2FRkv9yELgi8=
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 Expand Up @@ -122,6 +124,8 @@ github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lne
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/ramendr/ramen/api v0.0.0-20240726141352-b1af569f057c h1:xyqg9mYztsSZYWmmr+CvJ2gzPoDiuwCpzM0OA/Xax40=
github.com/ramendr/ramen/api v0.0.0-20240726141352-b1af569f057c/go.mod h1:/g3Jrr9U/itqpRA1NN/bLxSRrKP1ja5U5tfdOtRspGU=
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20240422111920-faced96485bc h1:bV/ttKjR3nn9jIrOSt5UOttDE6iQ6l+bzLEFPWw335M=
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20240422111920-faced96485bc/go.mod h1:e4AElguwRgtyGEW7JtfJvphjYbcYG4hlpvwDYrQFGi8=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
Expand Down Expand Up @@ -254,6 +258,8 @@ k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc=
k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/client-go v0.30.1 h1:uC/Ir6A3R46wdkgCV3vbLyNOYyCJ8oZnjtJGKfytl/Q=
k8s.io/client-go v0.30.1/go.mod h1:wrAqLNs2trwiCH/wxxmT/x3hKVH9PuV0GGW0oDoHVqc=
k8s.io/component-base v0.30.1 h1:bvAtlPh1UrdaZL20D9+sWxsJljMi0QZ3Lmw+kmZAaxQ=
k8s.io/component-base v0.30.1/go.mod h1:e/X9kDiOebwlI41AvBHuWdqFriSRrX50CdwA9TFaHLI=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
Expand Down
43 changes: 43 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,9 +32,11 @@ 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"
csiopv1a1 "github.com/ceph/ceph-csi-operator/api/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 @@ -106,6 +111,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)).
generationChangePredicate := predicate.GenerationChangedPredicate{}

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / bundle-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / bundle-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / bundle-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / bundle-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / bundle-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / catalog-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / catalog-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / catalog-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / catalog-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / catalog-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / operator-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / operator-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / operator-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / operator-build

expected ';', found ':='

Check failure on line 151 in internal/controller/storageclaim_controller.go

View workflow job for this annotation

GitHub Actions / operator-build

expected ';', found ':='
bldr := ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.StorageClaim{}, builder.WithPredicates(generationChangePredicate)).
Expand All @@ -127,6 +169,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

// Reconcile is part of the main kubernetes reconciliation loop which aims to
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.

Loading

0 comments on commit 38586a8

Please sign in to comment.