Deduplicate capabilities in generate kube
capabilities that were added and dropped were several times duplicated. Fix this
@@ -406,18 +406,26 @@ func determineCapAddDropFromCapabilities(defaultCaps, containerCaps []string) *v
drop []v1.Capability
add []v1.Capability
)
+ dedupDrop := make(map[string]bool)
+ dedupAdd := make(map[string]bool)
// Find caps in the defaultCaps but not in the container's
// those indicate a dropped cap
for _, capability := range defaultCaps {
if !util.StringInSlice(capability, containerCaps) {
+ if _, ok := dedupDrop[capability]; !ok {
drop = append(drop, v1.Capability(capability))
+ dedupDrop[capability] = true
+ }
}
}
// Find caps in the container but not in the defaults; those indicate
// an added cap
for _, capability := range containerCaps {
if !util.StringInSlice(capability, defaultCaps) {
+ if _, ok := dedupAdd[string(capability)]; !ok {
add = append(add, v1.Capability(capability))
+ dedupAdd[capability] = true
+ }
}
}
