mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-02 00:02:01 +00:00
virtcontainers: sandbox: Add new getter to retrieve netns
As we want to call the OCI hook from the CLI, we need a way for the CLI to figure out what is the network namespace used by the sandbox. This is needed particularly because virtcontainers creates the netns if none was provided. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
cb351dca10
commit
ec0fd1b67a
@ -59,6 +59,7 @@ type VC interface {
|
||||
// (required since virtcontainers.Sandbox only contains private fields)
|
||||
type VCSandbox interface {
|
||||
Annotations(key string) (string, error)
|
||||
GetNetNs() string
|
||||
GetAllContainers() []VCContainer
|
||||
GetAnnotations() map[string]string
|
||||
GetContainer(containerID string) VCContainer
|
||||
|
@ -36,6 +36,11 @@ func (s *Sandbox) GetAnnotations() map[string]string {
|
||||
return s.MockAnnotations
|
||||
}
|
||||
|
||||
// GetNetNs returns the network namespace of the current sandbox.
|
||||
func (s *Sandbox) GetNetNs() string {
|
||||
return s.MockNetNs
|
||||
}
|
||||
|
||||
// GetAllContainers implements the VCSandbox function of the same name.
|
||||
func (s *Sandbox) GetAllContainers() []vc.VCContainer {
|
||||
var ifa = make([]vc.VCContainer, len(s.MockContainers))
|
||||
|
@ -23,6 +23,7 @@ type Sandbox struct {
|
||||
MockURL string
|
||||
MockAnnotations map[string]string
|
||||
MockContainers []*Container
|
||||
MockNetNs string
|
||||
}
|
||||
|
||||
// Container is a fake Container type used for testing
|
||||
|
@ -544,6 +544,11 @@ func (s *Sandbox) GetAnnotations() map[string]string {
|
||||
return s.config.Annotations
|
||||
}
|
||||
|
||||
// GetNetNs returns the network namespace of the current sandbox.
|
||||
func (s *Sandbox) GetNetNs() string {
|
||||
return s.networkNS.NetNsPath
|
||||
}
|
||||
|
||||
// GetAllContainers returns all containers.
|
||||
func (s *Sandbox) GetAllContainers() []VCContainer {
|
||||
ifa := make([]VCContainer, len(s.containers))
|
||||
|
@ -1706,3 +1706,19 @@ func TestPreAddDevice(t *testing.T) {
|
||||
assert.Equal(t, len(mounts), 0,
|
||||
"mounts should contain nothing because it only contains a block device")
|
||||
}
|
||||
|
||||
func TestGetNetNs(t *testing.T) {
|
||||
s := Sandbox{}
|
||||
|
||||
expected := ""
|
||||
netNs := s.GetNetNs()
|
||||
assert.Equal(t, netNs, expected)
|
||||
|
||||
expected = "/foo/bar/ns/net"
|
||||
s.networkNS = NetworkNamespace{
|
||||
NetNsPath: expected,
|
||||
}
|
||||
|
||||
netNs = s.GetNetNs()
|
||||
assert.Equal(t, netNs, expected)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user