mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-20 22:21:13 +02:00
This PR will allow users to issue `osctl config generate`, tweak the configs to their liking, then use those configs to call `osctl cluster create`. Example workflow: ``` osctl config generate my-cluster https://10.5.0.2:6443 -o ./my-cluster ** tweaky tweak ** osctl cluster create --name my-cluster --input-dir "$PWD/my-cluster" ``` Signed-off-by: Spencer Smith <robertspencersmith@gmail.com>
92 lines
2.0 KiB
Go
92 lines
2.0 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/types/v1alpha1/generate"
|
|
)
|
|
|
|
// ClusterRequest is the root object describing cluster to be provisioned.
|
|
type ClusterRequest struct {
|
|
Name string
|
|
|
|
Network NetworkRequest
|
|
Nodes NodeRequests
|
|
|
|
Image string
|
|
KubernetesVersion string
|
|
}
|
|
|
|
// NetworkRequest describe cluster network.
|
|
type NetworkRequest struct {
|
|
Name string
|
|
CIDR net.IPNet
|
|
MTU int
|
|
}
|
|
|
|
// 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].Type == generate.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].Type == generate.TypeInit || reqs[i].Type == generate.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].Type == generate.TypeJoin {
|
|
nodes = append(nodes, reqs[i])
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// NodeRequest describes a request for a node.
|
|
type NodeRequest struct {
|
|
Type generate.Type
|
|
Name string
|
|
IP net.IP
|
|
ConfigData string
|
|
|
|
// Share of CPUs, in 1e-9 fractions
|
|
NanoCPUs int64
|
|
// Memory limit in bytes
|
|
Memory int64
|
|
}
|