forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YaoZengzeng <[email protected]>
- Loading branch information
1 parent
9fa6770
commit defb039
Showing
46 changed files
with
5,244 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cri | ||
|
||
// Config defines the CRI configuration. | ||
type Config struct { | ||
// Listen is the listening address which servers CRI. | ||
Listen string | ||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package mgr | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/alibaba/pouch/cri" | ||
|
||
"github.com/cri-o/ocicni/pkg/ocicni" | ||
"github.com/sirupsen/logrus" | ||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" | ||
) | ||
|
||
// CniMgr as an interface defines all operations against CNI. | ||
type CniMgr interface { | ||
// Name returns the plugin's name. This will be used when searching | ||
// for a plugin by name, e.g. | ||
Name() string | ||
|
||
// SetUpPodNetwork is the method called after the sandbox container of the | ||
// pod has been created but before the other containers of the pod | ||
// are launched. | ||
SetUpPodNetwork(config *runtime.PodSandboxConfig, id string, netnsPath string) error | ||
|
||
// TearDownPodNetwork is the method called before a pod's sandbox container will be deleted. | ||
TearDownPodNetwork(config *runtime.PodSandboxConfig) error | ||
|
||
// GetPodNetworkStatus is the method called to obtain the ipv4 or ipv6 addresses of the pod sandbox. | ||
GetPodNetworkStatus(config *runtime.PodSandboxConfig) (string, error) | ||
|
||
// Status returns error if the network plugin is in error state. | ||
Status() error | ||
} | ||
|
||
// CniManager is an implementation of interface CniMgr. | ||
type CniManager struct { | ||
// plugin is used to setup and teardown network when run/stop pod sandbox. | ||
plugin ocicni.CNIPlugin | ||
} | ||
|
||
// NewCniManager initializes a brand new cni manager. | ||
func NewCniManager(cfg *cri.Config) (*CniManager, error) { | ||
networkPluginBinDir := cfg.NetworkPluginBinDir | ||
networkPluginConfDir := cfg.NetworkPluginConfDir | ||
|
||
// Create CNI configuration directory if it doesn't exist to avoid breaking. | ||
_, err := os.Stat(networkPluginConfDir) | ||
if err != nil && os.IsNotExist(err) { | ||
err = os.MkdirAll(networkPluginConfDir, 0666) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create configuration directory for CNI: %v", err) | ||
} | ||
} | ||
|
||
plugin, err := ocicni.InitCNI(networkPluginConfDir, networkPluginBinDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &CniManager{ | ||
plugin: plugin, | ||
}, nil | ||
} | ||
|
||
// Name returns the plugin's name. This will be used when searching | ||
// for a plugin by name, e.g. | ||
func (c *CniManager) Name() string { | ||
return c.plugin.Name() | ||
} | ||
|
||
// SetUpPodNetwork is the method called after the sandbox container of the | ||
// pod has been created but before the other containers of the pod | ||
// are launched. | ||
func (c *CniManager) SetUpPodNetwork(config *runtime.PodSandboxConfig, id string, netnsPath string) error { | ||
podNetwork := ocicni.PodNetwork{ | ||
Name: config.GetMetadata().GetName(), | ||
Namespace: config.GetMetadata().GetNamespace(), | ||
ID: id, | ||
NetNS: netnsPath, | ||
// TODO: portmapping. | ||
} | ||
|
||
_, err := c.plugin.SetUpPod(podNetwork) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
if err != nil { | ||
// Teardown network if an error returned. | ||
err := c.plugin.TearDownPod(podNetwork) | ||
if err != nil { | ||
logrus.Errorf("failed to detroy network for sandbox %q: %v", id, err) | ||
} | ||
} | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
// TearDownPodNetwork is the method called before a pod's sandbox container will be deleted. | ||
func (c *CniManager) TearDownPodNetwork(config *runtime.PodSandboxConfig) error { | ||
return fmt.Errorf("TearDownPodNetwork Not Implemented Yet") | ||
} | ||
|
||
// GetPodNetworkStatus is the method called to obtain the ipv4 or ipv6 addresses of the pod sandbox. | ||
func (c *CniManager) GetPodNetworkStatus(config *runtime.PodSandboxConfig) (string, error) { | ||
return "", fmt.Errorf("GetPodNetworkStatus Not Implemented Yet") | ||
} | ||
|
||
// Status returns error if the network plugin is in error state. | ||
func (c *CniManager) Status() error { | ||
return fmt.Errorf("Status Not Implemented Yet") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.