mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
kubelet: change map[string]RuntimeHandler to []RuntimeHandler
The map is changed to an array so as to retain the order of the original array propagated from the CRI runtime. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
parent
d3d06c3c7e
commit
27f24a62e3
@ -530,8 +530,8 @@ const (
|
|||||||
type RuntimeStatus struct {
|
type RuntimeStatus struct {
|
||||||
// Conditions is an array of current observed runtime conditions.
|
// Conditions is an array of current observed runtime conditions.
|
||||||
Conditions []RuntimeCondition
|
Conditions []RuntimeCondition
|
||||||
// Handlers is a map of current available handlers
|
// Handlers is an array of current available handlers
|
||||||
Handlers map[string]RuntimeHandler
|
Handlers []RuntimeHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRuntimeCondition gets a specified runtime condition from the runtime status.
|
// GetRuntimeCondition gets a specified runtime condition from the runtime status.
|
||||||
|
@ -123,11 +123,12 @@ func (kl *Kubelet) HandlerSupportsUserNamespaces(rtHandler string) (bool, error)
|
|||||||
if rtHandlers == nil {
|
if rtHandlers == nil {
|
||||||
return false, fmt.Errorf("runtime handlers are not set")
|
return false, fmt.Errorf("runtime handlers are not set")
|
||||||
}
|
}
|
||||||
h, found := rtHandlers[rtHandler]
|
for _, h := range rtHandlers {
|
||||||
if !found {
|
if h.Name == rtHandler {
|
||||||
return false, fmt.Errorf("the handler %q is not known", rtHandler)
|
|
||||||
}
|
|
||||||
return h.SupportsUserNamespaces, nil
|
return h.SupportsUserNamespaces, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, fmt.Errorf("the handler %q is not known", rtHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetKubeletMappings gets the additional IDs allocated for the Kubelet.
|
// GetKubeletMappings gets the additional IDs allocated for the Kubelet.
|
||||||
|
@ -109,13 +109,13 @@ func TestHandlerSupportsUserNamespaces(t *testing.T) {
|
|||||||
defer testKubelet.Cleanup()
|
defer testKubelet.Cleanup()
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
|
|
||||||
kubelet.runtimeState.setRuntimeHandlers(map[string]kubecontainer.RuntimeHandler{
|
kubelet.runtimeState.setRuntimeHandlers([]kubecontainer.RuntimeHandler{
|
||||||
"has-support": {
|
{
|
||||||
Name: "has-support",
|
Name: "has-support",
|
||||||
SupportsUserNamespaces: true,
|
SupportsUserNamespaces: true,
|
||||||
},
|
},
|
||||||
"has-no-support": {
|
{
|
||||||
Name: "has-support",
|
Name: "has-no-support",
|
||||||
SupportsUserNamespaces: false,
|
SupportsUserNamespaces: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -219,13 +219,13 @@ func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus, handlers []*runtimeap
|
|||||||
Message: c.Message,
|
Message: c.Message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
retHandlers := make(map[string]kubecontainer.RuntimeHandler)
|
retHandlers := make([]kubecontainer.RuntimeHandler, len(handlers))
|
||||||
for _, h := range handlers {
|
for i, h := range handlers {
|
||||||
supportsUserns := false
|
supportsUserns := false
|
||||||
if h.Features != nil {
|
if h.Features != nil {
|
||||||
supportsUserns = h.Features.UserNamespaces
|
supportsUserns = h.Features.UserNamespaces
|
||||||
}
|
}
|
||||||
retHandlers[h.Name] = kubecontainer.RuntimeHandler{
|
retHandlers[i] = kubecontainer.RuntimeHandler{
|
||||||
Name: h.Name,
|
Name: h.Name,
|
||||||
SupportsUserNamespaces: supportsUserns,
|
SupportsUserNamespaces: supportsUserns,
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ type runtimeState struct {
|
|||||||
storageError error
|
storageError error
|
||||||
cidr string
|
cidr string
|
||||||
healthChecks []*healthCheck
|
healthChecks []*healthCheck
|
||||||
rtHandlers map[string]kubecontainer.RuntimeHandler
|
rtHandlers []kubecontainer.RuntimeHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// A health check function should be efficient and not rely on external
|
// A health check function should be efficient and not rely on external
|
||||||
@ -71,13 +71,13 @@ func (s *runtimeState) setRuntimeState(err error) {
|
|||||||
s.runtimeError = err
|
s.runtimeError = err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *runtimeState) setRuntimeHandlers(rtHandlers map[string]kubecontainer.RuntimeHandler) {
|
func (s *runtimeState) setRuntimeHandlers(rtHandlers []kubecontainer.RuntimeHandler) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
s.rtHandlers = rtHandlers
|
s.rtHandlers = rtHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *runtimeState) runtimeHandlers() map[string]kubecontainer.RuntimeHandler {
|
func (s *runtimeState) runtimeHandlers() []kubecontainer.RuntimeHandler {
|
||||||
s.RLock()
|
s.RLock()
|
||||||
defer s.RUnlock()
|
defer s.RUnlock()
|
||||||
return s.rtHandlers
|
return s.rtHandlers
|
||||||
|
Loading…
Reference in New Issue
Block a user