Orzelius 7914fb1041
chore: move the create command to it's own package
This is the first change in the cluster create command refactor project.
The changes will be split into small parts to make review and catching bugs easier.

The command has to be imported in cmd/root.go because it can't be referenced in the mgmt/cluster package as that would create a cyclic import.
This can be fixed later by separating the logic between a third package.

Signed-off-by: Orzelius <33936483+Orzelius@users.noreply.github.com>
Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2025-05-01 14:10:39 +04:00

47 lines
1.1 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 providers
import (
"context"
"fmt"
"github.com/siderolabs/talos/pkg/provision"
"github.com/siderolabs/talos/pkg/provision/providers/docker"
)
const (
// QemuProviderName is the name of the qemu provider.
QemuProviderName = "qemu"
// DockerProviderName is the name of the docker provider.
DockerProviderName = "docker"
)
// Factory instantiates provision provider by name.
func Factory(ctx context.Context, name string) (provision.Provisioner, error) {
if err := IsValidProvider(name); err != nil {
return nil, err
}
switch name {
case DockerProviderName:
return docker.NewProvisioner(ctx)
case QemuProviderName:
return newQemu(ctx)
}
panic("unknown valid provisioner")
}
// IsValidProvider returns an error if the passed provider doesn't exist.
func IsValidProvider(name string) error {
switch name {
case QemuProviderName, DockerProviderName:
return nil
}
return fmt.Errorf("unsupported provisioner %q", name)
}