-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
398 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package admission | ||
|
||
import ( | ||
kapi "k8s.io/kubernetes/pkg/api" | ||
) | ||
|
||
// ByRestrictions is a helper to sort SCCs based on priority. If priorities are equal | ||
// a string compare of the name is used. | ||
type ByPriority []*kapi.SecurityContextConstraints | ||
|
||
func (s ByPriority) Len() int { | ||
return len(s) | ||
} | ||
func (s ByPriority) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | ||
func (s ByPriority) Less(i, j int) bool { | ||
iSCC := s[i] | ||
jSCC := s[j] | ||
|
||
// if only one of the SCCs has a priority defined then the SCC with the priority should | ||
// be considered "less" so it will be moved up | ||
if iSCC.Priority != nil && jSCC.Priority == nil { | ||
return true | ||
} | ||
|
||
if iSCC.Priority == nil && jSCC.Priority != nil { | ||
return false | ||
} | ||
|
||
// if both have priorities defined then compare the priorities | ||
if iSCC.Priority != nil && jSCC.Priority != nil { | ||
// a higher priority is considered "less" so that it moves to the front of the line | ||
if *iSCC.Priority > *jSCC.Priority { | ||
return true | ||
} | ||
|
||
if *iSCC.Priority < *jSCC.Priority { | ||
return false | ||
} | ||
} | ||
|
||
// priorities are equal or undefined on both, let's try point values | ||
iRestrictionScore := pointValue(iSCC) | ||
jRestrictionScore := pointValue(jSCC) | ||
|
||
// a lower restriction score is considered "less" so that it moves to the front of the line | ||
// (the greater the score, the more lax the SCC is) | ||
if iRestrictionScore < jRestrictionScore { | ||
return true | ||
} | ||
|
||
if iRestrictionScore > jRestrictionScore { | ||
return false | ||
} | ||
|
||
// they are still equal, sort by name | ||
return iSCC.Name < jSCC.Name | ||
} |
Oops, something went wrong.