Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webhook): add cspc expansion validations #46

Merged
merged 4 commits into from
May 5, 2020

Conversation

shubham14bajpai
Copy link
Contributor

@shubham14bajpai shubham14bajpai commented Apr 27, 2020

Signed-off-by: shubham [email protected]

This PR adds webhook validations for cspc expansion.

Refer: openebs-archive/maya#1588

TODO:
add unit test for new functions

Copy link
Contributor

@mittachaitu mittachaitu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided comments mostly related to WriteCacheRaidGroups... and What about the test cases?

pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
newRaidGroups: []cstor.RaidGroup{},
}
// build raidGroups by identifying common raidGroups in old and new
for _, oldRg := range oldPoolSpec.DataRaidGroups {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to get raid groups of WriteCacheRaidGroups
lly in other places also we need to check the repetition of blockdevices in writeCacheRaidGroup in getDuplicateBlockDeviceList function.

pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mittachaitu mittachaitu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided comments

pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
for _, newRg := range newPoolSpec.WriteCacheRaidGroups {
if IsRaidGroupCommon(oldRg, newRg) {
isRaidGroupExist = true
rgs["data"].oldRaidGroups = append(rgs["data"].oldRaidGroups, oldRg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key should be writeCache in other places also

// 2.2 Validate changes for blockdevice replacement scenarios(openebs/openebs#2846).
// 3. Validate vertical pool expansions if there are any new raidgroups or blockdevices added.
func (pOps *PoolOperations) ArePoolSpecChangesValid(oldPoolSpec, newPoolSpec *cstor.PoolSpec) (bool, string) {
newToOldBd := make(map[string]string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add one check for raidGroupType also

if oldPoolSpec.PoolConfig.DataRaidGroupType != newPoolSpec.PoolConfig.DataRaidGroupType || oldPoolSpec.PoolConfig.WriteCacheRaidGroupType != newPoolSpec.PoolConfig.WriteCacheRaidGroupType {
return false, fmt.Sprintf("raidgroup can't be modified")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubham14bajpai sorry for bad reviews above check should be updated because there might be chances that user can add writecache raidgroup after pool creation at that time we need to allow expansion

if oldPoolSpec.PoolConfig.DataRaidGroupType != newPoolSpec.PoolConfig.DataRaidGroupType || (oldPoolSpec.PoolConfig.WriteCacheRaidGroupType != "" && oldPoolSpec.PoolConfig.WriteCacheRaidGroupType != newPoolSpec.PoolConfig.WriteCacheRaidGroupType) {
return false, fmt.Sprintf("raidgroup can't be modified")
}

_, ok := bdcObject.GetAnnotations()[types.PredecessorBDLabelKey]
if ok {
return true, errors.Errorf("replacement is still in progress for bd %s", v.BlockDeviceName)
if bdcObject != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be improved by returning a typed error -- like BDC does not exists.
And BDC does not exist -- should be done instead.
Philosophy is -- if err is nil -- object should be not nil -- code looks more cleaner.
Commenting for tracking. It can be enhanced in a new PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyways -- thanks. Nice Catch.

pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
// in stripe only block devices are added). Following are the validations:
// 1. New blockdevice shouldn't be claimed by any other CSPC (or) third party.
// 2. New blockdevice shouldn't be the replacing blockdevice.
func (pOps *PoolOperations) validatePoolExpansion(
Copy link
Contributor

@mittachaitu mittachaitu Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func (pOps *PoolOperations) validatePoolExpansion(
newPoolSpec *cstor.PoolSpec, commonRaidGroups map[string]*raidGroups) {
var bds []string 
for _, rgs := range commonRaidGroups {
   if rgs.rgType == "stripe" {
       bds = append(bds, getNewBDsFromStripeSpec(rgs.oldRaidGroups[0],
			rgs.newRaidGroups[0]))
   } else {
          newRgs := getExpandedRaidGroups(newPoolSpec, rgs.oldRaidGroups)
          bds = getBDsFromRaidGroups(newRgs)
      }
}
  err := pOps.validateNewBDs(bds, pOps.NewCSPC)
	if err != nil {
		return err
	}
	return nil
}

Check will above fit into it by considering caller code comment also

// 2.2 Validate changes for blockdevice replacement scenarios(openebs/openebs#2846).
// 3. Validate vertical pool expansions if there are any new raidgroups or blockdevices added.
func (pOps *PoolOperations) ArePoolSpecChangesValid(oldPoolSpec, newPoolSpec *cstor.PoolSpec) (bool, string) {
newToOldBd := make(map[string]string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubham14bajpai sorry for bad reviews above check should be updated because there might be chances that user can add writecache raidgroup after pool creation at that time we need to allow expansion

if oldPoolSpec.PoolConfig.DataRaidGroupType != newPoolSpec.PoolConfig.DataRaidGroupType || (oldPoolSpec.PoolConfig.WriteCacheRaidGroupType != "" && oldPoolSpec.PoolConfig.WriteCacheRaidGroupType != newPoolSpec.PoolConfig.WriteCacheRaidGroupType) {
return false, fmt.Sprintf("raidgroup can't be modified")
}

pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
pkg/webhook/cspc_operations.go Show resolved Hide resolved
pkg/webhook/cspc_operations.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mittachaitu mittachaitu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are good

Copy link
Contributor

@sonasingh46 sonasingh46 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants