Skip to content

Commit

Permalink
remove sync storage-group label from drive to AC in capacitycontroller
Browse files Browse the repository at this point in the history
Signed-off-by: Shi, Crane <crane.shi@emc.com>
  • Loading branch information
CraneShiEMC committed May 5, 2023
1 parent 09f9f3b commit 7d57051
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
27 changes: 7 additions & 20 deletions pkg/controller/capacitycontroller/capacitycontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,15 @@ func (d *Controller) reconcileDrive(ctx context.Context, drive *drivecrd.Drive)
usage != apiV1.DriveUsageInUse:
return d.handleInaccessibleDrive(ctx, drive.Spec)
default:
return d.createOrUpdateCapacity(ctx, drive)
return d.createOrUpdateCapacity(ctx, drive.Spec)
}
}

// createOrUpdateCapacity tries to create AC for drive or update its size if AC already exists
func (d *Controller) createOrUpdateCapacity(ctx context.Context, driveObj *drivecrd.Drive) (ctrl.Result, error) {
func (d *Controller) createOrUpdateCapacity(ctx context.Context, drive api.Drive) (ctrl.Result, error) {
log := d.log.WithFields(logrus.Fields{
"method": "createOrUpdateCapacity",
})
log.Debugf("createOrUpdateCapacity for corresponding Drive: %v", driveObj)
drive := driveObj.Spec
driveUUID := drive.GetUUID()
size := drive.GetSize()
// if drive is not clean, size is 0
Expand All @@ -152,17 +150,9 @@ func (d *Controller) createOrUpdateCapacity(ctx context.Context, driveObj *drive
ac, err := d.cachedCrHelper.GetACByLocation(driveUUID)
switch {
case err == nil:
// If the corresponding ac exists, sync drive's size or storage group label to its corresponding AC if necessary
if ac.Spec.Size != size || ac.Labels[apiV1.StorageGroupLabelKey] != driveObj.Labels[apiV1.StorageGroupLabelKey] {
// If ac is exists, update its size to drive size
if ac.Spec.Size != size {
ac.Spec.Size = size
// TODO need deep-dive of golang map utilization and further refactor if necessary here
if ac.Labels == nil {
ac.Labels = make(map[string]string)
}
ac.Labels[apiV1.StorageGroupLabelKey] = driveObj.Labels[apiV1.StorageGroupLabelKey]
if ac.Labels[apiV1.StorageGroupLabelKey] == "" {
delete(ac.Labels, apiV1.StorageGroupLabelKey)
}
if err := d.client.Update(context.WithValue(ctx, base.RequestUUID, ac.Name), ac); err != nil {
log.Errorf("Error during update AvailableCapacity request to k8s: %v, error: %v", ac, err)
return ctrl.Result{}, err
Expand Down Expand Up @@ -308,7 +298,7 @@ func (d *Controller) filterUpdateEvent(old runtime.Object, new runtime.Object) b
return handleLVGObjects(old, new)
}
if newDrive, ok = new.(*drivecrd.Drive); ok {
return filter(oldDrive, newDrive)
return filter(oldDrive.Spec, newDrive.Spec)
}
return true
}
Expand All @@ -328,15 +318,12 @@ func handleLVGObjects(old runtime.Object, new runtime.Object) bool {
return false
}

func filter(oldDrive *drivecrd.Drive, newDrive *drivecrd.Drive) bool {
func filter(old api.Drive, new api.Drive) bool {
// controller perform reconcile for drives, which have different statuses, health or isClean field.
// Another drives are skipped
old := oldDrive.Spec
new := newDrive.Spec
return old.GetIsClean() != new.GetIsClean() ||
old.GetStatus() != new.GetStatus() ||
old.GetHealth() != new.GetHealth() ||
oldDrive.Labels[apiV1.StorageGroupLabelKey] != newDrive.Labels[apiV1.StorageGroupLabelKey]
old.GetHealth() != new.GetHealth()
}

func filterLVG(old *lvgcrd.LogicalVolumeGroup, new *lvgcrd.LogicalVolumeGroup) bool {
Expand Down
4 changes: 1 addition & 3 deletions pkg/controller/capacitycontroller/capacitycontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ var (
APIVersion: apiV1.APIV1Version,
},
ObjectMeta: v1.ObjectMeta{
Name: drive1UUID,
Labels: make(map[string]string),
Name: drive1UUID,
},
Spec: apiDrive1,
}
Expand Down Expand Up @@ -104,7 +103,6 @@ var (
ObjectMeta: v1.ObjectMeta{
Name: acCRName,
Namespace: ns,
Labels: make(map[string]string),
},
Spec: acSpec,
}
Expand Down

0 comments on commit 7d57051

Please sign in to comment.