Skip to content

Commit

Permalink
Fix validateSidecarConflict (#884)
Browse files Browse the repository at this point in the history
Signed-off-by: pigletfly <[email protected]>
  • Loading branch information
pigletfly authored Feb 14, 2022
1 parent 56977b4 commit 411bda2
Showing 1 changed file with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
}
}
}
Expand Down

0 comments on commit 411bda2

Please sign in to comment.