103 Commits

Author SHA1 Message Date
Angus Lees
2b019bfde1 pkg/ns: evaluate syscall number at compile-time
Previously this code used a run-time map lookup keyed by
runtime.GOOS/GOARCH.  This version uses conditional compilation to make
this choice at compile time, giving immediate feedback for unsupported
platforms.
2016-05-17 18:36:29 +02:00
Angus Lees
a2f23f5a84 pkg/ns: use correct syscall number on arm 2016-05-17 18:36:22 +02:00
Stefan Junker
ed5f8dfeb2 *: appc/cni -> containernetworking/cni
The project has been moved so internally we simply rename everything.
Consumers are recommended to update their vendored version of cni.
2016-05-06 16:40:27 +02:00
Stefan Junker
911d941794 Merge pull request #187 from appc/v0.3.0
merge unneeded branch v0.3.0 into master
2016-04-22 19:25:54 +02:00
Zach Gershman
57b28f3936 Merge pull request #182 from rosenhouse/document-lockosthread
Document use of goroutine and LockOSThread in test helpers
2016-04-18 10:45:46 -07:00
Dan Williams
07a993dc7d ns: fix reading net namespace in multi-threaded processes
/proc/self/ns/net gives the main thread's namespace, not necessarily
the namespace of the thread that's running the testcases.  This causes
sporadic failures of the tests.

For example, with a testcase reading inodes after switching netns:

/proc/27686/task/27689/ns/net 4026532565
/proc/self/ns/net 4026531969
/proc/27686/task/27689/ns/net 4026532565

See also:
008d17ae00

Running Suite: pkg/ns Suite
===========================
Random Seed: 1459953577
Will run 6 of 6 specs

• Failure [0.028 seconds]
Linux namespace operations
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:167
  WithNetNS
  /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:166
    executes the callback within the target network namespace [It]
    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:97

    Expected
        <uint64>: 4026531969
    to equal
        <uint64>: 4026532565

    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96
------------------------------
•••••

Summarizing 1 Failure:

[Fail] Linux namespace operations WithNetNS [It] executes the callback within the target network namespace
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96

Ran 6 of 6 Specs in 0.564 seconds
FAIL! -- 5 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestNs (0.56s)
FAIL
2016-04-18 10:35:23 -05:00
Gabe Rosenhouse
94c4b25698 Document use of goroutine and lockosthread in test helpers 2016-04-17 20:27:02 -07:00
Gabe Rosenhouse
e3fb7ce3a7 Fix issues with MakeNetworkNS test helper 2016-04-17 19:47:54 -07:00
Gabe Rosenhouse
dd3b85c9cc Add basic unit tests of testhelpers 2016-04-17 19:25:39 -07:00
Gabe Rosenhouse
54d7f73092 Extract inode inspection functions into testhelpers 2016-04-17 18:35:49 -07:00
Gabe Rosenhouse
5d932e4716 Extract testhelpers from loopback test suite 2016-04-17 18:28:10 -07:00
Piotr Skamruk
72bec92851 pkg/utils: add functions to work with sysctl 2016-04-07 21:40:51 +02:00
Jonathan Boulle
f6135c7ba3 *: add missing license headers + check 2016-04-01 15:35:21 +02:00
Stefan Junker
897766d74b pkg/utils: correct the test's expected chain names 2016-03-31 18:01:32 +02:00
Stefan Junker
6aad63055c *: add comment to iptables rules for ipmasq 2016-03-31 18:01:32 +02:00
Stefan Junker
bcef17daac pkg/utils: remove unneeded condition in tests 2016-03-31 18:01:32 +02:00
Stefan Junker
77759626a8 pkg/utils: fix docstring 2016-03-31 18:01:32 +02:00
Stefan Junker
53d9cee00a pkg/utils: split and unexport constants 2016-03-31 18:01:32 +02:00
Stefan Junker
bc44d1227d pkg/utils: fix docstring 2016-03-31 18:01:32 +02:00
Stefan Junker
3e6069cab5 pkg/utils: use constant for chain prefix 2016-03-31 18:01:32 +02:00
Stefan Junker
09248dfad9 pkg/utils: use name+id for hash and extend tests 2016-03-31 18:01:32 +02:00
Abhishek Chanda
c33daf6706 pkg: add a function to generate chain names
Adds a function to generate chain names for use in iptables and
ports all drivers to use that function. Also adds tests for the
said function.
2016-03-31 18:01:32 +02:00
Stefan Junker
8916a7ea5f pkg/types: add tests for args 2016-03-21 20:40:39 +01:00
Stefan Junker
5a39a168f7 pkg/types: add IgnoreUnknown arg and logic
This commit adds a struct type CommonArgs that is to be embedded in
every plugin's argument struct. It contains a field named
"IgnoreUnknown" which will be parsed as a boolean and can be provided to
ignore unknown arguments passed to the plugin.
2016-03-21 20:36:05 +01:00
Stefan Junker
a6c5d80661 pkg/skel: add rudimentary unit tests
This is an attempt to testing the PluginMain() function of the skel pkg.
We should be able to do better by using a mockable interface for the
plugins, but this is a start.
2016-03-18 22:34:29 +01:00
Gabe Rosenhouse
2251ee1d0c Update docstring on WithNetNS 2016-03-15 08:37:00 -07:00
Gabe Rosenhouse
9356e23554 WithNetNS restores original namespace when callback errors
- adds test coverage of WithNetNS in BDD-style
2016-03-15 01:51:58 -07:00
Michael Bridgen
719a1db54b Add invoke.Delegate{Add,Del} for use by meta-plugins
The 'flannel' meta plugin delegates to other plugins to do the actual
OS-level work. It used the ipam.Exec{Add,Del} procedures for this
delegation, since those do precisely what's needed.

However this is a bit misleading, since the flannel plugin _isn't_
doing this for IPAM, and the ipam.Exec* procedures aren't doing
something specific to IPAM plugins.

So: anticipating that there may be more meta plugins that want to
delegate in the same way, this commit moves generic delegation
procedures to `pkg/invoke`, and makes the `pkg/ipam` procedures (still
used, accurately, in the non-meta plugins) shims.
2016-03-04 11:01:22 +00:00
Stefan Junker
c44bc010ab Merge pull request #120 from zachgersh/find-better-error
Better error messages when plugin is not found
2016-03-02 11:14:50 +01:00
André Martins
7b53bb9455 added the String method to Result type
Signed-off-by: André Martins <aanm90@gmail.com>
2016-02-19 17:40:46 +00:00
Zachary Gershman
290717d6fe Better error message when plugin cannot be found 2016-02-10 13:42:10 -08:00
Stefan Junker
137dc8a673 *: reflect SPEC's DNS changes in implementation
* DNS is now a type which will result in a JSON dictionary in
  configurations and results
* Minor refactoring, making use of type embedding
2016-01-29 10:39:28 +01:00
Alban Crequy
2f9ef4adb7 *: add "dns" field to the configuration
appc/cni#76 added a "dns" field in the result JSON. But before this
patch, the plugins had no way of knowing which name server to return.

There could be two ways of knowing which name server to return:
1. add it as an extra argument ("CNI_ARGS")
2. add it in the network configuration as a convenience (received via
   stdin)

I chose the second way because it is easier. In the case of rkt, it
means the user could just add the DNS name servers in
/etc/rkt/net.d/mynetwork.conf.
2016-01-26 18:54:56 +01:00
Derek Gonyeo
fd64ee6ade pkg/ip: fix typo in error message, s/iptabes/iptables/ 2015-12-16 13:20:19 -08:00
Eugene Yakubovich
0becca2e96 Change copyright from CoreOS to CNI authors
CNI is developed by more than just CoreOS, Inc
and the copyright is retained by all CNI
contributors (for their respective contributed code).
2015-09-29 11:51:33 -07:00
Stefan Junker
5b7aa09e52 link: switch to host netns to set up host veth end 2015-09-24 18:49:27 +02:00
Stefan Junker
f1c9c632e1 Revert "plugins/ptp: allow host veth to be UP"
This reverts commit 231d2d5a27f3ba54219c3f0b1c8ef2c5dab4faaf.
2015-09-24 18:32:18 +02:00
Stefan Junker
231d2d5a27 plugins/ptp: allow host veth to be UP 2015-09-24 10:57:36 +02:00
Eugene Yakubovich
9ea56937d4 bug fix: exec of DEL cmd caused JSON decode error
When plugin is executed with a DEL command, it does not
print result to stdout unless there is an error. Therefore
it stdout bytes should not be passed to json.Unmarshal.
2015-09-18 10:30:10 -07:00
Michael Bridgen
b88f173c43 Factor an API out into a module
This takes some of the machinery from CNI and from the rkt networking
code, and turns it into a library that can be linked into go apps.

Included is an example command-line application that uses the library,
called `cnitool`.

Other headline changes:

 * Plugin exec'ing is factored out

The motivation here is to factor out the protocol for invoking
plugins. To that end, a generalisation of the code from api.go and
pkg/plugin/ipam.go goes into pkg/invoke/exec.go.

 * Move argument-handling and conf-loading into public API

The fact that the arguments get turned into an environment for the
plugin is incidental to the API; so, provide a way of supplying them
as a struct or saying "just use the same arguments as I got" (the
latter is for IPAM plugins).
2015-09-16 10:14:39 +01:00
Neil Wilson
2d0d4b35e1 plugin/ipam: correct formatting of error message 2015-09-08 18:08:15 +00:00
Neil Wilson
8462a3f607 IPAM plugin: improve error messages
Make it more clear that we failed to find an IPAM plugin.
Check for a missing plugin name and issue a more helpful error.
2015-09-08 18:08:15 +00:00
Jonathan Boulle
7478744cf5 plugin/ipam: fix typo in error message 2015-09-07 15:43:34 -07:00
Stefan Junker
8b634b90da CNI_ARGS: use ';' to split args as documented 2015-09-05 18:58:58 +02:00
Stefan Junker
1d398af124 host-local: allow ip request via CNI_ARGS
A specific IP can now be requested via the environment variable CNI_ARGS, e.g.
`CNI_ARGS=ip=1.2.3.4`.
The plugin will try to reserve the specified IP.
If this is not successful the execution will fail.
2015-09-04 01:38:22 +02:00
Eugene Yakubovich
91454b6ebb enable net.ipv4.ip_forward in plugins that need it 2015-07-13 15:41:02 -07:00
Eugene Yakubovich
16680be42d No more path rewriting
Path rewriting causes too many problems when vendoring
vendored code. When CNI code is vendored into rkt,
godep has problems code already vendored by CNI.
2015-06-12 16:29:18 -07:00
Eugene Yakubovich
33a575f49d Propagate json error object to the caller
When plugin errors out, it prints out a JSON object to stdout
describing the failure. This object needs to be propagated out
through the plugins and to the container runtime. This change
also adds Print method to both the result and error structs
for easy serialization to stdout.
2015-06-09 10:46:28 -07:00
Eugene Yakubovich
c70320b5ed add DHCP IPAM plugin
The plugin binary actually functions in two modes. The first mode
is a regular CNI plugin. The second mode (when stared with "daemon" arg)
runs a DHCP client daemon. When executed as a CNI plugin, it issues
an RPC request to the daemon for actual processing. The daemon is
required since a DHCP lease needs to be maintained by periodically
renewing it. One instance of the daemon can server arbitrary number
of containers/leases.
2015-05-21 13:36:51 -07:00
Eugene Yakubovich
601f991ee5 Merge pull request #9 from eyakubovich/errors
report errors via JSON
2015-05-08 15:08:03 -07:00