Skip to content

Commit

Permalink
fix(webhook): fix cspi node selector label in scale down operation (o…
Browse files Browse the repository at this point in the history
…penebs-archive#122)

While scaling down a pool by removing a pool spec
from the CSPC, there was nil pool list getting initialized due to 
additional node-selector labels get added in pool list label-selector not
matches with existing CSPI labels, causing the webhook failures 

Signed-off-by: Ashutosh Kumar <ashutosh.kumar@mayadata.io>
  • Loading branch information
Ashutosh Kumar committed Jul 9, 2020
1 parent 716d4a2 commit 3d8831c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/webhook/cspc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
openebsapis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1"
"github.com/openebs/api/pkg/apis/types"
clientset "github.com/openebs/api/pkg/client/clientset/versioned"
util "github.com/openebs/api/pkg/util"
"github.com/openebs/api/pkg/util"
"github.com/pkg/errors"
"k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -519,6 +519,7 @@ func (wh *webhook) validateCSPCUpdateRequest(req *v1beta1.AdmissionRequest, getC
// that is being scaled down
func (p *PoolOperations) ValidateScaledown() (bool, string) {
removedPools := []string{}

for _, oldPool := range p.OldCSPC.Spec.Pools {
found := false
for _, newPool := range p.NewCSPC.Spec.Pools {
Expand All @@ -528,10 +529,26 @@ func (p *PoolOperations) ValidateScaledown() (bool, string) {
}
}
if !found && p.IsScaledownCase(oldPool) {
var nodeName string
if v, ok := oldPool.NodeSelector[types.HostNameLabelKey]; ok {
nodeName = v
} else {
gotNodeName, err := GetHostNameFromLabelSelector(oldPool.NodeSelector, p.kubeClient)
if err != nil {
return false, fmt.Sprintf("Could not list node for node selectors {%v}", oldPool.NodeSelector)
}
nodeName = gotNodeName
}

ls := &metav1.LabelSelector{
MatchLabels: map[string]string{
types.CStorPoolClusterLabelKey: p.OldCSPC.Name,
types.HostNameLabelKey: nodeName,
},
}
cspi, err := p.clientset.CstorV1().CStorPoolInstances(p.OldCSPC.Namespace).
List(metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(oldPool.NodeSelector).String() + "," +
types.CStorPoolClusterLabelKey + "=" + p.OldCSPC.Name,
LabelSelector: labels.Set(ls.MatchLabels).String(),
})
if err != nil {
return false, fmt.Sprintf("Could not list cspi for cspc %s: %s", p.OldCSPC.Name, err.Error())
Expand Down

0 comments on commit 3d8831c

Please sign in to comment.