Andrey Smirnov 2bf8540855 test: provision Talos clusters via Firecracker VMs
This is initial PR to push the initial code, it has several known
problems which are going to be addressed in follow-up PRs:

1. there's no "cluster destroy", so the only way to stop the VMs is to
`pkill firecracker`

2. provisioner creates state in `/tmp` and never deletes it, that is
required to keep cluster running when `osctl cluster create` finishes

3. doesn't run any controller process around firecracker to support
reboots/CNI cleanup (vethxyz interfaces are lingering on the host as
they're never cleaned up)

The plan is to create some structure in `~/.talos` to manage cluster
state, e.g. `~/.talos/clusters/<name>` which will contain all the
required files (disk images, file sockets, VM logs, etc.). This
directory structure will also work as a way to detect running clusters
and clean them up.

For point number 3, `osctl cluster create` is going to exec lightweight
process to control the firecracker VM process and to simulate VM reboots
if firecracker finishes cleanly (when VM reboots).

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-01-16 00:27:08 +03:00

107 lines
2.4 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package provision
import (
"fmt"
"net"
"github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/config/machine"
)
// ClusterRequest is the root object describing cluster to be provisioned.
type ClusterRequest struct {
Name string
Network NetworkRequest
Nodes NodeRequests
Image string
KernelPath string
InitramfsPath string
KubernetesVersion string
}
// CNIConfig describes CNI part of NetworkRequest.
type CNIConfig struct {
BinPath []string
ConfDir string
CacheDir string
}
// NetworkRequest describe cluster network.
type NetworkRequest struct {
Name string
CIDR net.IPNet
GatewayAddr net.IP
MTU int
// CNI-specific parameters.
CNI CNIConfig
}
// NodeRequests is a list of NodeRequest.
type NodeRequests []NodeRequest
// FindInitNode looks up init node, it returns an error if no init node is present or if it's duplicate.
func (reqs NodeRequests) FindInitNode() (req NodeRequest, err error) {
found := false
for i := range reqs {
if reqs[i].Config.Machine().Type() == machine.TypeInit {
if found {
err = fmt.Errorf("duplicate init node in requests")
return
}
req = reqs[i]
found = true
}
}
if !found {
err = fmt.Errorf("no init node found in requests")
}
return
}
// MasterNodes returns subset of nodes which are Init/ControlPlane type.
func (reqs NodeRequests) MasterNodes() (nodes []NodeRequest) {
for i := range reqs {
if reqs[i].Config.Machine().Type() == machine.TypeInit || reqs[i].Config.Machine().Type() == machine.TypeControlPlane {
nodes = append(nodes, reqs[i])
}
}
return
}
// WorkerNodes returns subset of nodes which are Init/ControlPlane type.
func (reqs NodeRequests) WorkerNodes() (nodes []NodeRequest) {
for i := range reqs {
if reqs[i].Config.Machine().Type() == machine.TypeWorker {
nodes = append(nodes, reqs[i])
}
}
return
}
// NodeRequest describes a request for a node.
type NodeRequest struct {
Name string
IP net.IP
Config runtime.Configurator
// Share of CPUs, in 1e-9 fractions
NanoCPUs int64
// Memory limit in bytes
Memory int64
// Disk (volume) size in bytes, if applicable
DiskSize int64
}