| Lorenz Brun | d58edf4 | 2024-11-27 20:38:14 +0000 | [diff] [blame] | 1 | package kubernetes |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| Lorenz Brun | b62b8e0 | 2024-12-16 20:18:47 +0100 | [diff] [blame^] | 5 | "sort" |
| Lorenz Brun | d58edf4 | 2024-11-27 20:38:14 +0000 | [diff] [blame] | 6 | "strings" |
| 7 | |
| 8 | "k8s.io/component-base/featuregate" |
| Lorenz Brun | 2ecccae | 2024-11-27 22:03:35 +0100 | [diff] [blame] | 9 | "k8s.io/kubernetes/pkg/features" |
| Lorenz Brun | d58edf4 | 2024-11-27 20:38:14 +0000 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | type featureGates map[featuregate.Feature]bool |
| 13 | |
| 14 | // AsFlag returns the feature gates as a --feature-gate flag. |
| 15 | func (fgs featureGates) AsFlag() string { |
| 16 | var strb strings.Builder |
| 17 | strb.WriteString("--feature-gates=") |
| Lorenz Brun | b62b8e0 | 2024-12-16 20:18:47 +0100 | [diff] [blame^] | 18 | features := make([]string, 0, len(fgs)) |
| 19 | for f := range fgs { |
| 20 | features = append(features, string(f)) |
| 21 | } |
| 22 | // Ensure deterministic output by sorting the map keys |
| 23 | sort.Strings(features) |
| 24 | for i, f := range features { |
| 25 | fmt.Fprintf(&strb, "%s=%v", f, fgs[featuregate.Feature(f)]) |
| 26 | if i+1 != len(features) { |
| Lorenz Brun | d58edf4 | 2024-11-27 20:38:14 +0000 | [diff] [blame] | 27 | strb.WriteByte(',') |
| 28 | } |
| 29 | } |
| 30 | return strb.String() |
| 31 | } |
| 32 | |
| 33 | // AsConfigObject returns the feature gates as a plain map for K8s configs. |
| 34 | func (fgs featureGates) AsMap() map[string]bool { |
| 35 | out := make(map[string]bool) |
| 36 | for f, en := range fgs { |
| 37 | out[string(f)] = en |
| 38 | } |
| 39 | return out |
| 40 | } |
| 41 | |
| Lorenz Brun | 2ecccae | 2024-11-27 22:03:35 +0100 | [diff] [blame] | 42 | var extraFeatureGates = featureGates{ |
| 43 | features.UserNamespacesSupport: true, |
| 44 | features.UserNamespacesPodSecurityStandards: true, |
| 45 | } |