lazyjack

package module
v1.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

README

Lazyjack

Lazyjacks are rigging used to assist in sail handling during reefing and furling, making the process easier.

In keeping with the nautical theme of Kubernetes, the lazyjack application is used to make it easier to provision bare-metal systems that they can be used with Kubernetes/Istio in an IPv6-only environment. It has been enhanced to handle an IPv4-only environment as well.

The goal is to reduce as many manual steps as possible, so that provisioning of systems can occur quickly. This is geared to a lab environment, where the user is using KubeAdm or similar tool to bring up Kubernetes.

Quick Start Guide

For the impatient, you can do the following to bring up cluster of two (or more) nodes. See below for details on each step.

  1. Provision the hardware with OS and the pre-requisite tools.
  2. Install Lazyjack on all systems.
  3. Modify the sample config file using the hosts/interfaces for your topology.
  4. Run init command on master.
  5. Copy updated config file to minions.
  6. Run prepare on each node.
  7. Run up on master, and then on minions.

A bit about IPv6 and Kubernetes...

Starting with Kubernetes 1.9, there is alpha support for IPv6 only (not dual stack) mode of operation for pods and services. There are various plugins that have or are adding support for IPv6. The reference Bridge plugin, has support and will be used by Lazyjack.

Currently, there are some external sites, like github.com, which do not support IPv6 yet. As a result, the Kubernetes installation in 1.9+ uses DNS64 and NAT64 to access the outside world. With this solution, a DNS64 and NAT64 server will be employed via containers, rather than relying on external H/W or S/W.

How does this all work?

Once the bare-metals systems have met the prerequisites shown below, you can create a configuration file for your topology, and then run Lazyjack commands on each node to prepare and run Kubernetes.

When done, you can use Lazyjack commands to clean up the systems, effectively undoing the setup made and restoring the system to original state.

Prerequisites

The following needs to be done, prior to using this tool:

  • One or more bare-metal systems running Linux (tested with Ubuntu 16.04), each with:
    • Two interfaces, one for access to box, one for management network for cluster.
    • Make sure management interface doesn't have a conflicting IP address.
    • Internet access via IPv4 on the node being used for DNS64/NAT64 (V6).
    • Docker (17.03.2) installed.
    • Version 1.11+ of kubeadm, kubectl (on master), and kubelet.
    • Go 1.10.3+ installed on the system and environment set up (may need newer with later releases of K8s).
    • CNI 0.7.1+ installed.
    • openssl installed on system (I used 1.0.2g).
    • (optional) Internet access via IPv6 for direct IPv6 access to external sites.
      • IPv6 enabled on node.
      • IPv6 address on main interface with Internet connectivity.
      • Default route for IPv6 traffic using main interface of nodes.
      • Setting sysctl accept_ra=2 on main I/F (e.g. net.ipv6.conf.eth0.accept_ra = 2) of nodes.
  • Install Lazyjack and config file on each system (see below).

Preparing Lazyjack

The easiest way to install lazyjack is to pull down the latest release. For example:

mkdir ~/bare-metal
cd ~/bare-metal
wget https://github.com/pmichali/lazyjack/releases/download/v1.0.0/lazyjack_1.0.0_linux_amd64.tar.gz
tar -xzf lazyjack_1.0.0_linux_amd64.tar.gz
sudo cp lazyjack /usr/local/bin

This will provide the executable and a sample configuration YAML file.

Alternately, you can get the code:

go get github.com/pmichali/lazyjack
cd $GOPATH/src/github.com/pmichali/lazyjack

Build an executable, and place it where desired for easy access. For example:

go build cmd/lazyjack.go
sudo cp lazyjack /usr/local/bin/

Copy this executable, and the associated configuration YAML file (see next section) to each system to be provisioned.

Configuration Setup

Lazyjack is driven by a YAML configuration file that specifies the topology for the entire cluster, the roles that nodes play, and the values to use for subnets, CIDRs, and IPs.

You can use the default (config.yaml) or specify the configuration file on the command line using the --config option.

We'll take a look at an example file and disect each section.

Example
general:
    token: "<provide-token>"
    token-cert-hash: "<provide-cert-hash>"
    plugin: bridge
    work-area: "/tmp/lazyjack"
    mode: "ipv6"
    kubernetes-version: "v1.12.0"
    insecure: true
topology:
  my-master:
    interface: "enp10s0"
    opmodes: "master dns64 nat64"
    id: 2
  a-minion:
    interface: "eth0"
    opmodes: "minion"
    id: 3
support_net:
    cidr: "fd00:10::/64"
    v4cidr: "172.18.0.0/16"
mgmt_net:
    cidr: "10.192.0.0/16"
    cidr2: "fd00:20::/64"
pod_net:
    cidr: "10.244.0.0/16"
    cidr2: "fd00:40::/72"
    mtu: 9000
service_net:
    cidr: "fd00:30::/110"
nat64:
    v4_cidr: "172.18.0.128/25"
    v4_ip: "172.18.0.200"
    ip: "fd00:10::200"
dns64:
    remote_server: "64.102.6.247"
    cidr: "fd00:10:64:ff9b::/96"
    ip: "fd00:10::100"
    allow_aaaa_use: true
Token (token) and Token CA Certificate Hash (token-cert-hash)

KubeAdm uses a token and CA certificate for nodes to communicate. These two fields are filled out automatically by the init command, which needs to be run on the master node, before copying the configuration file over to minion nodes for use in the up command. You don't need to set these.

Plugin (plugin)

Lazyjack will support both the Bridge and PTP plugins. Use either "bridge", or "ptp", respectively.

Work Area (work-area)

By default, the /tmp/lazyjack area is used to place configuration files, certificates, etc. that are used by lazyjack. For security purposes, you should select a secure location, by overriding the value in this field. On each init run, the area is deleted and recreated, with permissions restricting write access to user and group.

Mode (mode)

The default is IPv6, but ipv4 may be specified as of version 1.3.0, and dual-stack may be used as of 1.3.5.

Kuberentes Version (kubernetes-version)

Optional setting, where you can specify the version of Kubernetes to be used. If specified, this can be "latest" to use the latest code on master, or a version number of the form "v#.#.#" or "v#.#.#-X", where X is additional version info, like "alpha.1" or "dirty". When a number is specified, the major and minor version must match that of KubeAdm.

If omitted, the version of KubeAdm will be used to specify the Kubernetes version.

NOTE: If you are using an un-released version, it may be beneficial to set this to latest.

Insecure mode (insecure)

This optional boolean flag can be set to allow KubeAdm to run without specifying an auth token. This means that the init step is not needed, and the config YAML file does not need to be copied over to the minions, after the prepare step, thus simplifying startup for a non-production environment.

Topology (topology)

This is where you specify each of the systems to be provisioned. Each entry is referred to by the hostname, and contains three items.

First, the name of the interface to be used for the management of the cluster during operation. I used the second interface on my systems (the first being used to access the systems for provisioning), and had them on the same VLAN, connected to the same switch in the lab.

    interface: "eth1"

Second, an arbitrary ID (id) is assigned to each node. Use 2+ as the ID, as this will be used in IPs and subnets (the app doesn't validate this - yet).

    id: 100

Third, the operational mode (opmode) of the system. This string can have the value master or minion (only specify one master per cluster). It can also have the values dns64 and nat64 (again only specify these once) for IPv6 mode.

    opmodes: "master dns64 nat64"

Currently, the dns64 and nat64 settings must be on the same system (will see if it makes sense to allow them on separate nodes). They can accompany a master or minion, or can be on a node by themselves.

Support Network (support_net)

This section is only used, when operating in ipv6 mode. The entries are ignore for IPv4. For the NAT64 and DNS64 services, which are running in containers, we need a network that has both V4 and V6 addresses. This section of the YAML file specifies the IPv6 CIDR, and the IPv4 CIDR:

    cidr: "fd00:10::/64"
    v4cidr: "172.18.0.0/16"

The IPv4 subnet should be large enough to contain the V4 subnet that will be created for NAT64 mapping of V6 to V4 addresses. A /16 net is usually fine (Lazyjack doesn't validate this requirement, currently).

Management Network (mgmt_net)

The network that is used by Kubernetes for each cluster node, is called out in this section.

    cidr: "fd00:20::/64"

For IPv4, this must be a /8 or /16 CIDR. This allows multiple clusters to use the third octet for the cluster ID. For example:

    cidr: "10.192.0.0/16"

For dual-stack, you specify both IPv4 and IPv6 CIDRs and use cidr2 for the second entry.

NOTE: An IP(s) is(are) added to the specified interface on prepare and removed on down, so it is advised to not use the main interface used to access the node, as may loose connectivity.

Pod Network (pod_net)

A second network that is used by Kubernetes for the pods. This network should be distint from the support and management networks. Here, we specify the CIDR for the pod cluster. Inside this network, each node will carve out a subnet, using the node "ID" as the last part of the address.

    cidr: "fd00:40::/72"

In the example configuration, we would have a pod subnet fd00:40:0:0:2::/80 on node my-master and fd00:40:0:0:3::/80 on node a-minion. If you want to specify the prefix and size, the prefix must be fully qualified (e.g. in this case fd00:40:0:0:) and the size must be the size allocated to the node (e.g. 80).

For IPv4, this must be a /16 CIDR. Each node will carve out a /24 subnet, using the node "ID" as the third octet of the address. For example:

    cidr: "10.244.0.0/16"

For dual-stack, you specify both IPv4 and IPv6 CIDRs and use cidr2 for the second entry.

Optionally, you can set the MTU used on the interface for the pod and management networks, on each node. Use the following, under the pod_net section.

    mtu: 9000
Service Network (service_net)

Specify the network CIDR to be used for service pods. This should be a smaller network than the pod subnet?

    cidr: "fd00:30::/110"

For IPv4, this must be a subnet that is larger than /24. For example:

    cidr: "10.96.0.0/12"

For dual-stack, you must specify either an IPv4 or IPv6 CIDR, which will be used for the service network.

NOTE: As of Kubernetes 1.13, the KEP for dual-stack support was under development and implementation of support was being started. As a result, some functionality, like seeing both IPs for a pod, are not operational (although the pods have both IP addresses).

NAT64 (nat64)

For IPv6 mode, to be able to reach external sites that only support IPv4, we use NAT64 (which is combined with Docker's NAT44 capabilities) to translate between external IPv4 addresses and internal IPv6 addresses. To do this, it needs IPv4 access to the Internet, and uses NAT44 via Docker to translate from it's IPv4 address to the public IPv4 address for the host. Tayga (http://www.litech.org/tayga/) is used for this role and runs as a container on the node with nat64 specified as an opmode.

Tayga uses a pool of local IPv4 addresses that are mapped to IPv6 address. As such, the IPv4 pool and IPv4 address of Tayga must be specified. Lazyjack checks to make sure that both of these are inside of the support_net subnet, mentioned above.

    v4_cidr: "172.18.0.128/25"
    v4_ip: "172.18.0.200"

Also, specify the IPv6 address of Tayga on the support_net IPv6 subnet.

ip: "fd00:10::200"

For dual-stack, this section is not specified.

DNS64 (dns64)

For IPv6 mode, a companion to NAT64, the DNS64 container using bind9 will provide synthesized IPv6 addresses for external IPv4 addresses (currently, it does so for all addresses). The CIDR used for this translation is specified in this section.

    cidr: "fd00:10:64:ff9b::/96"

An external address with a IPv4 address of 172.217.12.238, would be encoded as fd00:10:64:ff9b::acd9:cee/96.

The DNS64 container will forward DNS requests to a remote DNS server, which is also specified.

    remote_server: "64.102.6.247"

The support_net IPv6 address of the bind9 server needs to be specified.

    ip: "fd00:10::100"

If the topology supports accessing the Internet via IPv6, the following can be set to allow external IPv6 addresses to be used directly, instead of translating them to IPv4 addresses using NAT64. To do this, requires telling DNS64 to use the AAAA records for lookups. The default is false, meaning IPv4 addresses will be used in all lookups.

    allow_aaaa_use: true

For dual-stack, this section is not specified.

Usage

As mentioned above, you should have Lazyjack and the YAML file on each system to be provisioned. Since Lazyjack needs to perform privileged operations, you'll need to run this as root:

   sudo ~/go/bin/lazyjack [options] {init|prepare|up|down|clean|version}

The commands do the following:

  • init - Sets up tokens and certificates needed by Kuberentes. Must be run on the master node, before copying the config file to minion nodes. Only needed once. Not needed, if running in insecure mode.
  • prepare - Prepares the node so that cluster can be brought up. Do on each node, before proceeded to next step.
  • up - Brings up Kubernetes cluster on the node. Do master first, and then minions.
  • down - Tears down the cluster on the node. Do minions first, and then master.
  • clean - Reverses the prepare steps performed to clear out settings.
  • version - Shows the version of this app and exits.

Once a cluster is up on the master, you can setup kubectl, as described by the KubeAdm init command:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Command Line Options
Usage: lazyjack [options] {init|prepare|up|down|clean|version}
  -alsologtostderr
        log to standard error as well as files
  -config string
        Configurations for lazyjack (default "config.yaml")
  -host string
        Name of (this) host to apply command (default "my-master")
  -log_backtrace_at value
        when logging hits line file:N, emit a stack trace
  -log_dir string
        If non-empty, write log files in this directory
  -logtostderr
        log to standard error instead of files
  -stderrthreshold value
        logs at or above this threshold go to stderr
  -v value
        log level for V logs
  -vmodule value
        comma-separated list of pattern=N settings for file-filtered logging

There are log level "1" and "4" entries in the app, if you want verbose logging. The log defaults to stderr.

The default hostname is the name of the system you are on.

Under The Covers

For each command, there are a series of actions performed...

For the init command
  • Creates CA certificate and key for KubeAdm.
  • Creates token and CA certificate hash.
  • Updates the configuration YAML file (needed for up command on minions, unless running in insecure mode).
For the prepare command
  • (IPv6) Creates support network with IPv6 and IPv4.
  • (IPv6) Starts DNS64 container, with config file from created volume, removes IPv4 address, and adds route to NAT64 server.
  • (IPv6) Starts NAT64 container.
  • (IPv6) Adds IPv4 route to NAT64 server on node.
  • Adds management network IP on specified interface.
  • Places management network IP in /etc/hosts, for this hostname.
  • Adds DNS64 support network IP as first nameserver in /etc/resolv.conf.
  • Creates a drop-in file for kubelet to specify IPv6 DNS64 server IP.
  • Creates KubeAdm configuration file, saves old one with .bak suffix, in case file customized.
  • (IPv6) Adds route to DNS64 synthesized network via NAT64 server (based on node).
  • (IPv6) Adds route to support network for other nodes to access.
For the up command
  • For Bridge and PTP plugins
    • Creates CNI config file
    • Create routes for each of the pod networks on other nodes. For dual-stack, does for each IP family.
  • Reloaded daemons for services.
  • Restarted kubelet service.
  • On master: Place CA certificate and Key files into Kubernetes area.
  • On master: Perform KubeAdm init command with config file.
  • On minion: Perform KubeAdm join command using token information.
For the down command
  • Perform KubeAdm reset command.
  • Remove routes to other nodes' pod networks.
  • Removes Bridge/PTP plugin's CNI config file.
  • Removes the br0 interface for Bridge plugin
For the clean command
  • Removes drop-in file for kubelet.
  • Removes IP from management interface.
  • Restores /etc/hosts.
  • Restores /etc/resolv.conf.
  • (IPv6) Removes route to NAT64 server for DNS64 synthesized net.
  • (IPv6) Removes route to support network.
  • (IPv6) Stops and removes DNS64 container and volume used for config.
  • (IPv6) Stops and removes NAT64 container.
  • (IPv6) Removes IPv4 route to NAT64 server.
  • (IPv6) Removes support network on DNS64/NAT64 node.

Customizing the cluster

After the prepare command has been invoked, a kubeadm.conf file has been created in the work area. At this point, before the up command is issued, you have the opportunity to tweak the kubeadm.conf file. For example, you can set the following, to use CoreDNS, instead of kube-dns:

featureGates:
  CoreDNS: true

Note: Newer Kubernetes versions default to using CoreDNS.

Another example is turning on IPVS for kube-proxy. The kubeadm.conf file can include:

kubeProxy:
  config:
      mode: "ipvs"

NOTE: You'll need to make sure that the kernel on the nodes support IPVS or you must load the IPVS modules. For example, on Ubuntu 16.04:

sudo su
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4

cut -f1 -d " "  /proc/modules | grep -e ip_vs -e nf_conntrack_ipv4

I also installed ipset and ipvsadm.

Limitations/Restrictions

  • Some newer versions of docker break the enabling of IPv6 in the containers used for DNS64 and NAT64.
  • CNI v0.7.1+ is needed for full IPv6 support by plugins.
  • Relies on the tayga and bind6 containers (as provided by other developers), for IPv6 only mode.
  • The init command modifies the specified configuration YAML file. As a result, init must be done before copying the config YAML to other nodes, unless you are running in insecure mode where the init step is not needed and the config YAML is not updated.
  • In normal mode, because the config YAML file is modified by the root user, permissions is set to 777, so that the non-root user can still modify the file.

Troubleshooting

This section has some notes on issues seen and resolutions (if any).

Tips

If for some reason the prepare fails after updating /etc/resolv.conf or /etc/hosts, you can recover the originals from the .bak files created. However, the tool is designed to allow multiple invocations, so this should not be required.

If a system is rebooted, the entire process (init, copy config, prepare, and up) must be performed, because some changes are not persisted, and some files are created in /tmp by default (but can be configured to different area).

On a related note, you want to make sure that the node does not already have incompatible configuration on being interfaces or for routes that will be defined.

Ping failures

I had one case where I could not ping from a pod on one node, to a pod on another (but it worked in the reverse direction). Looks like an issue with some stray IPTABLES rules. Found out that I could tear everything down, do the following commands to flush IPTABLES rules, and then bring everything up:

sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X

sudo ip6tables -P INPUT ACCEPT
sudo ip6tables -P FORWARD ACCEPT
sudo ip6tables -P OUTPUT ACCEPT
sudo ip6tables -t nat -F
sudo ip6tables -t mangle -F
sudo ip6tables -F
sudo ip6tables -X

Alternately, I had one case where I just changed the one filter rule to resolve the issue:

sudo iptables -t filter -P FORWARD ACCEPT
Kube-dns failing to startup

I had another case where kube-dns was not coming up, and kube-proxy log was showing IPTABLES restore errors saying "iptables-restore v1.6.0: invalid mask 128' specified". This should be using the ip6tables-restore operation. I was unable to find root cause, but did KubeAdm reset, clean` command, fllush IPTABLES rules (like above), rebooted, and problem was cleared. May have been corruption of IPTABLES rules.

Customizing kubeadm.conf

You can customize kubeadm.conf, after the prepare step, to make any additional changes desired for the configuration (e.g. setting kubernetesVersion to a specific version).

Join failures in 1.10.x

I found out that with Kubernetes 1.10, the minion node fails to join, showing an error indicating that it cannot tell if container runtime is running. I found that this was fixed in 1.11, but there is no backport. As a result, I removed notes about using Lazyjack with versions older than 1.11.

Ref: https://github.com/kubernetes/kubeadm/issues/814

Working on "master" branch with latest

When working with the "latest" code, built locally, instead of using apt-get (on Ubuntu) to install a released version, one has to make sure that kubelet gets installed and configured properly.

For example, using 1.13.0-alpha.1 built from master locally, besides uninstalling any older version of kubelet (which also uninstalls kubeadm), I found that I had to do more than copy the executables into /usr/bin. Specifically, the Service section of the kubelet service config file in /lib/systemd/system/kubelet.service needs to match what was used by released versions, with definitions of environment variables and the ExecStart clause using them to specify the config file and settings. The lines look like this (although you can copy a version of the file from 1.12 an reuse without changes):

[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_EVICTION_ARGS=--eviction-hard='memory.available<100Mi,nodefs.available<100Mi,nodefs.inodesFree<1000'"
Environment="KUBELET_DIND_ARGS="
Environment="KUBELET_LOG_ARGS=--v=4"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_FEATURE_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_EVICTION_ARGS $KUBELET_DIND_ARGS $KUBELET_LOG_ARGS $KUBELET_EXTRA_ARGS
Restart=always
StartLimitInterval=0
RestartSec=10

Without that info, when the kubelet service is started, it will run and tie up port 10250, preventing KubeAdm from starting things up.

Normally, because the ExecStart line calls out a non-existent config file, the service would sit in a loop continuously failing, until the kubeadm init command would load in the needed config file and things would start up as expected.

I also made sure that the /etc/systemd/system/kubelet.service.d/ area did not have any drop-in files (e.g. 10-kubeadm.conf).

Mismatched versions

I had one case where I was running 1.12 on minion, but was running 1.13 on the master and had specified latest as the Kubernetes version in the config YAML. During the up command on the minion, I saw this error:

configmaps "kubelet-config-1.12" is forbidden: User "system:bootstrap:abcdef" cannot get resource "configmaps" in API group "" in the namespace "kube-system"

The solution is to make sure that all nodes have compatible versions of images and that the Kubernetess version is correct.

TODOs/Futures

Implementation
  • Enhance validation
    • Ensure IP addresses, subnets, and all CIDRs are valid.
    • No overlap on pod, management, and support networks.
    • Make sure pod network prefix and size are compatible (prefix should be size - 16 bits).
    • Ensure NAT64 IP is within NAT64 subnet, and that NAT64 subnet is with support subnet.
    • Node IDs > 0. >1?
    • Docker version.
    • Kubeadm, kubectl, kubelet version 1.11+.
    • Go version.
    • CNI plugin version 0.7.1+.
    • Other tools?
  • Support Calico plugin. Cillium? Contiv? Others?
Details to figure out
  • Decide how to handle prepare failures (exits currently). Rollback? Difficulty?
  • Create makefile for building/installing. Build executable for immediate use?
  • Is there a way to check if management interface already has an (incompatible) IPv6 address?
  • Way to timeout on "kubeadm init", if it gets stuck (e.g. kubelet never comes up).
  • Add Continuous Integration tool and tests.
Enhancements to consider
  • Do Istio startup. Useful? Metal LB startup?
  • Running DNS64 and NAT64 on separate nodes. Useful? Routing?
  • Support hypervisors other than Docker (have separated out the code)?
  • Consider using Kubeadm's DynamicKubeletConfig, instead of drop-in file for kubelet.
  • Could skip running kubeadm commands and just display them, for debugging (how to best do that? command line arg?)
  • Could copy /etc/kubernetes/admin.conf to ~/.kube/config and change ownership, if can identify user name.
  • Using separate go routine for kubeadm commands, and provide a (configurable) timeout.
  • Consider including NAT64/DNS64 containers into project to remove dependencies.
  • Bringing up cluster in containers, instead of using separate bare-metal hosts.
  • Setup to allow provisioning without a token (so init step is not needed).
  • Consider allowing any subnet size for management network on v4 and leave to user to ensure room for node ID.
  • Allow IPv4 to use existing I/F on each host (implying not adding IP address or removing it on teardown.

Documentation

Index

Constants

View Source
const (
	// DefaultPlugin if none is specified
	DefaultPlugin = "bridge"
	// SupportNetName used by NAT64/DNS64 server
	SupportNetName = "support_net"

	// ResourceNotPresent status, indicating it can be created
	ResourceNotPresent = "not-present"
	// ResourceRunning status, indicating it is already created
	ResourceRunning = "running"
	// ResourceExists status, indicating that it exists, but is not running
	ResourceExists = "exists"

	// WorkArea where configuration files are placed for running program
	WorkArea = "/tmp/lazyjack"
	// CertArea where certificates and keys are stored
	CertArea = "certs"
	// KubernetesCertArea where KubeAdm references certificates and keys
	KubernetesCertArea = "/etc/kubernetes/pki"

	// DNS64Name name of the DNS64 server
	DNS64Name = "bind9"
	// DNS64Volume name of volume holding DNS64 configuration
	DNS64Volume = "volume-bind9"
	// DNS64NamedConf main configuration file
	DNS64NamedConf = "named.conf"

	// NAT64Name name of NAT64 server
	NAT64Name = "tayga"

	// KubeletSystemdArea where kubelet configuration files are located
	KubeletSystemdArea = "/etc/systemd/system/kubelet.service.d"
	// KubeletDropInFile name of drop-in file being created
	KubeletDropInFile = "20-extra-dns-args.conf"

	// CNIConfArea where CNI config files are stored
	CNIConfArea = "/etc/cni/net.d"
	// CNIConfFile name of the CNI config file
	CNIConfFile = "cni.conf"

	// EtcArea top level area for config files
	EtcArea = "/etc"
	// EtcHostsFile name of the hosts file
	EtcHostsFile = "hosts"
	// EtcHostsBackupFile backup name for hosts file
	EtcHostsBackupFile = "hosts.bak"
	// EtcResolvConfFile name of the nameserver file
	EtcResolvConfFile = "resolv.conf"
	// EtcResolvConfBackupFile backup name for nameserver file
	EtcResolvConfBackupFile = "resolv.conf.bak"

	// KubeAdmConfFile name of the configuration file used by KubeAdm
	KubeAdmConfFile = "kubeadm.conf"

	// DefaultToken used when in insecure mode
	DefaultToken = "abcdef.abcdefghijklmnop"

	// MinimumPodMTU is the smallest MTU for IPv6
	MinimumPodMTU = 1280
	// DefaultPodMTU is the default MTU to use, when not specified
	DefaultPodMTU = 1500

	// IPv6NetMode for IPv6 only networks
	IPv6NetMode = "ipv6"
	// DefaultNetMode default network operating mode
	DefaultNetMode = IPv6NetMode
	// IPv4NetMode for IPv4 only network operating mode
	IPv4NetMode = "ipv4"
	// DualStackNetMode for IPv4/IPv6 network operating mode
	DualStackNetMode = "dual-stack"
)
View Source
const DefaultDockerCommand = "docker"

DefaultDockerCommand command used for docker

Variables

View Source
var Template_v1_10 = template.Must(template.New("v1.10").Parse(`# V1.10 (and older) based config
api:
  advertiseAddress: "{{.AdvertiseAddress}}"
apiServerExtraArgs:
  insecure-bind-address: "{{.BindAddress}}"
  insecure-port: "{{.BindPort}}"
apiVersion: kubeadm.k8s.io/v1alpha1
featureGates: {CoreDNS: {{.UseCoreDNS}}}
kind: MasterConfiguration
{{.K8sVersion}}
networking:
  # podSubnet: "{{.PodNetworkCIDR}}"
  serviceSubnet: "{{.ServiceSubnet}}"
token: "{{.AuthToken}}"
tokenTTL: 0s
nodeName: {{.KubeMasterName}}
unifiedControlPlaneImage: ""
`))

Template_v1_10 kubeadm.conf content template for Kubernetes V1.10

View Source
var Template_v1_11 = template.Must(template.New("v1.11").Parse(`# V1.11 based config
api:
  advertiseAddress: "{{.AdvertiseAddress}}"
  bindPort: 6443
  controlPlaneEndpoint: ""
apiServerExtraArgs:
  insecure-bind-address: "{{.BindAddress}}"
  insecure-port: "{{.BindPort}}"
apiVersion: kubeadm.k8s.io/v1alpha2
auditPolicy:
  logDir: /var/log/kubernetes/audit
  logMaxAge: 2
  path: ""
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: {{.AuthToken}}
  ttl: 0s
  usages:
  - signing
  - authentication
certificatesDir: /etc/kubernetes/pki
# clusterName: kubernetes
etcd:
  local:
    dataDir: /var/lib/etcd
    image: ""
featureGates: {CoreDNS: {{.UseCoreDNS}}}
kind: MasterConfiguration
kubeProxy:
  config:
    bindAddress: "{{.BindAddress}}"
    clientConnection:
      acceptContentTypes: ""
      burst: 10
      contentType: application/vnd.kubernetes.protobuf
      kubeconfig: /var/lib/kube-proxy/kubeconfig.conf
      qps: 5
    # clusterCIDR: ""
    configSyncPeriod: 15m0s
    # conntrack:
    #   max: null
    #   maxPerCore: 32768
    #   min: 131072
    #   tcpCloseWaitTimeout: 1h0m0s
    #   tcpEstablishedTimeout: 24h0m0s
    enableProfiling: false
    healthzBindAddress: 0.0.0.0:10256
    hostnameOverride: ""
    iptables:
      masqueradeAll: false
      masqueradeBit: 14
      minSyncPeriod: 0s
      syncPeriod: 30s
    ipvs:
      excludeCIDRs: null
      minSyncPeriod: 0s
      scheduler: ""
      syncPeriod: 30s
    metricsBindAddress: 127.0.0.1:10249
    mode: ""
    nodePortAddresses: null
    oomScoreAdj: -999
    portRange: ""
    resourceContainer: /kube-proxy
    udpIdleTimeout: 250ms
kubeletConfiguration:
  baseConfig:
    address: 0.0.0.0
    authentication:
      anonymous:
        enabled: false
      webhook:
        cacheTTL: 2m0s
        enabled: true
      x509:
        clientCAFile: /etc/kubernetes/pki/ca.crt
    authorization:
      mode: Webhook
      webhook:
        cacheAuthorizedTTL: 5m0s
        cacheUnauthorizedTTL: 30s
    cgroupDriver: cgroupfs
    cgroupsPerQOS: true
    clusterDNS:
    - "{{.DNS_ServiceIP}}"
    clusterDomain: cluster.local
    containerLogMaxFiles: 5
    containerLogMaxSize: 10Mi
    contentType: application/vnd.kubernetes.protobuf
    cpuCFSQuota: true
    cpuManagerPolicy: none
    cpuManagerReconcilePeriod: 10s
    enableControllerAttachDetach: true
    enableDebuggingHandlers: true
    enforceNodeAllocatable:
    - pods
    eventBurst: 10
    eventRecordQPS: 5
    evictionHard:
      imagefs.available: 15%
      memory.available: 100Mi
      nodefs.available: 10%
      nodefs.inodesFree: 5%
    evictionPressureTransitionPeriod: 5m0s
    failSwapOn: true
    fileCheckFrequency: 20s
    hairpinMode: promiscuous-bridge
    healthzBindAddress: 127.0.0.1
    healthzPort: 10248
    httpCheckFrequency: 20s
    imageGCHighThresholdPercent: 85
    imageGCLowThresholdPercent: 80
    imageMinimumGCAge: 2m0s
    iptablesDropBit: 15
    iptablesMasqueradeBit: 14
    kubeAPIBurst: 10
    kubeAPIQPS: 5
    makeIPTablesUtilChains: true
    maxOpenFiles: 1000000
    maxPods: 110
    nodeStatusUpdateFrequency: 10s
    oomScoreAdj: -999
    podPidsLimit: -1
    # port: 10250
    registryBurst: 10
    registryPullQPS: 5
    resolvConf: /etc/resolv.conf
    rotateCertificates: true
    runtimeRequestTimeout: 2m0s
    serializeImagePulls: true
    staticPodPath: /etc/kubernetes/manifests
    streamingConnectionIdleTimeout: 4h0m0s
    syncFrequency: 1m0s
    volumeStatsAggPeriod: 1m0s
{{.K8sVersion}}
networking:
  # podSubnet: "{{.PodNetworkCIDR}}"
  serviceSubnet: "{{.ServiceSubnet}}"
nodeRegistration:
  name: {{.KubeMasterName}}
unifiedControlPlaneImage: ""
`))

Template_v1_11 kubeadm.conf content template for Kubernetes V1.11

View Source
var Template_v1_12 = template.Must(template.New("v1.12").Parse(`# V1.12 based config
apiEndpoint:
  advertiseAddress: "{{.AdvertiseAddress}}"
  bindPort: 6443
apiVersion: kubeadm.k8s.io/v1alpha3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: {{.AuthToken}}
  ttl: 0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: {{.KubeMasterName}}
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServerExtraArgs:
  insecure-bind-address: "{{.BindAddress}}"
  insecure-port: "{{.BindPort}}"
apiVersion: kubeadm.k8s.io/v1alpha3
auditPolicy:
  logDir: /var/log/kubernetes/audit
  logMaxAge: 2
  path: ""
certificatesDir: /etc/kubernetes/pki
controlPlaneEndpoint: ""
etcd:
  local:
    dataDir: /var/lib/etcd
    image: ""
featureGates: {CoreDNS: {{.UseCoreDNS}}}
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
{{.K8sVersion}}
networking:
  # podSubnet: "{{.PodNetworkCIDR}}"
  serviceSubnet: "{{.ServiceSubnet}}"
unifiedControlPlaneImage: ""
`))

Template_v1_12 kubeadm.conf content template for Kubernetes V1.12

View Source
var Template_v1_13 = template.Must(template.New("v1.13").Parse(`# V1.13 based config
apiEndpoint:
  advertiseAddress: "{{.AdvertiseAddress}}"
  bindPort: 6443
apiVersion: kubeadm.k8s.io/v1beta1
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: {{.AuthToken}}
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: {{.KubeMasterName}}
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServerExtraArgs:
  insecure-bind-address: "{{.BindAddress}}"
  insecure-port: "{{.BindPort}}"
apiVersion: kubeadm.k8s.io/v1beta1
auditPolicy:
  logDir: /var/log/kubernetes/audit
  logMaxAge: 2
  path: ""
certificatesDir: /etc/kubernetes/pki
# clusterName: kubernetes
controlPlaneEndpoint: ""
etcd:
  local:
    dataDir: /var/lib/etcd
    image: ""
featureGates: {CoreDNS: {{.UseCoreDNS}}}
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
{{.K8sVersion}}
networking:
  dnsDomain: cluster.local
  # podSubnet: "{{.PodNetworkCIDR}}"
  serviceSubnet: "{{.ServiceSubnet}}"
unifiedControlPlaneImage: ""
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
bindAddress: "{{.BindAddress}}"
clientConnection:
  acceptContentTypes: ""
  burst: 10
  contentType: application/vnd.kubernetes.protobuf
  kubeconfig: /var/lib/kube-proxy/kubeconfig.conf
  qps: 5
# clusterCIDR: ""
configSyncPeriod: 15m0s
# conntrack:
#   max: null
#   maxPerCore: 32768
#   min: 131072
#   tcpCloseWaitTimeout: 1h0m0s
#   tcpEstablishedTimeout: 24h0m0s
enableProfiling: false
healthzBindAddress: 0.0.0.0:10256
hostnameOverride: ""
iptables:
  masqueradeAll: false
  masqueradeBit: 14
  minSyncPeriod: 0s
  syncPeriod: 30s
ipvs:
  excludeCIDRs: null
  minSyncPeriod: 0s
  scheduler: ""
  syncPeriod: 30s
kind: KubeProxyConfiguration
metricsBindAddress: 127.0.0.1:10249
mode: ""
nodePortAddresses: null
oomScoreAdj: -999
portRange: ""
resourceContainer: /kube-proxy
udpIdleTimeout: 250ms
---
address: 0.0.0.0
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
  anonymous:
    enabled: false
  webhook:
    cacheTTL: 2m0s
    enabled: true
  x509:
    clientCAFile: /etc/kubernetes/pki/ca.crt
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 5m0s
    cacheUnauthorizedTTL: 30s
cgroupDriver: cgroupfs
cgroupsPerQOS: true
clusterDNS:
- "{{.DNS_ServiceIP}}"
clusterDomain: cluster.local
configMapAndSecretChangeDetectionStrategy: Watch
containerLogMaxFiles: 5
containerLogMaxSize: 10Mi
contentType: application/vnd.kubernetes.protobuf
cpuCFSQuota: true
cpuCFSQuotaPeriod: 100ms
cpuManagerPolicy: none
cpuManagerReconcilePeriod: 10s
enableControllerAttachDetach: true
enableDebuggingHandlers: true
enforceNodeAllocatable:
- pods
eventBurst: 10
eventRecordQPS: 5
evictionHard:
  imagefs.available: 15%
  memory.available: 100Mi
  nodefs.available: 10%
  nodefs.inodesFree: 5%
evictionPressureTransitionPeriod: 5m0s
failSwapOn: true
fileCheckFrequency: 20s
hairpinMode: promiscuous-bridge
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 20s
imageGCHighThresholdPercent: 85
imageGCLowThresholdPercent: 80
imageMinimumGCAge: 2m0s
iptablesDropBit: 15
iptablesMasqueradeBit: 14
kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110
nodeLeaseDurationSeconds: 40
nodeStatusUpdateFrequency: 10s
oomScoreAdj: -999
podPidsLimit: -1
# port: 10250
registryBurst: 10
registryPullQPS: 5
resolvConf: /etc/resolv.conf
rotateCertificates: true
runtimeRequestTimeout: 2m0s
serializeImagePulls: true
staticPodPath: /etc/kubernetes/manifests
streamingConnectionIdleTimeout: 4h0m0s
syncFrequency: 1m0s
volumeStatsAggPeriod: 1m0s
`))

Template_v1_13 kubeadm.conf content template for Kubernetes V1.13

Functions

func AddHostEntries

func AddHostEntries(c *Config) error

AddHostEntries udpates the /etc/hosts file with IP addresses to be used by the cluster for each node.

func AddResolvConfEntry

func AddResolvConfEntry(n *Node, c *Config) error

AddResolvConfEntry updates the /etc/resolv.conf file with nameserver entry used for the cluster.

func AddRouteForDNS64Network added in v1.0.7

func AddRouteForDNS64Network(c *Config) error

AddRouteForDNS64Network creates a route in the container to the NAT64 server for synthesized IPv6 addresses.

func BringUp

func BringUp(name string, c *Config)

BringUp performs the "up" actions to bring up a cluster. The (bridge) plugin is set up, kubelet server restarted to pickup changes, the cert/key placed (on master), and cluster init/join performed.

func BuildAddRouteArgs added in v1.0.7

func BuildAddRouteArgs(container, dest, via string) []string

BuildAddRouteArgs constructs arguments for adding an IPv6 route to container.

func BuildArgsForCACert added in v1.0.3

func BuildArgsForCACert(mgmtPrefix string, id int, base string) []string

BuildArgsForCACert constructs arguments for command to build CA certificate.

func BuildArgsForCADigest added in v1.0.3

func BuildArgsForCADigest(base string) []string

BuildArgsForCADigest builds arguments for comamnd to create CA digest.

func BuildArgsForCAKey added in v1.0.3

func BuildArgsForCAKey(base string) []string

BuildArgsForCAKey constructs arguments for command to build CA keys.

func BuildArgsForRSA added in v1.0.3

func BuildArgsForRSA(base string) []string

BuildArgsForRSA builds arguments for command to create RSA key.

func BuildArgsForX509Cert added in v1.0.3

func BuildArgsForX509Cert(base string) []string

BuildArgsForX509Cert builds args for command to create X.509 certificate.

func BuildCreateNetArgsFor added in v1.0.7

func BuildCreateNetArgsFor(name, cidr, v4cidr, gwPrefix string) []string

BuildCreateNetArgsFor constructs arguments to create a docker network.

func BuildCreateVolumeArgs added in v1.2.1

func BuildCreateVolumeArgs(name string) []string

BuildCreateVolumeArgs constructs arguments to create a volume

func BuildDeleteContainerArgs added in v1.2.1

func BuildDeleteContainerArgs(name string) []string

BuildDeleteContainerArgs create arguments for the docker command to delete container

func BuildDeleteNetArgsFor added in v1.0.7

func BuildDeleteNetArgsFor(name string) []string

BuildDeleteNetArgsFor constructs arguments to delete a network.

func BuildDeleteVolumeArgs added in v1.2.1

func BuildDeleteVolumeArgs(name string) []string

BuildDeleteVolumeArgs constructs arguments to delete a volume

func BuildGWIP

func BuildGWIP(prefix string, intfPart int) string

BuildGWIP helper constructs a gateway IP using the provided interface.

func BuildGetInterfaceArgs added in v1.0.7

func BuildGetInterfaceArgs(container, ifName string) []string

BuildGetInterfaceArgs constructs arguments for obtaining list of IPs for an interface.

func BuildInspectVolumeArgs added in v1.2.1

func BuildInspectVolumeArgs(name string) []string

BuildCreateVolumeArgs constructs arguments to create a volume

func BuildKubeAdmCommand

func BuildKubeAdmCommand(n, master *Node, c *Config) []string

BuildKubeAdmCommand constructs the init command (For master), or join command (for minions), using the previously created and stored token and certificate hash.

func BuildNodeCIDR

func BuildNodeCIDR(info NetInfo, node int) string

BuildNodeCIDR helper constructs a node CIDR. The network portion of the CIDR (the prefix), has the node added as the last part of the final address. For example, fd00:20::/64 -> fd00:20::3/64

func BuildPodSubnetPrefix added in v1.0.8

func BuildPodSubnetPrefix(mode, prefix string, netSize, nodeID int) (string, string)

BuildPodSubnetPrefixSuffix will create a pod network prefix, using the cluster prefix and node ID. For IPv6, if the subnet size is not a multiple of 16, then the node ID will be placed in the upper byte of the last part of the prefix. If the node ID is to be placed in the lower byte, and there is an upper byte, we need to make sure we pad with zero for values less than 0x10. The suffix will be "".

For IPv4, the pod network is expected to be /24 with the node ID in the third octect. As a result, the third octet in the prefix is repplaced with the node ID. The suffix will be "0".

func BuildResourceStateArgs added in v1.2.1

func BuildResourceStateArgs(resource string) []string

BuildResourceStateArgs constructs arg to obtain resource state

func BuildRoute

func BuildRoute(destStr, gwStr string, index int) (*netlink.Route, error)

BuildRoute creates a route to the destination, using the provided gateway.

func BuildRunArgsForDNS64

func BuildRunArgsForDNS64(c *Config) []string

BuildRunArgsForDNS64 constructs docker command to start DNS64 container.

func BuildRunArgsForNAT64

func BuildRunArgsForNAT64(c *Config) []string

BuildRunArgsForNAT64 constructs arguments to start a NAT64 container.

func BuildV4AddrDelArgs added in v1.0.7

func BuildV4AddrDelArgs(container, ip string) []string

BuildV4AddrDelArgs constructs arguments for deleting an IPv4 address from and interface.

func CalcNameServer added in v1.3.4

func CalcNameServer(n *Node, c *Config) string

CalcNameServer determines the IP to use for the name server in /etc/resolv.conf based on the service network mode. For IPv6 mode, the DNS64 IP is used, otherwise the node's IP is used.

func CalculateDerivedFields added in v1.0.5

func CalculateDerivedFields(c *Config) error

CalculateDerivedFields splits up CIDRs into prefix and size for use later. TODO: Validate no overlaps in CIDRs

func CheckMgmtSize added in v1.3.3

func CheckMgmtSize(size int) error

CheckMgmtSize ensures that management network size is valid for IPv4 mode.

func CheckPodSize added in v1.3.3

func CheckPodSize(size int) error

CheckPodSize ensures that pod network size is valid for IPv4 mode.

func CheckServiceSize added in v1.3.3

func CheckServiceSize(size int) error

CheckServiceSize ensures that service network size is valid for IPv4 mode.

func CheckUnlimitedSize added in v1.3.3

func CheckUnlimitedSize(size int) error

CheckUnlimitedSize skips checking for any limits on size for IPv4 networks.

func Cleanup

func Cleanup(name string, c *Config) error

Cleanup is the top level method for the "clean" action, to remove/revert config files, remove routes, and delete DNS64/NAT64 containers.

func CleanupClusterNode

func CleanupClusterNode(node *Node, c *Config) error

CleanupClusterNode removes the kubelet drop-in file, management port's IP address, reverts /etc/hosts and /etc/resolv.conf, removes route for DNS network, and removes route to NAT64 server (when the node is not the node hosting the server).

func CleanupDNS64Server

func CleanupDNS64Server(c *Config) error

CleanupDNS64Server removes the DNS64 server and associated config files. The IPv4 default route is not altered.

func CleanupForPlugin

func CleanupForPlugin(node *Node, c *Config) error

CleanupForPlugin performs actions to cleanup the CNI plugin on a node, Including removing the CNI config file and area.

func CleanupNAT64Server

func CleanupNAT64Server(c *Config) error

CleanupNAT64Server removes the NAT64 server and route to server. The default IPv4 route is not touched.

func CleanupSupportNetwork

func CleanupSupportNetwork(c *Config) error

CleanupSupportNetwork checks to see if the support network exists, and if so, removes the network.

func ConfigureManagementInterface added in v1.1.1

func ConfigureManagementInterface(node *Node, c *Config) error

ConfigureManagementInterface adds and address and sets the MTU for the interface used for the pod and management networks.

func CopyFile

func CopyFile(name, src, dst string) (err error)

CopyFile copies configuration files to another area. Used for placing needed certificates and keys that were created.

func CreateCNIConfigFile added in v1.2.0

func CreateCNIConfigFile(node *Node, c *Config) error

CreateCNIConfigFile creates the config file based on the plugin selected. Default location for file is /etc/cni/net.d/.

func CreateCertKeyArea

func CreateCertKeyArea(base string) error

CreateCertKeyArea creates the area used to hold certificates used by KubeAdm.

func CreateCertificateForCA

func CreateCertificateForCA(mgmtPrefix string, id int, base string) error

CreateCertificateForCA creates CA certificate and stores in a file.

func CreateConfigForDNS64

func CreateConfigForDNS64(c *Config) error

CreateConfigForDNS64 creates the needed configuration files for the DNS64 server.

func CreateDigestForCA added in v1.0.3

func CreateDigestForCA(base string) (string, error)

CreateDigestForCA creates the CA digest and extracts the hash for it.

func CreateKeyForCA

func CreateKeyForCA(base string) error

CreateKeyForCA creates the CA key and stores it in a file.

func CreateKubeAdmConfigContents

func CreateKubeAdmConfigContents(n *Node, c *Config) []byte

func CreateKubeAdmConfigFile

func CreateKubeAdmConfigFile(node *Node, c *Config) error

CreateKubeAdmConfigFile constructs the KubeAdm config file during the "prepare" step. This file can be modified, before using it in the "up" step.

func CreateKubeletDropInContents

func CreateKubeletDropInContents(c *Config) *bytes.Buffer

CreateKubeletDropInContents constructs the contents of the kubelet drop-in file to support IPv6.

func CreateKubeletDropInFile

func CreateKubeletDropInFile(c *Config) error

CreateKubeletDropInFile creates a config file to override the kubelet configuration, so that the correct address is used for DNS resolution.

func CreateNamedConfContents

func CreateNamedConfContents(c *Config) *bytes.Buffer

CreateNamedConfContents builds the contents of the configuration file used by the DNS64 server.

func CreateRSAForCA added in v1.0.3

func CreateRSAForCA(base string) error

CreateRSAForCA creates RSA key and stores in a file.

func CreateRouteToNAT64ServerForDNS64Subnet added in v1.0.3

func CreateRouteToNAT64ServerForDNS64Subnet(node *Node, c *Config) (err error)

CreateRouteToNAT64ServerForDNS64Subnet creates a route for the DNS64 network that points to the NAT64 server for proper routing of external addresses.

func CreateRouteToSupportNetworkForOtherNodes added in v1.0.3

func CreateRouteToSupportNetworkForOtherNodes(node *Node, c *Config) (err error)

CreateRouteToSupportNetworkForOtherNodes creates a route on a node, to get to the support netork, so that the DNS64 and NAT64 server can be accessed.

func CreateRoutesForPodNetwork

func CreateRoutesForPodNetwork(node *Node, c *Config) error

CreateRoutesForPodNetwork establishes static routes between a node and all other nodes as part of the "up" operation.

func CreateSupportNetwork

func CreateSupportNetwork(c *Config) (err error)

CreateSupportNetwork creates the network used by the DNS64 and NAT64 servers.

func CreateToken added in v1.0.3

func CreateToken() (string, error)

CreateToken creates the shared token and extracts the value.

func CreateX509CertForCA added in v1.0.3

func CreateX509CertForCA(base string) error

CreateX509CertForCA creates X.509 certificate and stores in a file.

func DoExecCommand

func DoExecCommand(cmd string, args []string) (string, error)

DoExecCommand is a wrapper for performing OS commands and returning output or error. Can be overridden for unit tests.

func DoRouteOpsOnNodes

func DoRouteOpsOnNodes(node *Node, c *Config, op string) error

DoRouteOpsOnNodes builds static routes between minion and master node for a CNI plugin, so that pods can communicate across nodes.

func EnsureCNIAreaExists

func EnsureCNIAreaExists(area string) error

EnsureCNIAreaExists makes sure there is an area for the CNI plugin's config files.

func EnsureDNS64Server added in v1.0.7

func EnsureDNS64Server(c *Config) (err error)

EnsureDNS64Server runs the DNS64 server, if it is not running. If it exists, but is not running, it is first deleted. If it is running, no action is taken.

func EnsureNAT64Server added in v1.0.7

func EnsureNAT64Server(c *Config) (err error)

EnsureNAT64Server creates the NAT64 container. If it is already running, no action is taken. If it exists, but is not running, it is deleted first.

func EnsureRouteToNAT64 added in v1.0.7

func EnsureRouteToNAT64(c *Config) error

EnsureRouteToNAT64 adds a route to the NAT64 container via the support network.

func ExtractDigest added in v1.0.5

func ExtractDigest(input string) (string, error)

ExtractDigest parses the digest, extracting the hash and validating it.

func ExtractNetInfo added in v1.3.3

func ExtractNetInfo(cidr string, info *NetInfo, check SizeCheck) error

ExtractNetInfo obtains the prefix, size, and IP family from the provided CIDR.

func ExtractToken added in v1.0.5

func ExtractToken(input string) (string, error)

ExtractToken extracts the access token and validates it, returning the value.

func FindHostIPForNAT64

func FindHostIPForNAT64(c *Config) (string, bool)

FindHostIPForNAT64 determines the management IP for the node containing the NAT64 server.

func GenerateDefaultRoute added in v1.3.4

func GenerateDefaultRoute(c *Config, i int) string

GenerateDefaultRoute creates the default route entry based on the IP mode. This will be called twice, if dual-stack mode.

func GetFileContents

func GetFileContents(file string) ([]byte, error)

GetFileContents reads the contents of the specified file.

func GetNetAndMask

func GetNetAndMask(input string) (string, int, error)

GetNetAndMask obtains the network part and mask from the provided CIDR.

func Initialize

func Initialize(name string, c *Config, configFile string) error

Initialize performs steps for the "init" operation, creating certificate, key, token, and hash, and then updates the configuration YAML file with the token and hash, so that KubeAdm operations can be performed.

func IsIPv4 added in v1.3.0

func IsIPv4(ip string) bool

IsIPv4 takes a known good IP address and determines if it is IPv4.

func MakePrefixFromNetwork added in v1.0.8

func MakePrefixFromNetwork(network string, netSize int) string

MakePrefixFromNetwork takes the network part of the CDIR, and builds an expanded prefix, so that a node ID can be added later to form the network part of the pod network. This means expanding "::" as needed, so that the prefix is fully qualified (and a :: can be added to the end later without causing a syntax error). This is done by determining how many 16 bit parts are needed and padding each missing part with a zero.

Also, if the network includes a final part that is 16 bits and only the upper eight bits are part of the prefix, then the lower byte will be removed so that the node ID can be placed there later.

Lastly, if we don't have this condition of the prefix containing the upper eight bits of the address, we'll place a colon on the end.

Examples:

fd00:40:: (72)            -> fd00:40:0:0:
fd00:10:20:30:4000:: (72) -> fd00:10:20:30:40
fd00:10:20:30:: (64)      -> fd00:10:20:30:
fd00:10:20:30:: (80)      -> fd00:10:20:30:0:

func MakeV4PrefixFromNetwork added in v1.3.0

func MakeV4PrefixFromNetwork(ip string) string

MakeV4PrefixFromNetwork extracts a prefix from the IPv4 address. It will always remove the last octet, regardless of subnet size.

func MatchingNodeIndex

func MatchingNodeIndex(line []byte, n []NodeInfo) int

MatchingNodeIndex obtains the index of the node entry that matches the name of one of the existing nodes.

func OpenConfigFile added in v1.0.5

func OpenConfigFile(configFile string) (io.ReadCloser, error)

OpenConfigFile opens the TAML file with configuration settings.

func OpenPermissions

func OpenPermissions(name string) error

OpenPermissions helper makes the directory read/write.

func OsExecCommand added in v1.3.1

func OsExecCommand(cmd string, args []string) (string, error)

func ParseIPv4Address

func ParseIPv4Address(ifConfig string) string

ParseIPv4Address extracts the CIDR from the interface's list of IP addresses.

func ParseVersion added in v1.3.1

func ParseVersion(version string) (string, error)

ParseVersion takes a version string and extracts the major.minor part, returning an error, if invalid. Examples of valid versions are "v1.11.0" and "v1.13.0-alpha.0.2169+8f620950e246fa-dirty".

func PlaceCertificateAndKeyForCA

func PlaceCertificateAndKeyForCA(workBase, dst string) error

PlaceCertificateAndKeyForCA copies generated files to the Kubernetes area so that KubeAdm can reference the information.

func Prepare

func Prepare(name string, c *Config) error

Prepare gets ready to start up the cluster. The support network is created (if not on the NAT64/DNS64 node), the NAT64 and DNS64 servers are started, and the node is configured for running the cluster.

func PrepareClusterNode

func PrepareClusterNode(node *Node, c *Config) error

PrepareClusterNode performs steps on the node to prepare for bringing up the cluster. Includes adding the management IP, updating hosts and resolv.conf entries, creating a kubelet drop-in file, creating the KubeAdm configuration file (on master), and creating routes to servers and the support network.

func PrepareDNS64Server

func PrepareDNS64Server(c *Config) error

PrepareDNS64Server starts up the bind9 DNS64 server. Will use existing container, if running. Will remove IPv4 address in the container and add a route to the container.

func PrepareNAT64Server

func PrepareNAT64Server(c *Config) error

PrepareNAT64Server starts up the Tayga NAT64 server. NOTE: Will use existing container, if running

func RecoverFile added in v1.0.7

func RecoverFile(file, backup, saveErr string) error

RecoverFile attempts to restore the backup of a file to the original.

func RegisterExecCommand added in v1.3.1

func RegisterExecCommand(cmdFunc ExecCommandFuncType)

RegisterExecCommand will register a OS command function for exec calls. Used ONLY by unit test.

func RemoveContainer added in v1.0.7

func RemoveContainer(name string, c *Config) error

RemoveContainer checks to see if the container is present, and if so, removes the container.

func RemoveDropInFile added in v1.0.7

func RemoveDropInFile(c *Config) error

RemoveDropInFile eliminates the kubelet drop-in file as part of the cleanup operation.

func RemoveIPv4AddressOnDNS64Server added in v1.0.7

func RemoveIPv4AddressOnDNS64Server(c *Config) (err error)

RemoveIPv4AddressOnDNS64Server removes IPv4 address in container, so there is only an IPv6 address.

func RemoveManagementIP added in v1.0.7

func RemoveManagementIP(node *Node, c *Config) error

RemoveManagementIP removes the node's management IP off of the interface configured as the management port.

func RemoveRouteForDNS64 added in v1.0.7

func RemoveRouteForDNS64(node *Node, c *Config) error

RemoveRouteForDNS64 removes the route to the DNS64 network via the IPv4 support network, if on the NAT64 node, or via the NAT64 server's management IP, if not on the NAT64 server.

func RemoveRouteForNAT64 added in v1.0.7

func RemoveRouteForNAT64(node *Node, c *Config) error

RemoveRouteForNAT64 removes the route to the support network via the NAT64 server's manage,ent IP.

func RemoveRoutesForPodNetwork

func RemoveRoutesForPodNetwork(node *Node, c *Config) error

RemoveRoutesForPodNetwork removes static routes between nodes, as part of the "down" operation.

func RestartKubeletService

func RestartKubeletService() error

RestartKubeletService restarts the service, after changes have been made to drop-in files.

func RevertConfigInfo

func RevertConfigInfo(contents []byte, file string) []byte

RevertConfigInfo restores the contents of the provided config file, by using the comment tags that describe the additions settings (to be removed), and the previous settings (to be restored).

func RevertEntries

func RevertEntries(file, backup string) error

RevertEntries obtains the config file contents, reverts the settings, and then stores the updated file (with a backup created, in case of issues).

func RevertEtcAreaFile added in v1.0.7

func RevertEtcAreaFile(c *Config, file, backup string) error

RevertEtcAreaFile will revert the entries in config files in the /etc/ area as part of cleanup.

func SaveFileContents

func SaveFileContents(contents []byte, file, backup string) error

SaveFileContents backs up the files (if it exists), and then saves the updated contents to the file. If the save fails, it attempts to restore the backup.

func SetupBaseAreas added in v1.0.5

func SetupBaseAreas(work, systemd, etc, cni, cert string, c *Config)

SetupBaseAreas allows the configuration to hold the root for both the working files (overridable), and key configuration files. This will allow the user to specify a different work area in the former and for unit tests to specify a temp area for the latter.

func SetupForPlugin

func SetupForPlugin(node *Node, c *Config) error

SetupForPlugin prepares the CNI plugin by making sure CNI area exists and then performing bridge specific setup.

func SetupHandles added in v1.0.7

func SetupHandles(c *Config) error

SetupHandles configures pointers to the methods that will handle network and hypervisor operations.

func StartKubernetes

func StartKubernetes(n *Node, c *Config) error

StartKubernetes uses the KubeAdm init or join command to start up the cluster on the master or minion node, respectively.

func StopKubernetes

func StopKubernetes() error

StopKubernetes is called during the "down" operation, to bring down the cluster.

func TearDown

func TearDown(name string, c *Config)

TearDown performs the "down" operations of bringing down the cluster, removing static routes, removing the Bridge plugin config file, and removing the bridge.

func UpdateConfigYAML

func UpdateConfigYAML(file, token, hash string) error

UpdateConfigYAML adds the access token and hash to the configuration YAML file, replacing any existing entries.

func UpdateConfigYAMLContents

func UpdateConfigYAMLContents(contents []byte, file, token, hash string) []byte

UpdateConfigYAMLContents will parse through the provided config file contents and add the token and token certificate hash entries. Old values, if present, will be removed. The new fields will be placed inside of the general section.

func UpdateHostsInfo

func UpdateHostsInfo(contents []byte, n []NodeInfo) []byte

UpdateHostsInfo goes through the /etc/hosts file and updates the IP addresses for nodes that are called out in the configuration file. Any existing entry is commented out, with a special tag to allow restoration. New entries get a comment that can be use to remove them upon cleanup.

func UpdateResolvConfInfo

func UpdateResolvConfInfo(contents []byte, ns string) []byte

UpdateResolvConfInfo updates the nameservers to use the ones defined for the cluster. Old entries are commented out, and new ones tagged, allowing later restoration, during cleanup.

func ValidateCIDR added in v1.0.4

func ValidateCIDR(which, cidr string) error

ValidateCIDR ensures that the CIDR is valid.

func ValidateCommand

func ValidateCommand(command string) (string, error)

ValidateCommand ensures that the command specified is supported.

func ValidateConfigContents

func ValidateConfigContents(c *Config, ignoreMissing bool) error

ValidateConfigContents checks contents of the config file. Token and certificate hash validation is ignored during init phase, which will generate these values, or if running in insecure mode. Side effect is that base paths are set up based on defaults (unless overriden by config file). The netlink library handle is set (allowing UTs to override and mock that library). TODO: Validate support net v4 subnet > NAT64 subnet

func ValidateDNS64Fields added in v1.1.1

func ValidateDNS64Fields(c *Config) error

ValidateDNS64Fields checks user supplied DNS64 settings, applies defaults, and handles any deprecated fields.

func ValidateHost

func ValidateHost(host string, config *Config) error

ValidateHost ensures that the host is mentioned in the configuration.

func ValidateNAT64Fields added in v1.1.2

func ValidateNAT64Fields(c *Config) error

ValidateNAT64Fields checks that the subnet for the IPv4 mapping address (assumed /16), contains the subnet used for the IPv4 mapping pool, and that both are valid.

func ValidateNetworkMode added in v1.3.0

func ValidateNetworkMode(c *Config) error

ValidateNetworkMode makes sure that only the supported network modes are entered. Currently, this is ipv4, ipv6, or dual-stack. The default is IPv6, when not specified.

func ValidateNodeOpModes

func ValidateNodeOpModes(netMode string, node *Node) error

ValidateNodeOpModes checks that valid operational mode names are used. NOTE: Side effect of saving the operating modes as flags, for easier use.

func ValidateOpModesForAllNodes

func ValidateOpModesForAllNodes(c *Config) error

ValidateOpModesForAllNodes checks the operation mode for all nodes, and ensures that there is exactly one master node. Note: Side effect is storing node name in node struct for ease of access

TODO: determine if allow duplicate DNS/NAT nodes TODO: test missing DNS/NAT node

func ValidatePlugin added in v1.0.5

func ValidatePlugin(c *Config) error

ValidatePlugin ensures the plugin name is valid. Side effect of storing legacy value into new field.

func ValidatePodFields added in v1.1.1

func ValidatePodFields(c *Config) error

ValidatePodFields checks user supplied pod network settings, applies defaults, and handles any deprecated fields.

func ValidateSoftwareVersions added in v1.3.1

func ValidateSoftwareVersions(c *Config) error

ValidateSoftwareVersions checks that the software used is compatible with the Lazyjack tool. As a side effect, the kubeadm version (major.minor) is stored, so that the proper config file can be generated.

If the user specifies the Kubernetes version to use, this makes sure that it is the same major/minor version as KubeAdm.

This function only checks kubeadm, but could check kubectl in the future.

func ValidateToken

func ValidateToken(token string, ignoreMissing bool) error

ValidateToken ensures that the token exists and seems valid. This check is skipped during the init operation, where the token is created.

func ValidateTokenCertHash

func ValidateTokenCertHash(certHash string, ignoreMissing bool) error

ValidateTokenCertHash ensures that the token certificate hash exists and seems valid. This check is skipped during the init operation, where the hash is created.

func ValidateUniqueIDs

func ValidateUniqueIDs(c *Config) error

ValidateUniqueIDs ensures that the node IDs are unique.

func WriteConfigForIPAM added in v1.3.5

func WriteConfigForIPAM(c *Config, node *Node, w io.Writer) (err error)

WriteConfigForIPAM creates the section of the CNI configuration that contains the IPAM information with subnet and gateway information for the pod network(s).

func WriteRange added in v1.3.5

func WriteRange(c *Config, node *Node, i int, w io.Writer) (err error)

WriteRange creates one IPAM range entry, based on the IP mode of the pod network

Types

type BridgePlugin added in v1.2.0

type BridgePlugin struct {
	Config *Config
}

BridgePlugin implements the actions needed for the Bridge CNI plugin.

func (BridgePlugin) Cleanup added in v1.2.0

func (b BridgePlugin) Cleanup(n *Node) error

Cleanup performs Bridge plugin actions to clean up for a node. Includes deleting routes between nodes.

func (BridgePlugin) Setup added in v1.2.0

func (b BridgePlugin) Setup(n *Node) error

Setup will take Bridge plugin specific actions to setup a node. Includes setting up routes between nodes.

func (BridgePlugin) WriteConfigContents added in v1.3.5

func (b BridgePlugin) WriteConfigContents(node *Node, w io.Writer) (err error)

WriteConfigContents builds the CNI bridge plugin's config file contents. The subnet will be eight bits smaller than the pod cluster network size.

type Config

type Config struct {
	Plugin   string          `yaml:"plugin"` // Deprecated
	General  GeneralSettings `yaml:"general"`
	Topology map[string]Node
	Support  SupportNetwork    `yaml:"support_net"`
	Mgmt     ManagementNetwork `yaml:"mgmt_net"`
	Pod      PodNetwork        `yaml:"pod_net"`
	Service  ServiceNetwork    `yaml:"service_net"`
	NAT64    NAT64Config       `yaml:"nat64"`
	DNS64    DNS64Config       `yaml:"dns64"`
}

Config defines the top level configuration read from YAML file.

func LoadConfig

func LoadConfig(cf io.ReadCloser) (*Config, error)

LoadConfig parses the stream provided into the configuration structure.

func ParseConfig

func ParseConfig(configReader io.Reader) (*Config, error)

ParseConfig parses the YAML configuration provided, into the config structure.

type DNS64Config

type DNS64Config struct {
	RemoteV4Server string `yaml:"remote_server"`
	CIDR           string `yaml:"cidr"`
	CIDRPrefix     string
	ServerIP       string `yaml:"ip"`
	AllowIPv6Use   bool   `yaml:"allow_ipv6_use"` // Deprecated
	AllowAAAAUse   bool   `yaml:"allow_aaaa_use"`
}

DNS64Config defines information for the DNS64 server configuration.

type Docker added in v1.0.7

type Docker struct {
	Command string
}

Docker represents a concrete hypervisor implementation.

func (*Docker) AddV6Route added in v1.0.7

func (d *Docker) AddV6Route(container, dest, via string) error

AddV6Route performs docker command to add an IPv6 route.

func (*Docker) CreateNetwork added in v1.0.7

func (d *Docker) CreateNetwork(name, cidr, v4cidr, gw string) error

CreateNetwork performs docker command to create a network.

func (*Docker) CreateVolume added in v1.2.1

func (d *Docker) CreateVolume(name string) error

CreateVolume creates a new docker volume

func (*Docker) DeleteContainer added in v1.0.7

func (d *Docker) DeleteContainer(name string) error

DeleteContainer constructs arguments to remove a container.

func (*Docker) DeleteNetwork added in v1.0.7

func (d *Docker) DeleteNetwork(name string) error

DeleteNetwork performs docker command to delete a network.

func (*Docker) DeleteV4Address added in v1.0.7

func (d *Docker) DeleteV4Address(container, ip string) error

DeleteV4Address performs docker command to remove the IPv4 address from the container's eth0 interface.

func (*Docker) DeleteVolume added in v1.2.1

func (d *Docker) DeleteVolume(name string) error

DeleteVolume force deletes a docker volume. No error occurs, if volume doesn't exist.

func (*Docker) DoCommand added in v1.2.1

func (d *Docker) DoCommand(name string, args []string) (string, error)

DoCommand performs a docker command, collecting and returning output. TODO: Perform in a separate go-routine with a timeout, and abort handling.

func (*Docker) GetInterfaceConfig added in v1.0.7

func (d *Docker) GetInterfaceConfig(name, ifName string) (string, error)

GetInterfaceConfig performs docker command to obtain an interface's IP addresses.

func (*Docker) GetVolumeMountPoint added in v1.2.1

func (d *Docker) GetVolumeMountPoint(name string) (string, error)

GetVolumeMountPoint obtains the mount point so that files can be deposited from host.

func (*Docker) ResourceState added in v1.0.7

func (d *Docker) ResourceState(r string) string

ResourceState method obtains the state of the resource, which can be not present, existing, or running (for container resources).

func (*Docker) RunContainer added in v1.0.7

func (d *Docker) RunContainer(name string, args []string) error

RunContainer performs docker command to run a container.

type ExecCommandFuncType added in v1.3.1

type ExecCommandFuncType = func(string, []string) (string, error)

ExecCommandFuncType is a function for performing OS commands

type GeneralSettings added in v1.0.5

type GeneralSettings struct {
	Mode               string     `yaml:"mode"`
	Plugin             string     `yaml:"plugin"`
	Token              string     `yaml:"token"`           // Internal
	TokenCertHash      string     `yaml:"token-cert-hash"` // Internal
	WorkArea           string     `yaml:"work-area"`
	CNIPlugin          PluginAPI  // Internal
	SystemdArea        string     // Internal
	EtcArea            string     // Internal
	CNIArea            string     // Internal
	K8sCertArea        string     // Internal
	NetMgr             Networker  // Internal
	Hyper              Hypervisor // Internal
	KubeAdmVersion     string     // Internal
	FullKubeAdmVersion string     // Internal
	K8sVersion         string     `yaml:"kubernetes-version"`
	Insecure           bool       `yaml:"insecure"`
}

GeneralSettings defines general settings used by the app.

type Hypervisor added in v1.0.7

type Hypervisor interface {
	ResourceState(r string) string
	DeleteContainer(string) error
	RunContainer(string, []string) error
	CreateNetwork(string, string, string, string) error
	DeleteNetwork(string) error
	GetInterfaceConfig(string, string) (string, error)
	DeleteV4Address(string, string) error
	AddV6Route(string, string, string) error
	CreateVolume(string) error
	DeleteVolume(string) error
	GetVolumeMountPoint(string) (string, error)
}

Hypervisor interface indicates the general API for hypervisor operations.

type KubeAdmConfigInfo added in v1.3.1

type KubeAdmConfigInfo struct {
	AdvertiseAddress string
	AuthToken        string
	BindAddress      string
	BindPort         int
	DNS_ServiceIP    string
	K8sVersion       string
	KubeMasterName   string
	PodNetworkCIDR   string
	ServiceSubnet    string
	UseCoreDNS       bool
}

KubeAdmConfigInfo provides values for the templates used to populate the kubeadm.conf file (contents).

func CollectKubeAdmConfigInfo added in v1.3.1

func CollectKubeAdmConfigInfo(n *Node, c *Config) KubeAdmConfigInfo

type ManagementNetwork

type ManagementNetwork struct {
	CIDR  string     `yaml:"cidr"`
	CIDR2 string     `yaml:"cidr2"`
	Info  [2]NetInfo //Internal
}

ManagementNetwork defines information for the management network.

type NAT64Config

type NAT64Config struct {
	V4MappingCIDR string `yaml:"v4_cidr"`
	V4MappingIP   string `yaml:"v4_ip"`
	ServerIP      string `yaml:"ip"`
}

NAT64Config defines information for the NAT64 server configuration.

type NetInfo added in v1.3.3

type NetInfo struct {
	Prefix string
	Size   int
	Mode   string // "ipv6" or "ipv4"
}

NetInfo contains the prefix, size, and mode for a network.

type NetLink struct {
	// contains filtered or unexported fields
}

NetLink defines the structure for netlink implementation of networking

func (*NetLink) AddrDel added in v1.0.8

func (n *NetLink) AddrDel(link netlink.Link, addr *netlink.Addr) error

AddrDel deletes an address from a link

func (*NetLink) AddrList added in v1.0.8

func (n *NetLink) AddrList(link netlink.Link, family int) ([]netlink.Addr, error)

AddrList lists IPs on a link

func (*NetLink) AddrReplace added in v1.0.8

func (n *NetLink) AddrReplace(link netlink.Link, addr *netlink.Addr) error

AddrReplace replaces IP address on a link

func (*NetLink) LinkByName added in v1.0.8

func (n *NetLink) LinkByName(name string) (netlink.Link, error)

LinkByName finds a link by name

func (*NetLink) LinkDel added in v1.0.8

func (n *NetLink) LinkDel(link netlink.Link) error

LinkDel deletes an interface

func (n *NetLink) LinkList() ([]netlink.Link, error)

LinkList lists all links on system

func (*NetLink) LinkSetDown added in v1.0.8

func (n *NetLink) LinkSetDown(link netlink.Link) error

LinkSetDown brings down an interface

func (*NetLink) LinkSetMTU added in v1.1.1

func (n *NetLink) LinkSetMTU(link netlink.Link, mtu int) error

func (*NetLink) ParseAddr added in v1.0.8

func (n *NetLink) ParseAddr(s string) (*netlink.Addr, error)

ParseAddr parses the string as an IP address

func (*NetLink) ParseIPNet added in v1.0.8

func (n *NetLink) ParseIPNet(s string) (*net.IPNet, error)

ParseIPNet parses the string as an IPNet object.

func (*NetLink) RouteAdd added in v1.0.8

func (n *NetLink) RouteAdd(route *netlink.Route) error

RouteAdd adds a route

func (*NetLink) RouteDel added in v1.0.8

func (n *NetLink) RouteDel(route *netlink.Route) error

RouteDel deletes a route

type NetLinkAPI added in v1.0.8

type NetLinkAPI interface {
	AddrDel(netlink.Link, *netlink.Addr) error
	AddrList(netlink.Link, int) ([]netlink.Addr, error)
	AddrReplace(netlink.Link, *netlink.Addr) error
	LinkByName(name string) (netlink.Link, error)
	LinkList() ([]netlink.Link, error)
	ParseAddr(string) (*netlink.Addr, error)
	ParseIPNet(s string) (*net.IPNet, error)
	RouteAdd(route *netlink.Route) error
	RouteDel(route *netlink.Route) error
	LinkSetDown(link netlink.Link) error
	LinkDel(link netlink.Link) error
	LinkSetMTU(link netlink.Link, mtu int) error
}

NetLinkAPI interface representing low level API to netlink package. Used to allow mocking for testing.

type NetMgr added in v1.0.8

type NetMgr struct {
	Server NetLinkAPI
}

NetMgr defines the structure for a netlink implementation for networking.

func (n NetMgr) AddAddressToLink(ip, intf string) error

AddAddressToLink method adds an IP address to a link, replacing the existing address, if any.

func (NetMgr) AddRouteUsingInterfaceName added in v1.0.8

func (n NetMgr) AddRouteUsingInterfaceName(dest, gw, intf string) error

AddRouteUsingInterfaceName method adds a route to the destination, using the local interface.

func (NetMgr) AddRouteUsingSupportNetInterface added in v1.0.8

func (n NetMgr) AddRouteUsingSupportNetInterface(dest, gw, supportNetCIDR string) error

AddRouteUsingSupportNetInterface method adds a route to the destination using the gateway and support network CIDR.

func (n NetMgr) AddressExistsOnLink(addr *netlink.Addr, link netlink.Link) bool

AddressExistsOnLink checks to see if the address to be deleted, is on the link. If we are unable to obtain link info, we'll assume address is not there, and will later skip trying to remove it.

func (NetMgr) BringLinkDown added in v1.0.8

func (n NetMgr) BringLinkDown(name string) error

BringLinkDown method shuts down the link specified.

func (n NetMgr) DeleteLink(name string) error

DeleteLink method deletes the link specified.

func (NetMgr) DeleteRouteUsingInterfaceName added in v1.0.8

func (n NetMgr) DeleteRouteUsingInterfaceName(dest, gw, intf string) error

DeleteRouteUsingInterfaceName method removes the route to the destination that uses the local interface.

func (NetMgr) DeleteRouteUsingSupportNetInterface added in v1.0.8

func (n NetMgr) DeleteRouteUsingSupportNetInterface(dest, gw, supportNetCIDR string) error

DeleteRouteUsingSupportNetInterface method removes the route to the destination that uses the provided CIDR.

func (NetMgr) FindLinkIndexForCIDR added in v1.0.8

func (n NetMgr) FindLinkIndexForCIDR(cidr string) (int, error)

FindLinkIndexForCIDR method obtains the index of the interface that contains the CIDR.

func (n NetMgr) RemoveAddressFromLink(ip, intf string) error

RemoveAddressFromLink method removes an IP addres from an interface.

func (NetMgr) RemoveBridge added in v1.0.8

func (n NetMgr) RemoveBridge(name string) error

RemoveBridge method removes the specified bridge.

func (NetMgr) SetLinkMTU added in v1.1.1

func (n NetMgr) SetLinkMTU(name string, mtu int) error

SetLinkMTU method sets the MTU on the link.

type Networker added in v1.0.8

type Networker interface {
	AddAddressToLink(ip, intf string) error
	RemoveAddressFromLink(ip, intf string) error
	AddRouteUsingSupportNetInterface(dest, gw, supportNetCIDR string) error
	DeleteRouteUsingSupportNetInterface(dest, gw, supportNetCIDR string) error
	AddRouteUsingInterfaceName(dest, gw, intf string) error
	DeleteRouteUsingInterfaceName(dest, gw, intf string) error
	BringLinkDown(name string) error
	DeleteLink(name string) error
	RemoveBridge(name string) error
	SetLinkMTU(name string, mtu int) error
}

Networker interface describes the API for networking operations

type Node

type Node struct {
	Interface      string `yaml:"interface"`
	ID             int    `yaml:"id"`
	OperatingModes string `yaml:"opmodes"`
	Name           string
	IsMaster       bool
	IsMinion       bool
	IsDNS64Server  bool
	IsNAT64Server  bool
}

Node defines information for the node.

func DetermineMasterNode

func DetermineMasterNode(c *Config) *Node

DetermineMasterNode identifies which node configuration entry is for the master node.

type NodeInfo

type NodeInfo struct {
	Name string
	IP   string
	Seen bool
}

NodeInfo holds name, IP address, and an indication that the node has been "visited".

func BuildNodeInfo

func BuildNodeInfo(c *Config) []NodeInfo

BuildNodeInfo creates a slice with all information on all the nodes sorted in alphabetical order.

type PluginAPI added in v1.2.0

type PluginAPI interface {
	WriteConfigContents(node *Node, w io.Writer) error
	Setup(n *Node) error
	Cleanup(n *Node) error
}

PluginAPI interface defines the actions for CNI plugins to implement.

type PodNetwork

type PodNetwork struct {
	CIDR  string     `yaml:"cidr"`
	CIDR2 string     `yaml:"cidr2"`
	Info  [2]NetInfo // Internal
	MTU   int        `yaml:"mtu"`
}

PodNetwork defines information for the the pod network.

type PointToPointPlugin added in v1.2.0

type PointToPointPlugin struct {
	Config *Config
}

PointToPointPlugin implements the actions needed for the PTP CNI plugin.

func (PointToPointPlugin) Cleanup added in v1.2.0

func (p PointToPointPlugin) Cleanup(n *Node) error

Cleanup performs PTP plugin actions to clean up for a node. Includes deleting routes between nodes.

func (PointToPointPlugin) Setup added in v1.2.0

func (p PointToPointPlugin) Setup(n *Node) error

Setup will take PTP plugin specific actions to setup a node. Includes setting up routes between nodes.

func (PointToPointPlugin) WriteConfigContents added in v1.3.5

func (p PointToPointPlugin) WriteConfigContents(node *Node, w io.Writer) (err error)

WriteConfigContents builds the CNI PTP plugin's config file contents.

type ServiceNetwork

type ServiceNetwork struct {
	CIDR string  `yaml:"cidr"`
	Info NetInfo // Internal
}

ServiceNetwork defines information for the service network.

type SizeCheck added in v1.3.3

type SizeCheck func(int) error

SizeCheck is a function type for validating IPv4 network sizes.

type SupportNetwork

type SupportNetwork struct {
	CIDR   string  `yaml:"cidr"`
	Info   NetInfo // Internal
	V4CIDR string  `yaml:"v4cidr"`
}

SupportNetwork defines information for the support network.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL