Merge pull request #2203 from 0902horn/configurable-containerd-factory
Make the containerd factory configurable
This commit is contained in:
commit
52f7d1d896
@ -31,11 +31,6 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// k8sNamespace is the namespace we use to connect containerd.
|
|
||||||
k8sNamespace = "k8s.io"
|
|
||||||
)
|
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
containerService containersapi.ContainersClient
|
containerService containersapi.ContainersClient
|
||||||
taskService tasksapi.TasksClient
|
taskService tasksapi.TasksClient
|
||||||
@ -52,13 +47,12 @@ var once sync.Once
|
|||||||
var ctrdClient containerdClient = nil
|
var ctrdClient containerdClient = nil
|
||||||
|
|
||||||
const (
|
const (
|
||||||
address = "/run/containerd/containerd.sock"
|
|
||||||
maxBackoffDelay = 3 * time.Second
|
maxBackoffDelay = 3 * time.Second
|
||||||
connectionTimeout = 2 * time.Second
|
connectionTimeout = 2 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client creates a containerd client
|
// Client creates a containerd client
|
||||||
func Client() (containerdClient, error) {
|
func Client(address, namespace string) (containerdClient, error) {
|
||||||
var retErr error
|
var retErr error
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
tryConn, err := net.DialTimeout("unix", address, connectionTimeout)
|
tryConn, err := net.DialTimeout("unix", address, connectionTimeout)
|
||||||
@ -75,7 +69,7 @@ func Client() (containerdClient, error) {
|
|||||||
grpc.WithBackoffMaxDelay(maxBackoffDelay),
|
grpc.WithBackoffMaxDelay(maxBackoffDelay),
|
||||||
grpc.WithTimeout(connectionTimeout),
|
grpc.WithTimeout(connectionTimeout),
|
||||||
}
|
}
|
||||||
unary, stream := newNSInterceptors(k8sNamespace)
|
unary, stream := newNSInterceptors(namespace)
|
||||||
gopts = append(gopts,
|
gopts = append(gopts,
|
||||||
grpc.WithUnaryInterceptor(unary),
|
grpc.WithUnaryInterceptor(unary),
|
||||||
grpc.WithStreamInterceptor(stream),
|
grpc.WithStreamInterceptor(stream),
|
||||||
|
@ -31,7 +31,8 @@ import (
|
|||||||
"github.com/google/cadvisor/manager/watcher"
|
"github.com/google/cadvisor/manager/watcher"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ArgContainerdEndpoint = flag.String("containerd", "unix:///var/run/containerd.sock", "containerd endpoint")
|
var ArgContainerdEndpoint = flag.String("containerd", "/run/containerd/containerd.sock", "containerd endpoint")
|
||||||
|
var ArgContainerdNamespace = flag.String("containerd-namespace", "k8s.io", "containerd namespace")
|
||||||
|
|
||||||
// The namespace under which containerd aliases are unique.
|
// The namespace under which containerd aliases are unique.
|
||||||
const k8sContainerdNamespace = "containerd"
|
const k8sContainerdNamespace = "containerd"
|
||||||
@ -56,7 +57,7 @@ func (self *containerdFactory) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *containerdFactory) NewContainerHandler(name string, inHostNamespace bool) (handler container.ContainerHandler, err error) {
|
func (self *containerdFactory) NewContainerHandler(name string, inHostNamespace bool) (handler container.ContainerHandler, err error) {
|
||||||
client, err := Client()
|
client, err := Client(*ArgContainerdEndpoint, *ArgContainerdNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -118,7 +119,7 @@ func (self *containerdFactory) DebugInfo() map[string][]string {
|
|||||||
|
|
||||||
// Register root container before running this function!
|
// Register root container before running this function!
|
||||||
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, includedMetrics container.MetricSet) error {
|
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, includedMetrics container.MetricSet) error {
|
||||||
client, err := Client()
|
client, err := Client(*ArgContainerdEndpoint, *ArgContainerdNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create containerd client: %v", err)
|
return fmt.Errorf("unable to create containerd client: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user