Unverified Commit 411bda25 authored by Wang Bing's avatar Wang Bing Committed by GitHub
Browse files

Fix validateSidecarConflict (#884)

Signed-off-by: default avatarpigletfly <wangbing.adam@gmail.com>
No related merge requests found
Showing with 14 additions and 29 deletions
+14 -29
......@@ -265,8 +265,14 @@ func validateSidecarConflict(sidecarSets *appsv1alpha1.SidecarSetList, sidecarSe
volumeInOthers := make(map[string]*appsv1alpha1.SidecarSet)
// init container name -> sidecarset
initContainerInOthers := make(map[string]*appsv1alpha1.SidecarSet)
matchedList := make([]*appsv1alpha1.SidecarSet, 0)
for i := range sidecarSets.Items {
set := &sidecarSets.Items[i]
obj := &sidecarSets.Items[i]
if !isSidecarSetNamespaceDiff(sidecarSet, obj) && util.IsSelectorOverlapping(sidecarSet.Spec.Selector, obj.Spec.Selector) {
matchedList = append(matchedList, obj)
}
}
for _, set := range matchedList {
//ignore this sidecarset
if set.Name == sidecarSet.Name {
continue
......@@ -285,46 +291,25 @@ func validateSidecarConflict(sidecarSets *appsv1alpha1.SidecarSetList, sidecarSe
// whether initContainers conflict
for _, container := range sidecarSet.Spec.InitContainers {
if other, ok := initContainerInOthers[container.Name]; ok {
//if the two sidecarset scope namespace is different, continue
if isSidecarSetNamespaceDiff(sidecarSet, other) {
continue
}
// if the two sidecarset will selector same pod, then judge conflict
if util.IsSelectorOverlapping(sidecarSet.Spec.Selector, other.Spec.Selector) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("containers"), container.Name, fmt.Sprintf(
"container %v already exist in %v", container.Name, other.Name)))
}
allErrs = append(allErrs, field.Invalid(fldPath.Child("containers"), container.Name, fmt.Sprintf(
"container %v already exist in %v", container.Name, other.Name)))
}
}
// whether containers conflict
for _, container := range sidecarSet.Spec.Containers {
if other, ok := containerInOthers[container.Name]; ok {
// if the two sidecarset scope namespace is different, continue
if isSidecarSetNamespaceDiff(sidecarSet, other) {
continue
}
// if the two sidecarset will selector same pod, then judge conflict
if util.IsSelectorOverlapping(sidecarSet.Spec.Selector, other.Spec.Selector) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("containers"), container.Name, fmt.Sprintf(
"container %v already exist in %v", container.Name, other.Name)))
}
allErrs = append(allErrs, field.Invalid(fldPath.Child("containers"), container.Name, fmt.Sprintf(
"container %v already exist in %v", container.Name, other.Name)))
}
}
// whether volumes conflict
for _, volume := range sidecarSet.Spec.Volumes {
if other, ok := volumeInOthers[volume.Name]; ok {
//if the two sidecarset scope namespace is different, continue
if isSidecarSetNamespaceDiff(sidecarSet, other) {
continue
}
// if the two sidecarset will selector same pod, then judge conflict
if util.IsSelectorOverlapping(sidecarSet.Spec.Selector, other.Spec.Selector) {
if !reflect.DeepEqual(&volume, getSidecarsetVolume(volume.Name, other)) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumes"), volume.Name, fmt.Sprintf(
"volume %s is in conflict with sidecarset %s", volume.Name, other.Name)))
}
if !reflect.DeepEqual(&volume, getSidecarsetVolume(volume.Name, other)) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumes"), volume.Name, fmt.Sprintf(
"volume %s is in conflict with sidecarset %s", volume.Name, other.Name)))
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment