mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +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 {
|
||||
// Conditions is an array of current observed runtime conditions.
|
||||
Conditions []RuntimeCondition
|
||||
// Handlers is a map of current available handlers
|
||||
Handlers map[string]RuntimeHandler
|
||||
// Handlers is an array of current available handlers
|
||||
Handlers []RuntimeHandler
|
||||
}
|
||||
|
||||
// GetRuntimeCondition gets a specified runtime condition from the runtime status.
|
||||
|
@ -123,12 +123,13 @@ func (kl *Kubelet) HandlerSupportsUserNamespaces(rtHandler string) (bool, error)
|
||||
if rtHandlers == nil {
|
||||
return false, fmt.Errorf("runtime handlers are not set")
|
||||
}
|
||||
h, found := rtHandlers[rtHandler]
|
||||
if !found {
|
||||
return false, fmt.Errorf("the handler %q is not known", rtHandler)
|
||||
}
|
||||
for _, h := range rtHandlers {
|
||||
if h.Name == rtHandler {
|
||||
return h.SupportsUserNamespaces, nil
|
||||
}
|
||||
}
|
||||
return false, fmt.Errorf("the handler %q is not known", rtHandler)
|
||||
}
|
||||
|
||||
// GetKubeletMappings gets the additional IDs allocated for the Kubelet.
|
||||
func (kl *Kubelet) GetKubeletMappings() (uint32, uint32, error) {
|
||||
|
@ -109,13 +109,13 @@ func TestHandlerSupportsUserNamespaces(t *testing.T) {
|
||||
defer testKubelet.Cleanup()
|
||||
kubelet := testKubelet.kubelet
|
||||
|
||||
kubelet.runtimeState.setRuntimeHandlers(map[string]kubecontainer.RuntimeHandler{
|
||||
"has-support": {
|
||||
kubelet.runtimeState.setRuntimeHandlers([]kubecontainer.RuntimeHandler{
|
||||
{
|
||||
Name: "has-support",
|
||||
SupportsUserNamespaces: true,
|
||||
},
|
||||
"has-no-support": {
|
||||
Name: "has-support",
|
||||
{
|
||||
Name: "has-no-support",
|
||||
SupportsUserNamespaces: false,
|
||||
},
|
||||
})
|
||||
|
@ -219,13 +219,13 @@ func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus, handlers []*runtimeap
|
||||
Message: c.Message,
|
||||
})
|
||||
}
|
||||
retHandlers := make(map[string]kubecontainer.RuntimeHandler)
|
||||
for _, h := range handlers {
|
||||
retHandlers := make([]kubecontainer.RuntimeHandler, len(handlers))
|
||||
for i, h := range handlers {
|
||||
supportsUserns := false
|
||||
if h.Features != nil {
|
||||
supportsUserns = h.Features.UserNamespaces
|
||||
}
|
||||
retHandlers[h.Name] = kubecontainer.RuntimeHandler{
|
||||
retHandlers[i] = kubecontainer.RuntimeHandler{
|
||||
Name: h.Name,
|
||||
SupportsUserNamespaces: supportsUserns,
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type runtimeState struct {
|
||||
storageError error
|
||||
cidr string
|
||||
healthChecks []*healthCheck
|
||||
rtHandlers map[string]kubecontainer.RuntimeHandler
|
||||
rtHandlers []kubecontainer.RuntimeHandler
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func (s *runtimeState) setRuntimeHandlers(rtHandlers map[string]kubecontainer.RuntimeHandler) {
|
||||
func (s *runtimeState) setRuntimeHandlers(rtHandlers []kubecontainer.RuntimeHandler) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
s.rtHandlers = rtHandlers
|
||||
}
|
||||
|
||||
func (s *runtimeState) runtimeHandlers() map[string]kubecontainer.RuntimeHandler {
|
||||
func (s *runtimeState) runtimeHandlers() []kubecontainer.RuntimeHandler {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
return s.rtHandlers
|
||||
|
Loading…
Reference in New Issue
Block a user