To allow some flexibilities in how user specifies the --api-port
argument. In case the 'host' is an string, We will try to convert
it into an IP address for port mapping. IP address is also allowed.
The APIs of createServer() and createWorker() takes too many arguments.
It is getting harder to maintain.
Use a new struct ClusterSpec to make API simpler. This also reduces
some code duplications.
When creating clusters with the --auto-restart flag, any running cluster
will remain "running" up on docker daemon restart.
By default, without this flag, a "running" cluster becomes "stopped"
after docker daemon restart.
Clusters stopped with 'k3d stop' command will remain stopped after
docker daemon restart regardless the settings of this flag.
Thanks @zeerorg for the suggestion on possible container volume leak.
With out this fix the k3s container volumes are left in the reclaimable
state. This experiment confirms it:
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 14 0 2.131GB 2.131GB (100%)
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
$ bin/k3d create; sleep 5; bin/k3d delete
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 14 0 2.131GB 2.131GB (100%)
Containers 0 0 0B 0B
Local Volumes 3 0 2.366MB 2.366MB (100%)
Build Cache 0 0 0B 0B
In this case, 2.36MB are left in the reclaimable state. This number can be
larger with a larger cluster.
With this fix, output of "docker system df" does not contain the
claimable volume
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 14 0 2.131GB 2.131GB (100%)
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
All ports exposed by --publish will also be exported for all worker
nodes. The host port will be auto indexed based worker id.
For example: with the following command option:
k3d create --publish 80:80 --publish 90:90/udp --workers 1
The exposed ports will be:
host TCP port 80 -> k3s server TCP 80
host TCP port 90 -> k3s server TCP 90
host UDP port 81 -> k3s worker 0 UDP 80
host UDP port 91 -> k3s worker 0 UDP 90
Inspired by the docker CLI, --publish take same input as docker CLI and
provides similar functions. For the k3s cluster server node, it behaves
the same as docker cli; it exports the k3d server ports to the host
ports.
Handling for worker nodes will be added in the subsequent patches.
This option can be used mutiple times for exposing more ports.
--add-port is an alias to this option.
This class holds the parsed results of the --publish options. Its
methods helps the create clones of class, with mutations applied.
Currently, there are two methods: Offset() change the host ports by a
fixed amount. Addport() adds one additional port to the class.