Skip to content

Commit f46ecf5

Browse files
committed
KEP-3619: Wiring up from RuntimeFeatures.SupplementalGroupsPolicy(CRI) to NodeFeatures.SupplementalGroupsPolicy(API)
KEP-3619: fix typos in pkg/kubelet/container/runtime.go
1 parent 5d75660 commit f46ecf5

File tree

8 files changed

+61
-4
lines changed

8 files changed

+61
-4
lines changed

pkg/kubelet/container/runtime.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ type RuntimeStatus struct {
556556
Conditions []RuntimeCondition
557557
// Handlers is an array of current available handlers
558558
Handlers []RuntimeHandler
559+
// Features is the set of features implemented by the runtime
560+
Features *RuntimeFeatures
559561
}
560562

561563
// GetRuntimeCondition gets a specified runtime condition from the runtime status.
@@ -579,7 +581,7 @@ func (r *RuntimeStatus) String() string {
579581
for _, h := range r.Handlers {
580582
sh = append(sh, h.String())
581583
}
582-
return fmt.Sprintf("Runtime Conditions: %s; Handlers: %s", strings.Join(ss, ", "), strings.Join(sh, ", "))
584+
return fmt.Sprintf("Runtime Conditions: %s; Handlers: %s, Features: %s", strings.Join(ss, ", "), strings.Join(sh, ", "), r.Features.String())
583585
}
584586

585587
// RuntimeHandler contains condition information for the runtime handler.
@@ -617,6 +619,19 @@ func (c *RuntimeCondition) String() string {
617619
return fmt.Sprintf("%s=%t reason:%s message:%s", c.Type, c.Status, c.Reason, c.Message)
618620
}
619621

622+
// RuntimeFeatures contains the set of features implemented by the runtime
623+
type RuntimeFeatures struct {
624+
SupplementalGroupsPolicy bool
625+
}
626+
627+
// String formats the runtime condition into a human readable string.
628+
func (f *RuntimeFeatures) String() string {
629+
if f == nil {
630+
return "nil"
631+
}
632+
return fmt.Sprintf("SupplementalGroupsPolicy: %v", f.SupplementalGroupsPolicy)
633+
}
634+
620635
// Pods represents the list of pods
621636
type Pods []*Pod
622637

pkg/kubelet/kubelet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,7 @@ func (kl *Kubelet) updateRuntimeUp() {
28832883

28842884
kl.runtimeState.setRuntimeState(nil)
28852885
kl.runtimeState.setRuntimeHandlers(s.Handlers)
2886+
kl.runtimeState.setRuntimeFeatures(s.Features)
28862887
kl.oneTimeInitializer.Do(kl.initializeRuntimeDependentModules)
28872888
kl.runtimeState.setRuntimeSync(kl.clock.Now())
28882889
}

pkg/kubelet/kubelet_node_status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ func (kl *Kubelet) defaultNodeStatusFuncs() []func(context.Context, *v1.Node) er
737737
nodestatus.Images(kl.nodeStatusMaxImages, kl.imageManager.GetImageList),
738738
nodestatus.GoRuntime(),
739739
nodestatus.RuntimeHandlers(kl.runtimeState.runtimeHandlers),
740+
nodestatus.NodeFeatures(kl.runtimeState.runtimeFeatures),
740741
)
741742

742743
setters = append(setters,

pkg/kubelet/kuberuntime/helpers.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func parsePodUIDFromLogsDirectory(name string) types.UID {
208208
}
209209

210210
// toKubeRuntimeStatus converts the runtimeapi.RuntimeStatus to kubecontainer.RuntimeStatus.
211-
func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus, handlers []*runtimeapi.RuntimeHandler) *kubecontainer.RuntimeStatus {
211+
func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus, handlers []*runtimeapi.RuntimeHandler, features *runtimeapi.RuntimeFeatures) *kubecontainer.RuntimeStatus {
212212
conditions := []kubecontainer.RuntimeCondition{}
213213
for _, c := range status.GetConditions() {
214214
conditions = append(conditions, kubecontainer.RuntimeCondition{
@@ -232,7 +232,13 @@ func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus, handlers []*runtimeap
232232
SupportsUserNamespaces: supportsUserns,
233233
}
234234
}
235-
return &kubecontainer.RuntimeStatus{Conditions: conditions, Handlers: retHandlers}
235+
var retFeatures *kubecontainer.RuntimeFeatures
236+
if features != nil {
237+
retFeatures = &kubecontainer.RuntimeFeatures{
238+
SupplementalGroupsPolicy: features.SupplementalGroupsPolicy,
239+
}
240+
}
241+
return &kubecontainer.RuntimeStatus{Conditions: conditions, Handlers: retHandlers, Features: retFeatures}
236242
}
237243

238244
func fieldSeccompProfile(scmp *v1.SeccompProfile, profileRootPath string, fallbackToRuntimeDefault bool) (*runtimeapi.SecurityProfile, error) {

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func (m *kubeGenericRuntimeManager) Status(ctx context.Context) (*kubecontainer.
347347
if resp.GetStatus() == nil {
348348
return nil, errors.New("runtime status is nil")
349349
}
350-
return toKubeRuntimeStatus(resp.GetStatus(), resp.GetRuntimeHandlers()), nil
350+
return toKubeRuntimeStatus(resp.GetStatus(), resp.GetRuntimeHandlers(), resp.GetFeatures()), nil
351351
}
352352

353353
// GetPods returns a list of containers grouped by pods. The boolean parameter

pkg/kubelet/nodestatus/setters.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,23 @@ func GoRuntime() Setter {
482482
}
483483
}
484484

485+
// NodeFeatures returns a Setter that sets NodeFeatures on the node.
486+
func NodeFeatures(featuresGetter func() *kubecontainer.RuntimeFeatures) Setter {
487+
return func(ctx context.Context, node *v1.Node) error {
488+
if !utilfeature.DefaultFeatureGate.Enabled(features.SupplementalGroupsPolicy) {
489+
return nil
490+
}
491+
features := featuresGetter()
492+
if features == nil {
493+
return nil
494+
}
495+
node.Status.Features = &v1.NodeFeatures{
496+
SupplementalGroupsPolicy: &features.SupplementalGroupsPolicy,
497+
}
498+
return nil
499+
}
500+
}
501+
485502
// RuntimeHandlers returns a Setter that sets RuntimeHandlers on the node.
486503
func RuntimeHandlers(fn func() []kubecontainer.RuntimeHandler) Setter {
487504
return func(ctx context.Context, node *v1.Node) error {

pkg/kubelet/runtime.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type runtimeState struct {
3636
cidr string
3737
healthChecks []*healthCheck
3838
rtHandlers []kubecontainer.RuntimeHandler
39+
rtFeatures *kubecontainer.RuntimeFeatures
3940
}
4041

4142
// A health check function should be efficient and not rely on external
@@ -83,6 +84,18 @@ func (s *runtimeState) runtimeHandlers() []kubecontainer.RuntimeHandler {
8384
return s.rtHandlers
8485
}
8586

87+
func (s *runtimeState) setRuntimeFeatures(features *kubecontainer.RuntimeFeatures) {
88+
s.Lock()
89+
defer s.Unlock()
90+
s.rtFeatures = features
91+
}
92+
93+
func (s *runtimeState) runtimeFeatures() *kubecontainer.RuntimeFeatures {
94+
s.RLock()
95+
defer s.RUnlock()
96+
return s.rtFeatures
97+
}
98+
8699
func (s *runtimeState) setStorageState(err error) {
87100
s.Lock()
88101
defer s.Unlock()

pkg/registry/core/node/strategy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func dropDisabledFields(node *api.Node, oldNode *api.Node) {
106106
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) && !utilfeature.DefaultFeatureGate.Enabled(features.UserNamespacesSupport) {
107107
node.Status.RuntimeHandlers = nil
108108
}
109+
110+
if !utilfeature.DefaultFeatureGate.Enabled(features.SupplementalGroupsPolicy) {
111+
node.Status.Features = nil
112+
}
109113
}
110114

111115
// nodeConfigSourceInUse returns true if node's Spec ConfigSource is set(used)

0 commit comments

Comments
 (0)