Add flags and initialize network plugin
Signed-off-by: Xianglin Gao <xlgao@zju.edu.cn>
This commit is contained in:
parent
10e3afbb23
commit
c541515674
@ -42,9 +42,13 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Exitf("Failed to connect containerd endpoint %q: %v", o.ContainerdEndpoint, err)
|
glog.Exitf("Failed to connect containerd endpoint %q: %v", o.ContainerdEndpoint, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(2).Infof("Run cri-containerd grpc server on socket %q", o.SocketPath)
|
glog.V(2).Infof("Run cri-containerd grpc server on socket %q", o.SocketPath)
|
||||||
service := server.NewCRIContainerdService(conn, o.RootDir)
|
|
||||||
|
service, err := server.NewCRIContainerdService(conn, o.RootDir, o.NetworkPluginBinDir, o.NetworkPluginConfDir)
|
||||||
|
if err != nil {
|
||||||
|
glog.Exitf("Failed to create CRI containerd service %+v: %v", o, err)
|
||||||
|
}
|
||||||
|
|
||||||
s := server.NewCRIContainerdServer(o.SocketPath, service, service)
|
s := server.NewCRIContainerdServer(o.SocketPath, service, service)
|
||||||
if err := s.Run(); err != nil {
|
if err := s.Run(); err != nil {
|
||||||
glog.Exitf("Failed to run cri-containerd grpc server: %v", err)
|
glog.Exitf("Failed to run cri-containerd grpc server: %v", err)
|
||||||
|
@ -36,6 +36,10 @@ type CRIContainerdOptions struct {
|
|||||||
ContainerdEndpoint string
|
ContainerdEndpoint string
|
||||||
// ContainerdConnectionTimeout is the connection timeout for containerd client.
|
// ContainerdConnectionTimeout is the connection timeout for containerd client.
|
||||||
ContainerdConnectionTimeout time.Duration
|
ContainerdConnectionTimeout time.Duration
|
||||||
|
// NetworkPluginBinDir is the directory in which the binaries for the plugin is kept.
|
||||||
|
NetworkPluginBinDir string
|
||||||
|
// NetworkPluginConfDir is the directory in which the admin places a CNI conf.
|
||||||
|
NetworkPluginConfDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCRIContainerdOptions returns a reference to CRIContainerdOptions
|
// NewCRIContainerdOptions returns a reference to CRIContainerdOptions
|
||||||
@ -55,6 +59,10 @@ func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
|
|||||||
2*time.Minute, "Connection timeout for containerd client.")
|
2*time.Minute, "Connection timeout for containerd client.")
|
||||||
fs.BoolVar(&c.PrintVersion, "version",
|
fs.BoolVar(&c.PrintVersion, "version",
|
||||||
false, "Print cri-containerd version information and quit.")
|
false, "Print cri-containerd version information and quit.")
|
||||||
|
fs.StringVar(&c.NetworkPluginBinDir, "network-bin-dir",
|
||||||
|
"/etc/cni/net.d", "The directory for putting network binaries.")
|
||||||
|
fs.StringVar(&c.NetworkPluginConfDir, "network-conf-dir",
|
||||||
|
"/opt/cni/bin", "The directory for putting network plugin configuration files.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitFlags must be called after adding all cli options flags are defined and
|
// InitFlags must be called after adding all cli options flags are defined and
|
||||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/truncindex"
|
"github.com/docker/docker/pkg/truncindex"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
@ -31,6 +33,8 @@ import (
|
|||||||
imagesservice "github.com/containerd/containerd/services/images"
|
imagesservice "github.com/containerd/containerd/services/images"
|
||||||
rootfsservice "github.com/containerd/containerd/services/rootfs"
|
rootfsservice "github.com/containerd/containerd/services/rootfs"
|
||||||
|
|
||||||
|
"github.com/kubernetes-incubator/cri-o/pkg/ocicni"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store"
|
||||||
osinterface "github.com/kubernetes-incubator/cri-containerd/pkg/os"
|
osinterface "github.com/kubernetes-incubator/cri-containerd/pkg/os"
|
||||||
@ -94,13 +98,15 @@ type criContainerdService struct {
|
|||||||
// imageStoreService is the containerd service to store and track
|
// imageStoreService is the containerd service to store and track
|
||||||
// image metadata.
|
// image metadata.
|
||||||
imageStoreService images.Store
|
imageStoreService images.Store
|
||||||
|
// netPlugin is used to setup and teardown network when run/stop pod sandbox.
|
||||||
|
netPlugin ocicni.CNIPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCRIContainerdService returns a new instance of CRIContainerdService
|
// NewCRIContainerdService returns a new instance of CRIContainerdService
|
||||||
func NewCRIContainerdService(conn *grpc.ClientConn, rootDir string) CRIContainerdService {
|
func NewCRIContainerdService(conn *grpc.ClientConn, rootDir, networkPluginBinDir, networkPluginConfDir string) (CRIContainerdService, error) {
|
||||||
// TODO: Initialize different containerd clients.
|
// TODO: Initialize different containerd clients.
|
||||||
// TODO(random-liu): [P2] Recover from runtime state and metadata store.
|
// TODO(random-liu): [P2] Recover from runtime state and metadata store.
|
||||||
return &criContainerdService{
|
c := &criContainerdService{
|
||||||
os: osinterface.RealOS{},
|
os: osinterface.RealOS{},
|
||||||
rootDir: rootDir,
|
rootDir: rootDir,
|
||||||
sandboxStore: metadata.NewSandboxStore(store.NewMetadataStore()),
|
sandboxStore: metadata.NewSandboxStore(store.NewMetadataStore()),
|
||||||
@ -118,6 +124,14 @@ func NewCRIContainerdService(conn *grpc.ClientConn, rootDir string) CRIContainer
|
|||||||
contentProvider: contentservice.NewProviderFromClient(contentapi.NewContentClient(conn)),
|
contentProvider: contentservice.NewProviderFromClient(contentapi.NewContentClient(conn)),
|
||||||
rootfsUnpacker: rootfsservice.NewUnpackerFromClient(rootfsapi.NewRootFSClient(conn)),
|
rootfsUnpacker: rootfsservice.NewUnpackerFromClient(rootfsapi.NewRootFSClient(conn)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
netPlugin, err := ocicni.InitCNI(networkPluginBinDir, networkPluginConfDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to initialize cni plugin: %v", err)
|
||||||
|
}
|
||||||
|
c.netPlugin = netPlugin
|
||||||
|
|
||||||
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criContainerdService) Start() error {
|
func (c *criContainerdService) Start() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user