runtime

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 38 Imported by: 1

Documentation

Overview

Package runtime defines the interface of a cluster operation and providers a register method.

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfigName              = consts.ConfigName
	InHostKubeconfigName    = "kubeconfig.yaml"
	InClusterKubeconfigName = "kubeconfig"
	EtcdDataDirName         = "etcd"
	PkiName                 = "pki"
	ManifestsName           = "manifests"
	Prometheus              = "prometheus.yaml"
	KindName                = "kind.yaml"
	AuditPolicyName         = "audit.yaml"
	AuditLogName            = "audit.log"
	SchedulerConfigName     = "scheduler.yaml"
	ApiserverTracingConfig  = "apiserver-tracing-config.yaml"

	// ComposeName is the default name of the docker-compose file
	// Deprecated: *-compose will be removed in the future
	ComposeName = "docker-compose.yaml"
)

The following functions are used to get the path of the cluster

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the default registry

View Source
var (
	// ErrComponentNotFound is returned when a component is not found
	ErrComponentNotFound = fmt.Errorf("component not found")
)

Functions

func ApplyComponentPatches added in v0.5.0

func ApplyComponentPatches(component *internalversion.Component, patches []internalversion.ComponentPatches)

ApplyComponentPatches applies patches to a component.

func ExpandVolumesHostPaths added in v0.2.0

func ExpandVolumesHostPaths(volumes []internalversion.Volume) ([]internalversion.Volume, error)

ExpandVolumesHostPaths expands relative paths specified in volumes to absolute paths

func FormatExec added in v0.4.0

func FormatExec(ctx context.Context, name string, args ...string) string

FormatExec prints the command to be executed to the output stream.

func GetComponentPatches added in v0.2.0

func GetComponentPatches(conf *internalversion.KwokctlConfiguration, componentName string) internalversion.ComponentPatches

GetComponentPatches returns the patches for a component.

func GetLogVolumes added in v0.2.0

func GetLogVolumes(ctx context.Context) []internalversion.Volume

GetLogVolumes returns volumes for Logs and ClusterLogs resource.

func GetUsedPorts added in v0.5.0

func GetUsedPorts(ctx context.Context) (rets sets.Sets[uint32])

GetUsedPorts returns the list of ports used by the clusters in the directory

func ListClusters

func ListClusters(ctx context.Context) ([]string, error)

ListClusters returns the list of clusters in the directory

Types

type BuildRuntime

type BuildRuntime func(name, workdir string) (Runtime, error)

BuildRuntime is a function to build a runtime

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

Cluster is the cluster

func NewCluster

func NewCluster(name, workdir string) *Cluster

NewCluster creates a new cluster

func (*Cluster) AppendToFile added in v0.4.0

func (c *Cluster) AppendToFile(name string, content []byte) error

AppendToFile appends content to a file.

func (*Cluster) AuditLogs

func (c *Cluster) AuditLogs(ctx context.Context, out io.Writer) error

AuditLogs returns the audit logs of the cluster.

func (*Cluster) AuditLogsFollow

func (c *Cluster) AuditLogsFollow(ctx context.Context, out io.Writer) error

AuditLogsFollow follows the audit logs of the cluster.

func (*Cluster) Config

Config returns the cluster config

func (*Cluster) CopyFile added in v0.4.0

func (c *Cluster) CopyFile(oldpath, newpath string) error

CopyFile copies a file from src to dst.

func (*Cluster) CopySchedulerConfig added in v0.4.0

func (c *Cluster) CopySchedulerConfig(oldpath, newpath, kubeconfig string) error

CopySchedulerConfig copies the scheduler configuration file to the given path.

func (*Cluster) CreateFile added in v0.4.0

func (c *Cluster) CreateFile(name string) error

CreateFile creates a file.

func (*Cluster) DownloadWithCache added in v0.4.0

func (c *Cluster) DownloadWithCache(ctx context.Context, cacheDir, src, dest string, mode fs.FileMode, quiet bool) error

DownloadWithCache downloads the src file to the dest file.

func (*Cluster) EnsureBinary added in v0.5.0

func (c *Cluster) EnsureBinary(ctx context.Context, name, binary string) (string, error)

EnsureBinary ensures the binary exists.

func (*Cluster) EnsureImage added in v0.5.0

func (c *Cluster) EnsureImage(ctx context.Context, command string, image string) error

EnsureImage ensures the image exists.

func (*Cluster) Etcdctl added in v0.3.0

func (c *Cluster) Etcdctl(ctx context.Context, args ...string) error

Etcdctl runs etcdctl.

func (*Cluster) Exec added in v0.4.0

func (c *Cluster) Exec(ctx context.Context, name string, args ...string) error

Exec executes the given command and returns the output.

func (*Cluster) ForeachComponents added in v0.4.0

func (c *Cluster) ForeachComponents(ctx context.Context, reverse, order bool, fun func(ctx context.Context, component internalversion.Component) error) error

ForeachComponents starts components.

func (*Cluster) ForkExec added in v0.4.0

func (c *Cluster) ForkExec(ctx context.Context, dir string, name string, args ...string) error

ForkExec forks a new process and execs the given command. The process will be terminated when the context is canceled.

func (*Cluster) ForkExecIsRunning added in v0.4.0

func (c *Cluster) ForkExecIsRunning(ctx context.Context, dir string, name string) bool

ForkExecIsRunning checks if the process is running.

func (*Cluster) ForkExecKill added in v0.4.0

func (c *Cluster) ForkExecKill(ctx context.Context, dir string, name string) error

ForkExecKill kills the process if it is running.

func (*Cluster) GeneratePki added in v0.4.0

func (c *Cluster) GeneratePki(pkiPath string, sans ...string) error

GeneratePki generates the pki for kwokctl

func (*Cluster) GetBinPath added in v0.1.0

func (c *Cluster) GetBinPath(name string) string

GetBinPath returns the path to the given binary name.

func (*Cluster) GetClientset added in v0.4.0

func (c *Cluster) GetClientset(ctx context.Context) (client.Clientset, error)

GetClientset returns the clientset of the cluster.

func (*Cluster) GetComponent added in v0.1.0

func (c *Cluster) GetComponent(ctx context.Context, name string) (internalversion.Component, error)

GetComponent returns the component by name

func (*Cluster) GetEtcdClient added in v0.5.0

func (c *Cluster) GetEtcdClient(ctx context.Context) (etcd.Client, error)

GetEtcdClient returns the etcd client of cluster

func (*Cluster) GetLogPath added in v0.1.0

func (c *Cluster) GetLogPath(name string) string

GetLogPath returns the path of the given log name.

func (*Cluster) GetWorkdirPath added in v0.1.0

func (c *Cluster) GetWorkdirPath(name string) string

GetWorkdirPath returns the path to the file in the workdir.

func (*Cluster) InitCRDs added in v0.4.0

func (c *Cluster) InitCRDs(ctx context.Context) error

InitCRDs initializes the CRDs.

func (*Cluster) Install

func (c *Cluster) Install(ctx context.Context) error

Install installs the cluster

func (*Cluster) IsDryRun added in v0.4.0

func (c *Cluster) IsDryRun() bool

IsDryRun returns true if the runtime is in dry-run mode

func (*Cluster) Kubectl

func (c *Cluster) Kubectl(ctx context.Context, args ...string) error

Kubectl runs kubectl.

func (*Cluster) KubectlInCluster

func (c *Cluster) KubectlInCluster(ctx context.Context, args ...string) error

KubectlInCluster runs kubectl in the cluster.

func (*Cluster) ListComponents added in v0.5.0

func (c *Cluster) ListComponents(ctx context.Context) ([]internalversion.Component, error)

ListComponents returns the list of components

func (*Cluster) Load

Load loads the cluster config

func (*Cluster) MkdirAll added in v0.4.0

func (c *Cluster) MkdirAll(name string) error

MkdirAll creates a directory.

func (*Cluster) Name added in v0.1.0

func (c *Cluster) Name() string

Name returns the cluster name

func (*Cluster) OpenFile added in v0.4.0

func (c *Cluster) OpenFile(name string) (io.WriteCloser, error)

OpenFile opens/creates a file for writing.

func (*Cluster) ParseVersionFromBinary added in v0.4.0

func (c *Cluster) ParseVersionFromBinary(ctx context.Context, path string) (version.Version, error)

ParseVersionFromBinary parses the version from the given binary.

func (*Cluster) ParseVersionFromImage added in v0.4.0

func (c *Cluster) ParseVersionFromImage(ctx context.Context, runtime string, image string, command string) (version.Version, error)

ParseVersionFromImage parses the version from the image.

func (*Cluster) PullImages added in v0.4.0

func (c *Cluster) PullImages(ctx context.Context, command string, images []string, quiet bool) error

PullImages is a helper function to pull images

func (*Cluster) Ready

func (c *Cluster) Ready(ctx context.Context) (bool, error)

Ready returns true if the cluster is ready

func (*Cluster) Remove added in v0.4.0

func (c *Cluster) Remove(name string) error

Remove removes a file.

func (*Cluster) RemoveAll added in v0.4.0

func (c *Cluster) RemoveAll(name string) error

RemoveAll removes a directory and all its contents.

func (*Cluster) RenameFile added in v0.4.0

func (c *Cluster) RenameFile(oldpath, newpath string) error

RenameFile renames a file.

func (*Cluster) Save added in v0.1.0

func (c *Cluster) Save(ctx context.Context) error

Save saves the cluster config

func (*Cluster) SetConfig added in v0.1.0

SetConfig sets the cluster config

func (*Cluster) SnapshotRestoreWithYAML added in v0.2.0

func (c *Cluster) SnapshotRestoreWithYAML(ctx context.Context, path string, conf SnapshotRestoreWithYAMLConfig) error

SnapshotRestoreWithYAML restore the snapshot of cluster

func (*Cluster) SnapshotSaveWithYAML added in v0.2.0

func (c *Cluster) SnapshotSaveWithYAML(ctx context.Context, path string, conf SnapshotSaveWithYAMLConfig) error

SnapshotSaveWithYAML save the snapshot of cluster

func (*Cluster) Uninstall

func (c *Cluster) Uninstall(ctx context.Context) error

Uninstall uninstalls the cluster.

func (*Cluster) WaitReady

func (c *Cluster) WaitReady(ctx context.Context, timeout time.Duration) error

WaitReady waits for the cluster to be ready.

func (*Cluster) Workdir added in v0.1.0

func (c *Cluster) Workdir() string

Workdir returns the cluster workdir

func (*Cluster) WriteFile added in v0.4.0

func (c *Cluster) WriteFile(name string, content []byte) error

WriteFile writes content to a file.

func (*Cluster) WriteFileWithMode added in v0.4.0

func (c *Cluster) WriteFileWithMode(name string, content []byte, mode os.FileMode) error

WriteFileWithMode writes content to a file with the given mode.

func (*Cluster) WriteToPath added in v0.4.0

func (c *Cluster) WriteToPath(ctx context.Context, path string, commands []string) error

WriteToPath writes the output of a command to a specified file

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is a registry of runtime

func NewRegistry

func NewRegistry() *Registry

NewRegistry create a new registry

func (*Registry) Get

func (r *Registry) Get(name string) (BuildRuntime, bool)

Get a runtime

func (*Registry) List

func (r *Registry) List() []string

List all registered runtime

func (*Registry) Load

func (r *Registry) Load(ctx context.Context, name, workdir string) (Runtime, error)

Load a runtime

func (*Registry) Register

func (r *Registry) Register(name string, buildRuntime BuildRuntime)

Register a runtime

type Runtime

type Runtime interface {
	// Available checks whether the runtime is available.
	Available(ctx context.Context) error

	// SetConfig sets the config of cluster
	SetConfig(ctx context.Context, conf *internalversion.KwokctlConfiguration) error

	// Save the config of cluster
	Save(ctx context.Context) error

	// Config return the config of cluster
	Config(ctx context.Context) (*internalversion.KwokctlConfiguration, error)

	// Install the cluster
	Install(ctx context.Context) error

	// Uninstall the cluster
	Uninstall(ctx context.Context) error

	// Up start the cluster
	Up(ctx context.Context) error

	// Down stop the cluster
	Down(ctx context.Context) error

	// Start a cluster
	Start(ctx context.Context) error

	// Stop a cluster
	Stop(ctx context.Context) error

	// StartComponent start cluster component
	StartComponent(ctx context.Context, name string) error

	// StopComponent stop cluster component
	StopComponent(ctx context.Context, name string) error

	// GetComponent return the component if it exists
	GetComponent(ctx context.Context, name string) (internalversion.Component, error)

	// ListComponents list the components of cluster
	ListComponents(ctx context.Context) ([]internalversion.Component, error)

	// Ready check the cluster is ready
	Ready(ctx context.Context) (bool, error)

	// WaitReady wait the cluster is ready
	WaitReady(ctx context.Context, timeout time.Duration) error

	// AddContext add the context of cluster to kubeconfig
	AddContext(ctx context.Context, kubeconfigPath string) error

	// RemoveContext remove the context of cluster from kubeconfig
	RemoveContext(ctx context.Context, kubeconfigPath string) error

	// Kubectl command
	Kubectl(ctx context.Context, args ...string) error

	// KubectlInCluster command in cluster
	KubectlInCluster(ctx context.Context, args ...string) error

	// EtcdctlInCluster command in cluster
	EtcdctlInCluster(ctx context.Context, args ...string) error

	// Logs logs of a component
	Logs(ctx context.Context, name string, out io.Writer) error

	// LogsFollow follow logs of a component with follow
	LogsFollow(ctx context.Context, name string, out io.Writer) error

	// CollectLogs will populate dir with cluster logs and other debug files
	CollectLogs(ctx context.Context, dir string) error

	// AuditLogs audit logs of apiserver
	AuditLogs(ctx context.Context, out io.Writer) error

	// AuditLogsFollow follow audit logs of apiserver
	AuditLogsFollow(ctx context.Context, out io.Writer) error

	// ListBinaries list binaries in the cluster
	ListBinaries(ctx context.Context) ([]string, error)

	// ListImages list images in the cluster
	ListImages(ctx context.Context) ([]string, error)

	// SnapshotSave save the snapshot of cluster
	SnapshotSave(ctx context.Context, path string) error

	// SnapshotRestore restore the snapshot of cluster
	SnapshotRestore(ctx context.Context, path string) error

	// SnapshotSaveWithYAML save the snapshot of cluster
	SnapshotSaveWithYAML(ctx context.Context, path string, conf SnapshotSaveWithYAMLConfig) error

	// SnapshotRestoreWithYAML restore the snapshot of cluster
	SnapshotRestoreWithYAML(ctx context.Context, path string, conf SnapshotRestoreWithYAMLConfig) error

	// GetWorkdirPath get the workdir path of cluster
	GetWorkdirPath(name string) string

	// InitCRDs init the crds of cluster
	InitCRDs(ctx context.Context) error

	// InitCRs init the crs of cluster
	InitCRs(ctx context.Context) error

	// IsDryRun returns true if the runtime is in dry-run mode
	IsDryRun() bool

	// GetClientset returns the clientset of cluster
	GetClientset(ctx context.Context) (client.Clientset, error)

	// GetEtcdClient returns the etcd client of cluster
	GetEtcdClient(ctx context.Context) (etcd.Client, error)
}

Runtime is the interface for a runtime.

type SnapshotRestoreWithYAMLConfig added in v0.5.0

type SnapshotRestoreWithYAMLConfig struct {
	Filters []string
}

type SnapshotSaveWithYAMLConfig added in v0.5.0

type SnapshotSaveWithYAMLConfig struct {
	Filters []string
}

Directories

Path Synopsis
Package binary implements the runtime.Runtime interface using the binaries.
Package binary implements the runtime.Runtime interface using the binaries.
Package compose implements the runtime.Runtime interface using the image.
Package compose implements the runtime.Runtime interface using the image.
Package kind implements the runtime.Runtime interface using the kind.
Package kind implements the runtime.Runtime interface using the kind.
config/kind/v1alpha4
Package v1alpha4 copy from https://github.com/kubernetes-sigs/kind/blob/master/pkg/apis/config/v1alpha4/types.go
Package v1alpha4 copy from https://github.com/kubernetes-sigs/kind/blob/master/pkg/apis/config/v1alpha4/types.go
config/kubeadm/v1beta3
Package v1beta3 copy from https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/apis/kubeadm/v1beta3/types.go
Package v1beta3 copy from https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/apis/kubeadm/v1beta3/types.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL