Skip to content

Commit

Permalink
fix(webhook): check for hostname instead of nodename for bd validatio…
Browse files Browse the repository at this point in the history
…ns (#94)

Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai authored and kmova committed Jun 11, 2020
1 parent 99b897c commit 6020b20
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/webhook/cspc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
type PoolValidator struct {
poolSpec *cstor.PoolSpec
namespace string
nodeName string
hostName string
cspcName string
clientset clientset.Interface
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (b *Builder) withClientset(c clientset.Interface) *Builder {
// withPoolNodeName sets the node name field of poolValidator with provided
// values
func (b *Builder) withPoolNodeName(nodeName string) *Builder {
b.object.nodeName = nodeName
b.object.hostName = nodeName
return b
}

Expand Down Expand Up @@ -389,7 +389,7 @@ func (poolValidator *PoolValidator) raidGroupValidation(
return true, ""
}

func validateBlockDevice(bd *openebsapis.BlockDevice, nodeName string) error {
func validateBlockDevice(bd *openebsapis.BlockDevice, hostName string) error {
if bd.Status.State != "Active" {
return errors.Errorf(
"block device is in not in active state",
Expand All @@ -400,11 +400,11 @@ func validateBlockDevice(bd *openebsapis.BlockDevice, nodeName string) error {
bd.Spec.FileSystem.Type,
)
}
if bd.Spec.NodeAttributes.NodeName != nodeName {
if bd.Labels[types.HostNameLabelKey] != hostName {
return errors.Errorf(
"block device %s doesn't belongs to node %s",
bd.Name,
bd.Spec.NodeAttributes.NodeName,
bd.Labels[types.HostNameLabelKey],
)
}
return nil
Expand All @@ -427,7 +427,7 @@ func (poolValidator *PoolValidator) blockDeviceValidation(
err,
)
}
err = validateBlockDevice(bdObj, poolValidator.nodeName)
err = validateBlockDevice(bdObj, poolValidator.hostName)

if err != nil {
return false, fmt.Sprintf("%v", err)
Expand Down

0 comments on commit 6020b20

Please sign in to comment.