We use docker machine for provisioning nodes for RKE clusters.
the original docker machine is not maintained, and any PRs for it will likely not be accepted
When running rancher locally from an IDE, rancher will use whichever docker-machine binary is available to it.
To check where this is, one can run which docker-machine
.
If you are developing docker-machine and would like rancher to run your version, you must first make the binary:
- Clone the rancher fork repo into
$GOPATH/src/github.com/docker/machine
cd $GOPATH/src/github.com/docker/machine/cmd/docker-machine
go build
- Copy the resulting binary (docker-machine) to the path that was returned by
which docker-machine
. This path is likely /usr/local/bin.
Now, rancher should use your version of docker-machine.
Some schemas in Rancher are automatically generated by inspecting docker-machine. For example, the azureConfig (used for creating azure nodes) is generated by inspecting the cli flags in rancher that are prepended with "azure". The azure ones are created in machine/drivers/azure/azure.go.
In this example, we will be adding a field to the azure config. However, adding a field to the other config schemas should be very similar.
A field can be added to the azureConfig schema by adding a flag. For example, if I wanted to add a flag for a fallback image to use if the flAzureImage was unavailable, I would follow these steps:
- in second const block, create constant that stores the flags name in const block:
flAzureFallbackImage = "azure-fallback-image"
(Optional) 2. in first const block, create constant that stores default value:
`defaultAzureFallbackImage = "canonical:UbuntuServer:18.04.0-LTS:latest"
- in driver struct, add corresponding field:
FallbackImage string
- add statement for initializing field from flags in SetConfigFromFlag function:
if required field and string value (under required string flags comment):
{&d.FallbackImage, flAzureFallbackImage}
if optional field or non-string value (under optional flags comment:
&d.FallbackImage, flAzureFallbackImage
- use field: in this example, I would probably want to use my new field during the VM creation process. Navigating to the Create function, I can see that a CreateVirtualMachine function (found in azureutil.go) is used. That is where one could add the logic for using the fallback image.
NOTE: Before your version of docker-machine is ready to be added to Rancher, you must have had your PR merged into Rancher's fork of docker machine AND a release must have been made that includes your commits.
Open rancher/package/Dockerfile
There will be a line that reads as follows:
ENV CATTLE_MACHINE_VERSION v.x.x-rancherx-x
(actual version name may vary)
Replace version, in this case v.x.x-rancherx-x, with the release made after your commit to docker machine.