Skip to content

Commit

Permalink
Revert "Revert syncing storage group label to LVG CR if necessary"
Browse files Browse the repository at this point in the history
This reverts commit 1dd0b14.

Signed-off-by: Shi, Crane <crane.shi@emc.com>
  • Loading branch information
CraneShiEMC committed Jun 26, 2023
1 parent 6c9ec1f commit 44cf129
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
12 changes: 10 additions & 2 deletions pkg/base/k8s/kubeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ 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,
APIVersion: crdV1.APIV1Version,
},
ObjectMeta: apisV1.ObjectMeta{
Name: name,
Labels: constructDefaultAppMap(),
Labels: constructLVGCRLabels(storageGroup),
},
Spec: apiLVG,
}
Expand Down Expand Up @@ -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
}

Check warning on line 435 in pkg/base/k8s/kubeclient.go

View check run for this annotation

Codecov / codecov/patch

pkg/base/k8s/kubeclient.go#L434-L435

Added lines #L434 - L435 were not covered by tests
return labels
}
2 changes: 1 addition & 1 deletion pkg/base/k8s/kubeclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/ac_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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)

Check warning on line 93 in pkg/common/ac_operations.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/ac_operations.go#L93

Added line #L93 was not covered by tests
if err = a.k8sClient.CreateCR(ctx, name, lvg); err != nil {
ll.Errorf("Unable to create LVG CR: %v", err)
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/volume_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check warning on line 190 in pkg/common/volume_operations.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/volume_operations.go#L190

Added line #L190 was not covered by tests
return nil, status.Errorf(codes.Internal,
"unable to prepare underlying storage for storage class %s", v.StorageClass)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/node/volumemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/node/volumemgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 44cf129

Please sign in to comment.