talos/pkg/provision/options.go
Andrey Smirnov 9379cf9ee1 refactor: expose provision as public package
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>
2020-08-12 05:12:05 -07:00

116 lines
2.6 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 (
"io"
"os"
"runtime"
"github.com/talos-systems/talos/pkg/client"
"github.com/talos-systems/talos/pkg/client/config"
)
// Option controls Provisioner.
type Option func(o *Options) error
// WithLogWriter sets logging destination.
func WithLogWriter(w io.Writer) Option {
return func(o *Options) error {
o.LogWriter = w
return nil
}
}
// WithEndpoint specifies endpoint to use when acessing Talos cluster.
func WithEndpoint(endpoint string) Option {
return func(o *Options) error {
o.ForceEndpoint = endpoint
return nil
}
}
// WithTalosConfig specifies talosconfig to use when acessing Talos cluster.
func WithTalosConfig(talosConfig *config.Config) Option {
return func(o *Options) error {
o.TalosConfig = talosConfig
return nil
}
}
// WithTalosClient specifies client to use when acessing Talos cluster.
func WithTalosClient(client *client.Client) Option {
return func(o *Options) error {
o.TalosClient = client
return nil
}
}
// WithBootlader enables or disables bootloader (bootloader is enabled by default).
func WithBootlader(enabled bool) Option {
return func(o *Options) error {
o.BootloaderEnabled = enabled
return nil
}
}
// WithTargetArch specifies target architecture for the cluster.
func WithTargetArch(arch string) Option {
return func(o *Options) error {
o.TargetArch = arch
return nil
}
}
// WithDockerPorts allows docker provisioner to expose ports on workers.
func WithDockerPorts(ports []string) Option {
return func(o *Options) error {
o.DockerPorts = ports
return nil
}
}
// WithDockerPortsHostIP sets host IP for docker provisioner to expose ports on workers.
func WithDockerPortsHostIP(hostIP string) Option {
return func(o *Options) error {
o.DockerPortsHostIP = hostIP
return nil
}
}
// Options describes Provisioner parameters.
type Options struct {
LogWriter io.Writer
TalosConfig *config.Config
TalosClient *client.Client
ForceEndpoint string
TargetArch string
// Enable bootloader by booting from disk image after install.
BootloaderEnabled bool
// Expose ports to worker machines in docker provisioner
DockerPorts []string
DockerPortsHostIP string
}
// DefaultOptions returns default options.
func DefaultOptions() Options {
return Options{
BootloaderEnabled: true,
TargetArch: runtime.GOARCH,
LogWriter: os.Stderr,
DockerPortsHostIP: "0.0.0.0",
}
}