Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Networking part2 [WIP DO NOT MERGE] #142

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PREFIX ?= ${DESTDIR}/usr/local
BINDIR ?= ${PREFIX}/bin
LIBEXECDIR ?= ${PREFIX}/libexec
MANDIR ?= ${PREFIX}/share/man
ETCDIR ?= ${DESTDIR}/etc
ETCDIR ?= ${PREFIX}/../etc
ETCDIR_LIBPOD ?= ${ETCDIR}/crio
BUILDTAGS ?= seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh) $(shell hack/btrfs_installed_tag.sh) $(shell hack/ostree_tag.sh) $(shell hack/selinux_tag.sh)

Expand Down Expand Up @@ -135,7 +135,7 @@ docs/%.1: docs/%.1.md .gopathok

docs: $(MANPAGES)

install: .gopathok install.bin install.man
install: .gopathok install.bin install.man install.cni

install.bin:
install ${SELINUXOPT} -D -m 755 bin/kpod $(BINDIR)/kpod
Expand All @@ -153,6 +153,10 @@ install.completions:
install ${SELINUXOPT} -d -m 755 ${BASHINSTALLDIR}
install ${SELINUXOPT} -m 644 -D completions/bash/kpod ${BASHINSTALLDIR}

install.cni:
install ${SELINUXOPT} -D -m 644 cni/98-kpod-loopback.conf ${ETCDIR}/cni/net.d/98-kpod-loopback.conf
install ${SELINUXOPT} -m 644 cni/99-kpod-bridge.conf ${ETCDIR}/cni/net.d/99-kpod-bridge.conf

uninstall:
rm -f $(LIBEXECDIR)/crio/conmon
for i in $(filter %.1,$(MANPAGES)); do \
Expand Down
3 changes: 2 additions & 1 deletion cmd/kpod/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ var createFlags = []cli.Flag{
},
cli.StringFlag{
Name: "network",
Usage: "Connect a container to a network (default 'default')",
Usage: "Connect a container to a network",
Value: "bridge",
},
cli.StringSliceFlag{
Name: "network-alias",
Expand Down
18 changes: 9 additions & 9 deletions cmd/kpod/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ func addNetNS(config *createConfig, g *generate.Generator) error {
netMode := config.NetMode
if netMode.IsHost() {
return g.RemoveLinuxNamespace(libpod.NetNamespace)
}
if netMode.IsNone() {
return libpod.ErrNotImplemented
}
if netMode.IsBridge() {
} else if netMode.IsNone() {
return libpod.ErrNotImplemented
}
if netMode.IsContainer() {
} else if netMode.IsBridge() {
return nil
} else if netMode.IsContainer() {
ctr, err := config.Runtime.LookupContainer(netMode.ConnectedContainer())
if err != nil {
return errors.Wrapf(err, "container %q not found", netMode.ConnectedContainer())
Expand All @@ -93,6 +90,8 @@ func addNetNS(config *createConfig, g *generate.Generator) error {
if err := g.AddOrReplaceLinuxNamespace(libpod.NetNamespace, nsPath); err != nil {
return err
}
} else {
return errors.Errorf("unknown network mode")
}
return nil
}
Expand Down Expand Up @@ -531,8 +530,9 @@ func (c *createConfig) GetContainerCreateOptions() ([]libpod.CtrCreateOption, er
options = append(options, libpod.WithName(c.Name))
}
// TODO parse ports into libpod format and include
// TODO should not happen if --net=host
options = append(options, libpod.WithNetNS([]ocicni.PortMapping{}))
if c.NetMode.IsBridge() {
options = append(options, libpod.WithNetNS([]ocicni.PortMapping{}))
}

return options, nil
}
Expand Down
4 changes: 4 additions & 0 deletions cni/98-kpod-loopback.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cniVersion": "0.2.0",
"type": "loopback"
}
15 changes: 15 additions & 0 deletions cni/99-kpod-bridge.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have copies of these in contrib/cni - can you either delete those, or move these there?

"cniVersion": "0.3.0",
"name": "kpod",
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"subnet": "10.88.0.0/16",
"routes": [
{ "dst": "0.0.0.0/0" }
]
}
}
33 changes: 2 additions & 31 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if [ -e /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
filelabel=$(awk -F'"' '/^file.*=.*/ {print $2}' /etc/selinux/${SELINUXTYPE}/contexts/lxc_contexts)
chcon -R ${filelabel} $TESTDIR
fi
LIBPOD_CNI_CONFIG="$TESTDIR/cni/net.d/"
LIBPOD_CNI_CONFIG="/etc/cni/net.d/"
LIBPOD_CNI_PLUGIN=${LIBPOD_CNI_PLUGIN:-/opt/cni/bin/}
POD_CIDR="10.88.0.0/16"
POD_CIDR_MASK="10.88.*.*"
Expand Down Expand Up @@ -193,36 +193,6 @@ function is_apparmor_enabled() {
echo 0
}

function prepare_network_conf() {
mkdir -p $LIBPOD_CNI_CONFIG
cat >$LIBPOD_CNI_CONFIG/10-crio.conf <<-EOF
{
"cniVersion": "0.2.0",
"name": "crionet",
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"subnet": "10.20.40.0/24",
"routes": [
{ "dst": "0.0.0.0/0" }
]
}
}
EOF

cat >$LIBPOD_CNI_CONFIG/99-loopback.conf <<-EOF
{
"cniVersion": "0.2.0",
"type": "loopback"
}
EOF

echo 0
}

function prepare_plugin_test_args_network_conf() {
mkdir -p $LIBPOD_CNI_CONFIG
cat >$LIBPOD_CNI_CONFIG/10-plugin-test-args.conf <<-EOF
Expand All @@ -240,6 +210,7 @@ function prepare_plugin_test_args_network_conf() {
{ "dst": "0.0.0.0/0" }
]
}
skip ""
}
EOF

Expand Down
1 change: 0 additions & 1 deletion test/kpod_attach.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load helpers

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_diff.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load helpers

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_export.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_history.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
4 changes: 0 additions & 4 deletions test/kpod_images.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ load helpers

IMAGE="busybox"

function setup() {
prepare_network_conf
}

function teardown() {
cleanup_test
}
Expand Down
1 change: 0 additions & 1 deletion test/kpod_import.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_inspect.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_load.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load helpers

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_logs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_mount.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
23 changes: 23 additions & 0 deletions test/kpod_networking.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bats

load helpers

function teardown() {
cleanup_test
}

function setup() {
copy_images
}

@test "test network connection with default bridge" {
run ${KPOD_BINARY} ${KPOD_OPTIONS} run -dt ${ALPINE} wget www.yahoo.com
echo "$output"
[ "$status" -eq 0 ]
}

@test "test network connection with host" {
run ${KPOD_BINARY} ${KPOD_OPTIONS} run -dt --network host ${ALPINE} wget www.yahoo.com
echo "$output"
[ "$status" -eq 0 ]
}
1 change: 0 additions & 1 deletion test/kpod_pause.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load helpers

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_ps.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ load helpers

IMAGE="redis:alpine"
function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_push.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_rm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load helpers

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_run_ns.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_save.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_start.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load helpers

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_stats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_stop.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_top.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function teardown() {
}

function setup() {
prepare_network_conf
copy_images
}

Expand Down
1 change: 0 additions & 1 deletion test/kpod_wait.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load helpers

function setup() {
prepare_network_conf
copy_images
}

Expand Down