245eb078f4
This commit reimplements the kuryr-cni, that is the actual CNI plugin that gets called by kubelet and passes the request to kuryr-daemon, in golang. This means that it can injected as a binary without any dependencies, instead of using a bash script that looks for ID of kuryr-daemon container and does `docker exec` to run Python kuryr-cni inside. The obvious advantage of that is removing a constraint of python, curl and docker/runc binaries being available on any K8s host that runs Kuryr. This enables integration with Magnum, where kubelet runs in such a minimal container. Besides that injecting a binary is way more elegant and less error-prone. The golang implementation should keep the compatibility with Python one. Also currently only containerized jobs are switched to use it, so Python implementation is still kept in the repo. I'm not against removing it in very near future. Please note that there is an important limitation in comparison to the Python implementation - i.e. in case of golang binary running on K8s host, we don't have an easy access to kuryr.conf, meaning that localhost:50036 is currently hardcoded as the kuryr-daemon endpoint. This should be fixed by putting the configured endpoint into 10-kuryr.conf file that gets injected onto the host by cni_ds_init script. Implements: blueprint golang-kuryr-cni Change-Id: Ia241fb5b2937c63d3ed6e3de1ac3003e370e4db6 |
||
---|---|---|
.. | ||
.gitignore | ||
.travis.yml | ||
appveyor.yml | ||
errors.go | ||
LICENSE | ||
README.md | ||
stack.go |
errors
Package errors provides simple error handling primitives.
go get github.com/pkg/errors
The traditional error handling idiom in Go is roughly akin to
if err != nil {
return err
}
which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.
Adding context to an error
The errors.Wrap function returns a new error that adds context to the original error. For example
_, err := ioutil.ReadAll(r)
if err != nil {
return errors.Wrap(err, "read failed")
}
Retrieving the cause of an error
Using errors.Wrap
constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by errors.Cause
.
type causer interface {
Cause() error
}
errors.Cause
will recursively retrieve the topmost error which does not implement causer
, which is assumed to be the original cause. For example:
switch err := errors.Cause(err).(type) {
case *MyError:
// handle specifically
default:
// unknown error
}
Read the package documentation for more information.
Contributing
We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high.
Before proposing a change, please discuss your change by raising an issue.
License
BSD-2-Clause