Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions internal/controller/cephfscg/cghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type VSCGHandler interface {

CreateOrUpdateReplicationGroupSource(
replicationGroupSourceNamespace string,
storageClassName string,
runFinalSync bool,
) (*ramendrv1alpha1.ReplicationGroupSource, bool, error)

Expand Down Expand Up @@ -154,6 +155,7 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupDestination(
//nolint:funlen,gocognit,cyclop,gocyclo
func (c *cgHandler) CreateOrUpdateReplicationGroupSource(
replicationGroupSourceNamespace string,
storageClassName string,
runFinalSync bool,
) (*ramendrv1alpha1.ReplicationGroupSource, bool, error) {
replicationGroupSourceName := c.cgName
Expand Down Expand Up @@ -198,13 +200,8 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupSource(
return nil, !finalSyncComplete, err
}

namespaces := []string{c.instance.Namespace}
if c.instance.Spec.ProtectedNamespaces != nil && len(*c.instance.Spec.ProtectedNamespaces) != 0 {
namespaces = *c.instance.Spec.ProtectedNamespaces
}

volumeGroupSnapshotClassName, err := util.GetVolumeGroupSnapshotClassFromPVCsStorageClass(c.ctx, c.Client,
c.volumeGroupSnapshotClassSelector, *c.volumeGroupSnapshotSource, namespaces, c.logger)
c.volumeGroupSnapshotClassSelector, storageClassName, c.logger)
if err != nil {
log.Error(err, "Failed to get VGSClass name")
// If final sync is requested, ensure final sync cleanup is run regardless of the error
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/cephfscg/cghandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ var _ = Describe("Cghandler", func() {
Async: &ramendrv1alpha1.VRGAsyncSpec{},
},
}, &metav1.LabelSelector{}, nil, rgsName, testLogger)
rgs, finalSync, err := vsCGHandler.CreateOrUpdateReplicationGroupSource("default", false)
rgs, finalSync, err := vsCGHandler.CreateOrUpdateReplicationGroupSource("default", "test", false)
Expect(err).To(BeNil())
Expect(finalSync).To(BeFalse())
Expect(rgs.Spec.Trigger.Schedule).NotTo(BeNil())
Expand Down
44 changes: 11 additions & 33 deletions internal/controller/util/cephfs_cg.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,36 @@ func GetVolumeGroupSnapshotClassFromPVCsStorageClass(
ctx context.Context,
k8sClient client.Client,
volumeGroupSnapshotClassSelector metav1.LabelSelector,
pvcsConsistencyGroupSelector metav1.LabelSelector,
namespace []string,
storageClassName string,
logger logr.Logger,
) (string, error) {
volumeGroupSnapshotClasses, err := GetVolumeGroupSnapshotClasses(ctx, k8sClient, volumeGroupSnapshotClassSelector)
if err != nil {
return "", err
}

pvcs, err := ListPVCsByPVCSelector(ctx, k8sClient, logger, pvcsConsistencyGroupSelector, namespace, false)
if err != nil {
return "", err
}

storageClassProviders := []string{}

for _, pvc := range pvcs.Items {
storageClass := &storagev1.StorageClass{}
storageClass := &storagev1.StorageClass{}

if err := k8sClient.Get(ctx,
types.NamespacedName{Name: *pvc.Spec.StorageClassName},
storageClass,
); err != nil {
return "", err
}

storageClassProviders = append(storageClassProviders, storageClass.Provisioner)
if err := k8sClient.Get(ctx,
types.NamespacedName{Name: storageClassName},
storageClass,
); err != nil {
return "", err
}

var matchedVolumeGroupSnapshotClassName string

for _, volumeGroupSnapshotClass := range volumeGroupSnapshotClasses {
if VolumeGroupSnapshotClassMatchStorageProviders(volumeGroupSnapshotClass, storageClassProviders) {
if storageClass.Provisioner == volumeGroupSnapshotClass.Driver {
matchedVolumeGroupSnapshotClassName = volumeGroupSnapshotClass.Name

break
}
}

if matchedVolumeGroupSnapshotClassName == "" {
noVSCFoundErr := fmt.Errorf("unable to find matching volumegroupsnapshotclass for storage provisioner %s",
storageClassProviders)
storageClass.Provisioner)
logger.Error(noVSCFoundErr, "No VolumeGroupSnapshotClass found")

return "", noVSCFoundErr
Expand Down Expand Up @@ -173,18 +163,6 @@ func GetVolumeGroupSnapshotClasses(
return vgscList.Items, nil
}

func VolumeGroupSnapshotClassMatchStorageProviders(
volumeGroupSnapshotClass groupsnapv1beta1.VolumeGroupSnapshotClass, storageClassProviders []string,
) bool {
for _, storageClassProvider := range storageClassProviders {
if storageClassProvider == volumeGroupSnapshotClass.Driver {
return true
}
}

return false
}

func IsRDExist(rdspec ramendrv1alpha1.VolSyncReplicationDestinationSpec,
rdspecs []ramendrv1alpha1.VolSyncReplicationDestinationSpec,
) bool {
Expand Down
52 changes: 10 additions & 42 deletions internal/controller/util/cephfs_cg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,45 +250,45 @@ var _ = Describe("CephfsCg", func() {
})
Describe("GetVolumeGroupSnapshotClassFromPVCsStorageClass", func() {
It("Should be failed", func() {
CreateSC(SCName, "testProvisioner1")
volumeGroupSnapshotClassName, err := util.GetVolumeGroupSnapshotClassFromPVCsStorageClass(
context.Background(), k8sClient, metav1.LabelSelector{}, metav1.LabelSelector{}, []string{"default"}, testLogger)
context.Background(), k8sClient, metav1.LabelSelector{}, "test", testLogger)
Expect(volumeGroupSnapshotClassName).To(Equal(""))
Expect(err).NotTo(BeNil())
Expect(err.Error()).To(ContainSubstring("unable to find matching volumegroupsnapshotclass for storage provisioner"))
DeleteSC(SCName)
})
Context("There is pvc and storage class", func() {
BeforeEach(func() {
CreateSC(SCName)
CreatePVC(PVCName, SCName)
CreateSC(SCName, "testProvisioner")
})
AfterEach(func() {
DeletePVC(PVCName)
DeleteSC(SCName)
})
It("should be run as expected", func() {
volumeGroupSnapshotClassName, err := util.GetVolumeGroupSnapshotClassFromPVCsStorageClass(
context.Background(), k8sClient,
metav1.LabelSelector{MatchLabels: map[string]string{"test": "testxxxx"}},
metav1.LabelSelector{}, []string{"default"}, testLogger)
"", testLogger)
Expect(volumeGroupSnapshotClassName).To(Equal(""))
Expect(err).NotTo(BeNil())

volumeGroupSnapshotClassName, err = util.GetVolumeGroupSnapshotClassFromPVCsStorageClass(
context.Background(), k8sClient,
metav1.LabelSelector{MatchLabels: map[string]string{"test": "test"}},
metav1.LabelSelector{MatchLabels: map[string]string{"test": "test"}}, []string{"default"}, testLogger)
"testxxxx", testLogger)
Expect(volumeGroupSnapshotClassName).To(Equal(""))
Expect(err).NotTo(BeNil())

volumeGroupSnapshotClassName, err = util.GetVolumeGroupSnapshotClassFromPVCsStorageClass(
context.Background(), k8sClient, metav1.LabelSelector{}, metav1.LabelSelector{}, []string{"default"}, testLogger)
context.Background(), k8sClient, metav1.LabelSelector{}, "test", testLogger)
Expect(volumeGroupSnapshotClassName).To(Equal("vgsc"))
Expect(err).To(BeNil())

volumeGroupSnapshotClassName, err = util.GetVolumeGroupSnapshotClassFromPVCsStorageClass(
context.Background(), k8sClient,
metav1.LabelSelector{MatchLabels: map[string]string{"test": "test"}},
metav1.LabelSelector{MatchLabels: map[string]string{"testpvc": "testpvc"}}, []string{"default"}, testLogger)
"test", testLogger)
Expect(volumeGroupSnapshotClassName).To(Equal("vgsc"))
Expect(err).To(BeNil())
})
Expand All @@ -303,38 +303,6 @@ var _ = Describe("CephfsCg", func() {
})
})
})
Describe("VolumeGroupSnapshotClassMatchStorageProviders", func() {
It("Should be false", func() {
match := util.VolumeGroupSnapshotClassMatchStorageProviders(
groupsnapv1beta1.VolumeGroupSnapshotClass{
Driver: "test",
}, nil,
)
Expect(match).To(BeFalse())
})
It("Should be false", func() {
match := util.VolumeGroupSnapshotClassMatchStorageProviders(
groupsnapv1beta1.VolumeGroupSnapshotClass{
Driver: "test",
}, []string{"test1"},
)
Expect(match).To(BeFalse())
})
It("Should be false", func() {
match := util.VolumeGroupSnapshotClassMatchStorageProviders(
groupsnapv1beta1.VolumeGroupSnapshotClass{}, []string{"test1"},
)
Expect(match).To(BeFalse())
})
It("Should be true", func() {
match := util.VolumeGroupSnapshotClassMatchStorageProviders(
groupsnapv1beta1.VolumeGroupSnapshotClass{
Driver: "test",
}, []string{"test"},
)
Expect(match).To(BeTrue())
})
})

Describe("IsRDExist", func() {
It("Should be false", func() {
Expand Down Expand Up @@ -549,12 +517,12 @@ var (
SCName = "test"
)

func CreateSC(scName string) {
func CreateSC(scName string, provisioner string) {
sc := &storagev1.StorageClass{
ObjectMeta: metav1.ObjectMeta{
Name: scName,
},
Provisioner: "testProvisioner",
Provisioner: provisioner,
}

Eventually(func() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/vrg_volsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (v *VRGInstance) reconcilePVCAsVolSyncPrimary(pvc corev1.PersistentVolumeCl
)

rgs, finalSyncComplete, err := cephfsCGHandler.CreateOrUpdateReplicationGroupSource(
pvc.Namespace, v.instance.Spec.RunFinalSync,
pvc.Namespace, *pvc.Spec.StorageClassName, v.instance.Spec.RunFinalSync,
)
if err != nil {
v.log.Info("Failed to CreateOrUpdateReplicationGroupSource", "err", err)
Expand Down
Loading