From d3dde7262367763502c845fa7b5abde08f87d712 Mon Sep 17 00:00:00 2001 From: raaizik <132667934+raaizik@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:25:35 +0300 Subject: [PATCH] controllers: create VRCs - Creates VolRepClass in response to changes made to DRClusterConfig - k8s csi addons bump Signed-off-by: raaizik <132667934+raaizik@users.noreply.github.com> --- ...client-operator.clusterserviceversion.yaml | 9 +- config/rbac/role.yaml | 9 +- go.mod | 9 +- go.sum | 8 +- .../controller/storageclaim_controller.go | 5 +- pkg/utils/k8sutils.go | 19 ++-- .../ramen/api/v1alpha1/drpolicy_types.go | 47 ++++++++++ .../v1alpha1/volumereplicationgroup_types.go | 16 +++- .../api/v1alpha1/zz_generated.deepcopy.go | 87 ++++++++++++++++++- vendor/modules.txt | 7 +- 10 files changed, 189 insertions(+), 27 deletions(-) diff --git a/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml b/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml index cb09d8e5..a7252dfc 100644 --- a/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml +++ b/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml @@ -329,11 +329,18 @@ spec: resources: - maintenancemodes verbs: + - get + - list + - watch + - apiGroups: + - replication.storage.openshift.io + resources: + - volumereplicationclass + verbs: - create - delete - get - list - - update - watch - apiGroups: - ramendr.openshift.io diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 042fa8a8..e41efc3e 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -286,11 +286,18 @@ rules: resources: - maintenancemodes verbs: + - get + - list + - watch +- apiGroups: + - replication.storage.openshift.io + resources: + - volumereplicationclass + verbs: - create - delete - get - list - - update - watch - apiGroups: - ramendr.openshift.io diff --git a/go.mod b/go.mod index a9e2eef8..05ee04dd 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.22.7 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 ) @@ -18,7 +19,7 @@ exclude ( ) require ( - github.com/ceph/ceph-csi-operator/api v0.0.0-20241114115439-f325f74205d3 + github.com/ceph/ceph-csi-operator/api v0.0.0-20241119082218-62dc94e55c32 github.com/csi-addons/kubernetes-csi-addons v0.10.0 github.com/go-logr/logr v1.4.2 github.com/kubernetes-csi/external-snapshotter/client/v8 v8.0.0 @@ -26,12 +27,14 @@ require ( github.com/onsi/gomega v1.34.2 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/ramendr/ramen/api v0.0.0-20241105140706-d8587766acb3 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-20241120160011-2e7cf0127dd4 github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.68.0 + gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/api v0.31.1 k8s.io/apiextensions-apiserver v0.31.0 k8s.io/apimachinery v0.31.1 @@ -46,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 ) diff --git a/go.sum b/go.sum index 33ea437d..01b6ba04 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r 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/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/ceph/ceph-csi-operator/api v0.0.0-20241114115439-f325f74205d3 h1:ft8h5V7BfQqIGJAyiTvn6x86Oi/yMs8yqW7rfKvN9SQ= -github.com/ceph/ceph-csi-operator/api v0.0.0-20241114115439-f325f74205d3/go.mod h1:odEUoarG26wXBCC2l4O4nMWhAz6VTKr2FRkv9yELgi8= +github.com/ceph/ceph-csi-operator/api v0.0.0-20241119082218-62dc94e55c32 h1:IawGJ9fPalvY77XtDElI4ZoVfU5aLnEKL3kwWBn3YEA= +github.com/ceph/ceph-csi-operator/api v0.0.0-20241119082218-62dc94e55c32/go.mod h1:odEUoarG26wXBCC2l4O4nMWhAz6VTKr2FRkv9yELgi8= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -325,8 +325,8 @@ github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVho github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237 h1:ig6ePD0yopC5Qi5BRmhsIsKaOkdsGXTSmG3HTYIpquo= -github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237/go.mod h1:nO6VM/+PEhcPGyFIQJdhY6ip822cA61PAy/s6IjenAA= +github.com/ramendr/ramen/api v0.0.0-20241105140706-d8587766acb3 h1:q4UjNvv3jzKOeG/S+S1Ms2FV3WajBIE6266/7BIxdX4= +github.com/ramendr/ramen/api v0.0.0-20241105140706-d8587766acb3/go.mod h1:O7VpTy8MMrh31DF4fv+2SZBSouAr8NlzIY4KYx7K75U= github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241120160011-2e7cf0127dd4 h1:ppE7R+yh9I2PZuGPaUDdwQ45ZFV8YfHFNKccOxTo8tg= github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241120160011-2e7cf0127dd4/go.mod h1:XEZxUtzjlARPV8YvzcX2p7iiRbrUbDP4Q/CXx9ly5lw= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/internal/controller/storageclaim_controller.go b/internal/controller/storageclaim_controller.go index 8ae6172d..8d6ba14e 100644 --- a/internal/controller/storageclaim_controller.go +++ b/internal/controller/storageclaim_controller.go @@ -20,11 +20,12 @@ import ( "context" "encoding/json" "fmt" + "slices" + "strings" + 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" - "slices" - "strings" csiopv1a1 "github.com/ceph/ceph-csi-operator/api/v1alpha1" "github.com/go-logr/logr" diff --git a/pkg/utils/k8sutils.go b/pkg/utils/k8sutils.go index 89cacdb5..1d9b0a04 100644 --- a/pkg/utils/k8sutils.go +++ b/pkg/utils/k8sutils.go @@ -105,15 +105,6 @@ func AddLabel(obj metav1.Object, key string, value string) bool { return false } -func AddAnnotations(obj metav1.Object, newAnnotations map[string]string) { - annotations := obj.GetAnnotations() - if annotations == nil { - annotations = map[string]string{} - obj.SetAnnotations(annotations) - } - maps.Copy(annotations, newAnnotations) -} - // AddAnnotation adds an annotation to a resource metadata, returns true if added else false func AddAnnotation(obj metav1.Object, key string, value string) bool { annotations := obj.GetAnnotations() @@ -128,6 +119,16 @@ func AddAnnotation(obj metav1.Object, key string, value string) bool { return false } +// AddAnnotations adds values from newAnnotations to the keys on the supplied obj or overwrites values for existing keys on the obj +func AddAnnotations(obj metav1.Object, newAnnotations map[string]string) { + annotations := obj.GetAnnotations() + if annotations == nil { + annotations = map[string]string{} + obj.SetAnnotations(annotations) + } + maps.Copy(annotations, newAnnotations) +} + func GetMD5Hash(text string) string { hash := md5.Sum([]byte(text)) return hex.EncodeToString(hash[:]) diff --git a/vendor/github.com/ramendr/ramen/api/v1alpha1/drpolicy_types.go b/vendor/github.com/ramendr/ramen/api/v1alpha1/drpolicy_types.go index b53a0681..6ecac12e 100644 --- a/vendor/github.com/ramendr/ramen/api/v1alpha1/drpolicy_types.go +++ b/vendor/github.com/ramendr/ramen/api/v1alpha1/drpolicy_types.go @@ -54,6 +54,53 @@ type DRPolicySpec struct { // DRPolicyStatus defines the observed state of DRPolicy type DRPolicyStatus struct { Conditions []metav1.Condition `json:"conditions,omitempty"` + + // DRPolicyStatus.Async contains the status of observed + // async replication details between the clusters in the policy + //+optional + Async Async `json:"async,omitempty"` + + // DRPolicyStatus.Sync contains the status of observed + // sync replication details between the clusters in the policy + //+optional + Sync Sync `json:"sync,omitempty"` +} + +// for RDR +type Async struct { + // PeerClasses is a list of common StorageClasses across the clusters in a policy + // that have related async relationships. (one per pair of peers in the policy) + //+optional + PeerClasses []PeerClass `json:"peerClasses,omitempty"` +} + +// for MetroDR +type Sync struct { + // PeerClasses is a list of common StorageClasses across the clusters in a policy + // that have related sync relationships. (one per pair of peers in the policy) + //+optional + PeerClasses []PeerClass `json:"peerClasses,omitempty"` +} + +type PeerClass struct { + // ReplicationID is the common value for the label "ramendr.openshift.io/replicationID" on the corresponding + // VolumeReplicationClass or VolumeGroupReplicationClass on each peer for the matched StorageClassName. + //+optional + ReplicationID string `json:"replicationID,omitempty"` + + // StorageID is the collection of values for the label "ramendr.openshift.io/storageID" on the corresponding + // StorageClassName across the peers. It is singleton if the storage instance is shared across the peers, + // and distict if storage instances are different. + //+optional + StorageID []string `json:"storageID,omitempty"` + + // StorageClassName is the name of a StorageClass that is available across the peers + //+optional + StorageClassName string `json:"storageClassName,omitempty"` + + // ClusterIDs is a list of two clusterIDs that represent this peer relationship for a common StorageClassName + // The IDs are based on the value of the metadata.uid of the kube-system namespace + ClusterIDs []string `json:"clusterIDs,omitempty"` } const ( diff --git a/vendor/github.com/ramendr/ramen/api/v1alpha1/volumereplicationgroup_types.go b/vendor/github.com/ramendr/ramen/api/v1alpha1/volumereplicationgroup_types.go index 96436268..868c2bd2 100644 --- a/vendor/github.com/ramendr/ramen/api/v1alpha1/volumereplicationgroup_types.go +++ b/vendor/github.com/ramendr/ramen/api/v1alpha1/volumereplicationgroup_types.go @@ -62,10 +62,22 @@ type VRGAsyncSpec struct { // +kubebuilder:validation:Required // +kubebuilder:validation:Pattern=`^\d+[mhd]$` SchedulingInterval string `json:"schedulingInterval"` + + // PeerClasses is a list of common StorageClasses across the clusters in a policy that have related + // sync relationships. This is ONLY modified post creation, if the workload that is protected + // creates a PVC using a newer StorageClass that is determined to be common across the peers. + //+optional + PeerClasses []PeerClass `json:"peerClasses,omitempty"` } -// VRGSyncSpec has the parameters associated with MetroDR -type VRGSyncSpec struct{} +// VRGSyncSpec has the parameters associated with VE +type VRGSyncSpec struct { + // PeerClasses is a list of common StorageClasses across the clusters in a policy that have related + // async relationships. This is ONLY modified post creation, if the workload that is protected + // creates a PVC using a newer StorageClass that is determined to be common across the peers. + //+optional + PeerClasses []PeerClass `json:"peerClasses,omitempty"` +} // VolSyncReplicationDestinationSpec defines the configuration for the VolSync // protected PVC to be used by the destination cluster (Secondary) diff --git a/vendor/github.com/ramendr/ramen/api/v1alpha1/zz_generated.deepcopy.go b/vendor/github.com/ramendr/ramen/api/v1alpha1/zz_generated.deepcopy.go index 59059ff6..687a5ccb 100644 --- a/vendor/github.com/ramendr/ramen/api/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/github.com/ramendr/ramen/api/v1alpha1/zz_generated.deepcopy.go @@ -14,6 +14,28 @@ import ( configv1alpha1 "k8s.io/component-base/config/v1alpha1" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Async) DeepCopyInto(out *Async) { + *out = *in + if in.PeerClasses != nil { + in, out := &in.PeerClasses, &out.PeerClasses + *out = make([]PeerClass, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Async. +func (in *Async) DeepCopy() *Async { + if in == nil { + return nil + } + out := new(Async) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterMaintenanceMode) DeepCopyInto(out *ClusterMaintenanceMode) { *out = *in @@ -506,6 +528,8 @@ func (in *DRPolicyStatus) DeepCopyInto(out *DRPolicyStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + in.Async.DeepCopyInto(&out.Async) + in.Sync.DeepCopyInto(&out.Sync) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DRPolicyStatus. @@ -722,6 +746,31 @@ func (in *MaintenanceModeStatus) DeepCopy() *MaintenanceModeStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PeerClass) DeepCopyInto(out *PeerClass) { + *out = *in + if in.StorageID != nil { + in, out := &in.StorageID, &out.StorageID + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.ClusterIDs != nil { + in, out := &in.ClusterIDs, &out.ClusterIDs + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeerClass. +func (in *PeerClass) DeepCopy() *PeerClass { + if in == nil { + return nil + } + out := new(PeerClass) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PlacementDecision) DeepCopyInto(out *PlacementDecision) { *out = *in @@ -1302,12 +1351,41 @@ func (in *StorageIdentifiers) DeepCopy() *StorageIdentifiers { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Sync) DeepCopyInto(out *Sync) { + *out = *in + if in.PeerClasses != nil { + in, out := &in.PeerClasses, &out.PeerClasses + *out = make([]PeerClass, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Sync. +func (in *Sync) DeepCopy() *Sync { + if in == nil { + return nil + } + out := new(Sync) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VRGAsyncSpec) DeepCopyInto(out *VRGAsyncSpec) { *out = *in in.ReplicationClassSelector.DeepCopyInto(&out.ReplicationClassSelector) in.VolumeSnapshotClassSelector.DeepCopyInto(&out.VolumeSnapshotClassSelector) in.VolumeGroupSnapshotClassSelector.DeepCopyInto(&out.VolumeGroupSnapshotClassSelector) + if in.PeerClasses != nil { + in, out := &in.PeerClasses, &out.PeerClasses + *out = make([]PeerClass, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VRGAsyncSpec. @@ -1366,6 +1444,13 @@ func (in *VRGResourceMeta) DeepCopy() *VRGResourceMeta { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VRGSyncSpec) DeepCopyInto(out *VRGSyncSpec) { *out = *in + if in.PeerClasses != nil { + in, out := &in.PeerClasses, &out.PeerClasses + *out = make([]PeerClass, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VRGSyncSpec. @@ -1508,7 +1593,7 @@ func (in *VolumeReplicationGroupSpec) DeepCopyInto(out *VolumeReplicationGroupSp if in.Sync != nil { in, out := &in.Sync, &out.Sync *out = new(VRGSyncSpec) - **out = **in + (*in).DeepCopyInto(*out) } in.VolSync.DeepCopyInto(&out.VolSync) if in.KubeObjectProtection != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 99ef1708..5d56e503 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,7 +4,7 @@ github.com/beorn7/perks/quantile # github.com/blang/semver/v4 v4.0.0 ## explicit; go 1.14 github.com/blang/semver/v4 -# github.com/ceph/ceph-csi-operator/api v0.0.0-20241114115439-f325f74205d3 +# github.com/ceph/ceph-csi-operator/api v0.0.0-20241119082218-62dc94e55c32 ## explicit; go 1.22.0 github.com/ceph/ceph-csi-operator/api/v1alpha1 # github.com/cespare/xxhash/v2 v2.3.0 @@ -213,8 +213,8 @@ github.com/prometheus/common/model github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237 -## explicit; go 1.22.0 +# github.com/ramendr/ramen/api v0.0.0-20241105140706-d8587766acb3 +## explicit; go 1.22.5 github.com/ramendr/ramen/api/v1alpha1 # github.com/red-hat-storage/ocs-client-operator/api v0.0.0-00010101000000-000000000000 => ./api ## explicit; go 1.22.5 @@ -928,4 +928,5 @@ sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 # github.com/portworx/sched-ops => github.com/portworx/sched-ops v0.20.4-openstorage-rc3 # 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