Fix update container resources
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
45
pkg/store/container/client.go
Normal file
45
pkg/store/container/client.go
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package container
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
)
|
||||
|
||||
// Client holds the containerd container client.
|
||||
// containerd.Container is a pointer underlying. New assignment won't affect
|
||||
// the previous pointer, so simply lock around is enough.
|
||||
type Client struct {
|
||||
lock sync.RWMutex
|
||||
container containerd.Container
|
||||
}
|
||||
|
||||
// Get containerd container client.
|
||||
func (c *Client) Get() containerd.Container {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
return c.container
|
||||
}
|
||||
|
||||
// Set containerd container client.
|
||||
func (c *Client) Set(container containerd.Container) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
c.container = container
|
||||
}
|
||||
@@ -32,8 +32,8 @@ type Container struct {
|
||||
Metadata
|
||||
// Status stores the status of the container.
|
||||
Status StatusStorage
|
||||
// Containerd container
|
||||
Container containerd.Container
|
||||
// Container is the containerd container client.
|
||||
Container *Client
|
||||
// Container IO
|
||||
IO *cio.ContainerIO
|
||||
// TODO(random-liu): Add stop channel to get rid of stop poll waiting.
|
||||
@@ -45,7 +45,7 @@ type Opts func(*Container) error
|
||||
// WithContainer adds the containerd Container to the internal data store.
|
||||
func WithContainer(cntr containerd.Container) Opts {
|
||||
return func(c *Container) error {
|
||||
c.Container = cntr
|
||||
c.Container = &Client{container: cntr}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ type Metadata struct {
|
||||
// SandboxID is the sandbox id the container belongs to.
|
||||
SandboxID string
|
||||
// Config is the CRI container config.
|
||||
// NOTE(random-liu): Resource limits are updatable, the source
|
||||
// of truth for resource limits are in containerd.
|
||||
Config *runtime.ContainerConfig
|
||||
// ImageRef is the reference of image used by the container.
|
||||
ImageRef string
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
type Sandbox struct {
|
||||
// Metadata is the metadata of the sandbox, it is immutable after created.
|
||||
Metadata
|
||||
// Containerd sandbox container
|
||||
// Container is the containerd sandbox container client
|
||||
Container containerd.Container
|
||||
// CNI network namespace client
|
||||
NetNS *NetNS
|
||||
|
||||
Reference in New Issue
Block a user