mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-18 12:37:05 +02:00
This change is only moving packages and updating import paths. Goal: expose `internal/pkg/provision` as `pkg/provision` to enable other projects to import Talos provisioning library. As cluster checks are almost always required as part of provisioning process, package `internal/pkg/cluster` was also made public as `pkg/cluster`. Other changes were direct dependencies discovered by `importvet` which were updated. Public packages (useful, general purpose packages with stable API): * `internal/pkg/conditions` -> `pkg/conditions` * `internal/pkg/tail` -> `pkg/tail` Private packages (used only on provisioning library internally): * `internal/pkg/inmemhttp` -> `pkg/provision/internal/inmemhttp` * `internal/pkg/kernel/vmlinuz` -> `pkg/provision/internal/vmlinuz` * `internal/pkg/cniutils` -> `pkg/provision/internal/cniutils` Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
115 lines
2.5 KiB
Go
115 lines
2.5 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/pkg/config"
|
|
"github.com/talos-systems/talos/pkg/config/types/v1alpha1/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
|
|
|
|
// Path to talosctl executable to re-execute itself as needed.
|
|
SelfExecutable string
|
|
|
|
// Path to root of state directory (~/.talos/clusters by default).
|
|
StateDirectory string
|
|
}
|
|
|
|
// CNIConfig describes CNI part of NetworkRequest.
|
|
type CNIConfig struct {
|
|
BinPath []string
|
|
ConfDir string
|
|
CacheDir string
|
|
}
|
|
|
|
// NetworkRequest describes cluster network.
|
|
type NetworkRequest struct {
|
|
Name string
|
|
CIDR net.IPNet
|
|
GatewayAddr net.IP
|
|
MTU int
|
|
Nameservers []net.IP
|
|
|
|
// 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.TypeJoin {
|
|
nodes = append(nodes, reqs[i])
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// NodeRequest describes a request for a node.
|
|
type NodeRequest struct {
|
|
Name string
|
|
IP net.IP
|
|
Config config.Provider
|
|
|
|
// Share of CPUs, in 1e-9 fractions
|
|
NanoCPUs int64
|
|
// Memory limit in bytes
|
|
Memory int64
|
|
// Disk (volume) size in bytes, if applicable
|
|
DiskSize int64
|
|
// Ports
|
|
Ports []string
|
|
}
|