Skip to content

Commit b9bc716

Browse files
committed
refactor: split cluster create logic into smaller parts
* Create the following packages under `/create`: - `flags` containing the pflag.Value implementations - `clusterops` containing the options for cluster creation - `configmaker` containing the logic that aids in creation of talos and provision configuration for cluster creation - internal `makers` and `siderolinkbuilder` packages that hide the internal logic that configmaker uses * Remove code duplication of default values. Now all default values come from the clusterops Get functions. * Add unit tests for flag implementations. * Add tests that compare machine configs generated for cluster create to default configs. These tests also functions as snapshot tests and will asure no undesired changes pass through in the future unnoticed. Signed-off-by: Orzelius <33936483+Orzelius@users.noreply.github.com>
1 parent a28e5cb commit b9bc716

File tree

25 files changed

+2586
-2160
lines changed

25 files changed

+2586
-2160
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package configmaker
6+
7+
import (
8+
"github.com/siderolabs/talos/cmd/talosctl/cmd/mgmt/cluster/create/clusterops"
9+
"github.com/siderolabs/talos/cmd/talosctl/cmd/mgmt/cluster/create/clusterops/configmaker/internal/makers"
10+
)
11+
12+
// DockerOptions are the options for provisioning a docker based Talos cluster.
13+
type DockerOptions makers.MakerOptions[clusterops.Docker]
14+
15+
// GetDockerConfigs returns the cluster configs for docker.
16+
func GetDockerConfigs(options DockerOptions) (clusterops.ClusterConfigs, error) {
17+
maker, err := makers.NewDocker(options)
18+
if err != nil {
19+
return clusterops.ClusterConfigs{}, err
20+
}
21+
22+
return maker.GetClusterConfigs()
23+
}
24+
25+
// QemuOptions are the options for provisioning a qemu based Talos cluster.
26+
type QemuOptions makers.MakerOptions[clusterops.Qemu]
27+
28+
// GetQemuConfigs returns the cluster configs for qemu.
29+
func GetQemuConfigs(options QemuOptions) (clusterops.ClusterConfigs, error) {
30+
maker, err := makers.NewQemu(options)
31+
if err != nil {
32+
return clusterops.ClusterConfigs{}, err
33+
}
34+
35+
return maker.GetClusterConfigs()
36+
}

0 commit comments

Comments
 (0)