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