Skip to content

Commit

Permalink
Deduplicate capabilities in generate kube
Browse files Browse the repository at this point in the history
capabilities that were added and dropped were several times duplicated. Fix this

Signed-off-by: Peter Hunt <[email protected]>
  • Loading branch information
haircommander committed Aug 1, 2019
1 parent afb493a commit 3acfcb3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
drop = append(drop, v1.Capability(capability))
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) {
add = append(add, v1.Capability(capability))
if _, ok := dedupAdd[string(capability)]; !ok {
add = append(add, v1.Capability(capability))
dedupAdd[capability] = true
}
}
}

Expand Down

0 comments on commit 3acfcb3

Please sign in to comment.