diff --git a/pkg/base/k8s/kubeclient.go b/pkg/base/k8s/kubeclient.go index 79fbdbd6e..badc89451 100644 --- a/pkg/base/k8s/kubeclient.go +++ b/pkg/base/k8s/kubeclient.go @@ -228,7 +228,7 @@ func (k *KubeClient) ConstructACRCR(name string, apiACR api.AvailableCapacityRes // ConstructLVGCR constructs LogicalVolumeGroup custom resource from api.LogicalVolumeGroup struct // Receives a name for k8s ObjectMeta and an instance of api.LogicalVolumeGroup struct // Returns an instance of LogicalVolumeGroup CR struct -func (k *KubeClient) ConstructLVGCR(name string, apiLVG api.LogicalVolumeGroup) *lvgcrd.LogicalVolumeGroup { +func (k *KubeClient) ConstructLVGCR(name string, apiLVG api.LogicalVolumeGroup, storageGroup string) *lvgcrd.LogicalVolumeGroup { return &lvgcrd.LogicalVolumeGroup{ TypeMeta: apisV1.TypeMeta{ Kind: crdV1.LVGKind, @@ -236,7 +236,7 @@ func (k *KubeClient) ConstructLVGCR(name string, apiLVG api.LogicalVolumeGroup) }, ObjectMeta: apisV1.ObjectMeta{ Name: name, - Labels: constructDefaultAppMap(), + Labels: constructLVGCRLabels(storageGroup), }, Spec: apiLVG, } @@ -427,3 +427,11 @@ func constructDefaultAppMap() (labels map[string]string) { } return } + +func constructLVGCRLabels(storageGroup string) (labels map[string]string) { + labels = constructDefaultAppMap() + if storageGroup != "" { + labels[crdV1.StorageGroupLabelKey] = storageGroup + } + return labels +} diff --git a/pkg/base/k8s/kubeclient_test.go b/pkg/base/k8s/kubeclient_test.go index 659d4bb07..2b4034d02 100644 --- a/pkg/base/k8s/kubeclient_test.go +++ b/pkg/base/k8s/kubeclient_test.go @@ -496,7 +496,7 @@ var _ = Describe("Constructor methods", func() { }) Context("ConstructLVGCR", func() { It("Should return right LogicalVolumeGroup CR", func() { - constructedCR := k8sclient.ConstructLVGCR(testLVGName, testApiLVG) + constructedCR := k8sclient.ConstructLVGCR(testLVGName, testApiLVG, "") Expect(constructedCR.TypeMeta.Kind).To(Equal(testLVGCR.TypeMeta.Kind)) Expect(constructedCR.TypeMeta.APIVersion).To(Equal(testLVGCR.TypeMeta.APIVersion)) Expect(constructedCR.ObjectMeta.Name).To(Equal(testLVGCR.ObjectMeta.Name)) diff --git a/pkg/common/ac_operations.go b/pkg/common/ac_operations.go index 747907349..6fae2e78f 100644 --- a/pkg/common/ac_operations.go +++ b/pkg/common/ac_operations.go @@ -33,7 +33,7 @@ import ( // AvailableCapacityOperations is the interface for interact with AvailableCapacity CRs from Controller type AvailableCapacityOperations interface { - RecreateACToLVGSC(ctx context.Context, sc string, acs ...accrd.AvailableCapacity) *accrd.AvailableCapacity + RecreateACToLVGSC(ctx context.Context, sc string, sg string, acs ...accrd.AvailableCapacity) *accrd.AvailableCapacity } // ACOperationsImpl is the basic implementation of AvailableCapacityOperations interface @@ -56,7 +56,7 @@ func NewACOperationsImpl(k8sClient *k8s.KubeClient, l *logrus.Logger) *ACOperati // Concerts first AC to LVG SC and set size of remaining to 0 // Receives newSC as string (e.g. HDDLVG) and AvailableCapacities where LVG should be based // Returns created AC or nil -func (a *ACOperationsImpl) RecreateACToLVGSC(ctx context.Context, newSC string, +func (a *ACOperationsImpl) RecreateACToLVGSC(ctx context.Context, newSC string, storageGroup string, acs ...accrd.AvailableCapacity) *accrd.AvailableCapacity { ll := a.log.WithFields(logrus.Fields{ "method": "RecreateACToLVGSC", @@ -90,7 +90,7 @@ func (a *ACOperationsImpl) RecreateACToLVGSC(ctx context.Context, newSC string, ) // create LVG CR based on ACs - lvg := a.k8sClient.ConstructLVGCR(name, apiLVG) + lvg := a.k8sClient.ConstructLVGCR(name, apiLVG, storageGroup) if err = a.k8sClient.CreateCR(ctx, name, lvg); err != nil { ll.Errorf("Unable to create LVG CR: %v", err) return nil diff --git a/pkg/common/volume_operations.go b/pkg/common/volume_operations.go index 532fee40e..8784485bd 100644 --- a/pkg/common/volume_operations.go +++ b/pkg/common/volume_operations.go @@ -187,7 +187,7 @@ func (vo *VolumeOperationsImpl) handleVolumeCreation(ctx context.Context, log *l if ac.Spec.StorageClass != v.StorageClass && util.IsStorageClassLVG(v.StorageClass) { // AC needs to be converted to LogicalVolumeGroup AC, LogicalVolumeGroup doesn't exist yet - if ac = vo.acProvider.RecreateACToLVGSC(ctx, v.StorageClass, *ac); ac == nil { + if ac = vo.acProvider.RecreateACToLVGSC(ctx, v.StorageClass, ac.Labels[apiV1.StorageGroupLabelKey], *ac); ac == nil { return nil, status.Errorf(codes.Internal, "unable to prepare underlying storage for storage class %s", v.StorageClass) } diff --git a/pkg/node/volumemgr.go b/pkg/node/volumemgr.go index f0e878dc3..63d857454 100644 --- a/pkg/node/volumemgr.go +++ b/pkg/node/volumemgr.go @@ -913,7 +913,7 @@ func (m *VolumeManager) discoverLVGOnSystemDrive() error { VolumeRefs: lvs, Health: apiV1.HealthGood, } - vgCR = m.k8sClient.ConstructLVGCR(vgCRName, vg) + vgCR = m.k8sClient.ConstructLVGCR(vgCRName, vg, "") ctx = context.WithValue(context.Background(), base.RequestUUID, vg.Name) ) m.updateLVGAnnotation(vgCR, vgFreeSpace) diff --git a/pkg/node/volumemgr_test.go b/pkg/node/volumemgr_test.go index f0101fae1..8438c7f50 100644 --- a/pkg/node/volumemgr_test.go +++ b/pkg/node/volumemgr_test.go @@ -962,7 +962,7 @@ func Test_discoverLVGOnSystemDrive_LVGAlreadyExists(t *testing.T) { Name: "some-name", Node: m.nodeID, Locations: []string{"some-uuid"}, - }) + }, "") lvgList = lvgcrd.LogicalVolumeGroupList{} err error )