Update how we detect overlapping deployments

When looking for overlapping deployments, we should also find other deployments that select current deployment's pods,
not just the ones whose pods are selected by current deployment.
This commit is contained in:
Janet Kuo
2016-11-02 14:43:23 -07:00
parent d28f7031a1
commit 9f3560c563
3 changed files with 25 additions and 5 deletions

View File

@@ -835,3 +835,22 @@ func (o BySelectorLastUpdateTime) Less(i, j int) bool {
}
return ti.Before(tj)
}
// OverlapsWith returns true when two given deployments are different and overlap with each other
func OverlapsWith(current, other *extensions.Deployment) (bool, error) {
if current.UID == other.UID {
return false, nil
}
currentSelector, err := unversioned.LabelSelectorAsSelector(current.Spec.Selector)
if err != nil {
return false, fmt.Errorf("deployment %s/%s has invalid label selector: %v", current.Namespace, current.Name, err)
}
otherSelector, err := unversioned.LabelSelectorAsSelector(other.Spec.Selector)
if err != nil {
// Broken selectors from other deployments shouldn't block current deployment. Just log the error and continue.
glog.V(2).Infof("Skip overlapping check: deployment %s/%s has invalid label selector: %v", other.Namespace, other.Name, err)
return false, nil
}
return (!currentSelector.Empty() && currentSelector.Matches(labels.Set(other.Spec.Template.Labels))) ||
(!otherSelector.Empty() && otherSelector.Matches(labels.Set(current.Spec.Template.Labels))), nil
}