5.2 KiB
Entrypoints
This document describes the various ways that weave as a binary gets launched, and where and how it processes options.
The goal is to enable maintainers to modify functionality without having to reverse engineer the code to find all of the places you can start a weave binary and what it depends upon.
Components
weaver
weaver is the primary binary: it sets up the weave bridge to which containers are attached, manages IP address allocation, serves DNS requests and does many more things.
Since version 2.0, weaver also bundles the Docker Plugin (legacy version) and Docker API Proxy which used to be shipped as separate containers.
weaveutil
weaveutil is a binary which provides a number of functions for managing an existing weave network. It gets information about the network, attaches and detaches containers, etc.
For the majority of interactions with an existing weave network, you will launch weaveutil in some manner or another.
Almost all options can be passed as --option to weaveutil. These options are created in prog/weaveutil/main.go with a table mapping each command to a dedicated golang function.
In addition to operating in normal mode, weaveutil has several additional operating modes. Before processing any commands, weaveutil checks the filename with which it was called.
- If it was
weave-ipamit delegates responsibility to thecniIPAM()function inprog/weaveutil/cni.go, which, in turn, calls the standard CNI plugin functioncni.PluginMain(), passing it weave's IPAM implementation fromplugin/ipam. - If it was
weave-netit delegates responsibility to thecniNet()function inprog/weaveutil/cni.go, which, in turn, calls the standard CNI plugin functioncni.PluginMain(), passing it weave's net plugin implementation fromplugin/net.
Finally, weaveutil is called by weaver when it needs to operate in a different network namespace.
Go programs cannot safely switch namespaces; see this issue.
The call chain is weaver->nsenter->weaveutil.
weave
Wrapping weaver and weaveutil is weave, a sh script that provides help information and calls weaveutil as relevant.
weave-kube
weave-kube is an image with the weave binaries and a wrapper script installed. It is responsible for:
- Setting up the weave network
- Connecting to peers
- Copy the weave CNI-compatible binary plugin
weaveutilto/opt/cni/bin/weave-netand weave config in/etc/cni/net.d/10-weave.conf - Running the weave network policy controller (weave-npc) to implement kubernetes'
NetworkPolicy
Once installation is complete, each network-relevant change in a container leads kubelet to:
- Set certain environment variables to configure the CNI plugin, mostly related to the container ID
- Launch
/opt/cni/bin/weave-net - Pass the CNI config - the contents of
/etc/cni/net.d/10-weave.conftoweave-net
Thus, when each container is changed, and kubelet calls weave as a CNI plugin, it really just is launching weaveutil as weave-net.
The installation and setup of all of the above - and therefore the entrypoint to the weave-kube image - is the script prog/weave-kube/launch.sh. launch.sh does the following:
- Read configuration variables from the environment. When the documentation for
weave-kubedescribes configuring the weave network by changing the environment variables in the daemonset in the.ymlfile,launch.shreads these environment variables. - Set up the config file at
/etc/cni/net.d/10-weave.conf - Run the
weaveinitialization script - Run
weaverwith the correct configuration passed as command-line options
Adding Options
To add new options to how weave should run with each invocation, you would do the following:
- determine to which
weavecommand you want to add the option(s).weavenormally is launched asweave <command> <options> .... - Add the option to
weavescript help for eachweavecommand you wish to make it available. As of this writing, all of the commands and their options are listed in the functionusage_no_exist(). - Add the option to
weavescript option processing for theweavecommand, under thecase $COMMAND inin the mainweavescript. - In the function for the
weavecommand, determine if the command should be passed on toweaveutilorweaver. Pass the option on toweaveutilorweaver, as appropriate, in the format--option, in the function for theweavecommand. - Add a command-line option
--optiontoweaveutilorweaveras appropriate. - If the option can be configured for CNI:
- have
prog/weave-kube/launch.shread it as an environment variable and set inside - set a default for the environment variable in
prog/weave-kube/weave-daemonset-k8s-1.6.yamlandweave-daemonset.yaml - if it should be set via
weaverglobally on its one-time initialization invocation, pass it on inlaunch.sh - if it needs to be set via
weaveutilon each invocation ofweave-net, havelaunch.shsave it as an option in the CNI config file/etc/cni/net.d/10-weave.confand then have the CNI code inplugin/net/cni.goinweaveutilread it and use where appropriate
- have
- Document it!