Documentation
¶
Overview ¶
Package service provides an init-system-agnostic interface for installing, enabling, and controlling the KubeSolo system service.
Each init system (systemd, OpenRC, SysV, s6, runit, upstart) is implemented as a separate type that satisfies the Manager interface. The Daemon and Foreground runners implement the non-service run modes.
Index ¶
- func BackupDatastore(name, image string, target RollbackTarget) error
- func ContainerExists(name string) bool
- func ContainerExistsByName(cname string) bool
- func ContainerLogTail(name string, lines int) ([]string, error)
- func ContainerNameFor(name string) string
- func ContainerVersion(name string) (string, error)
- func FilePath(init detect.InitSystem) string
- func FinishRestore(name, image string, undo bool) error
- func GetContainerAPIPort(name string) (int, error)
- func GetContainerD2KPort(name string) (int, error)
- func InspectInstance(name string) (*container.InspectResponse, error)
- func InstanceExists(name string) bool
- func LoadImages(name string, images []string) ([]string, error)
- func LockInstance(name string) (func(), error)
- func ParseContainerMounts(spec string) ([]string, error)
- func ParseContainerPorts(spec string) (nat.PortSet, nat.PortMap, error)
- func PullImage(img string) error
- func ReadContainerConfig(name string) ([]byte, error)
- func RemoveContainerConfigVolume(name string) (bool, error)
- func RemoveContainerNetwork(name string) (bool, error)
- func RemoveContainerVolume(name string) (bool, error)
- func ReplaceContainer(name string, cfg *config.Config, cmdArgs []string, configDoc []byte, ...) error
- func ResetContainer(name string) error
- func RestoreDatastore(name, image string) error
- func RollbackImage(t RollbackTarget) (string, error)
- func SettleBackup(name, image string) error
- func StartContainer(name string) error
- func StopContainer(name string) error
- func StreamLogs(name string, follow bool, tail string, w io.Writer) error
- func WriteContainerConfig(name string, doc []byte) error
- type Instance
- type Manager
- type RollbackTarget
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackupDatastore ¶ added in v1.2.3
func BackupDatastore(name, image string, target RollbackTarget) error
BackupDatastore copies the datastore of the named instance, whose container must be stopped, into the backup, with target describing how to return to it. image runs the copy; it is the image of the stopped container.
func ContainerExists ¶
ContainerExists reports whether the KubeSolo container for the given instance name exists. Convenience wrapper around ContainerExistsByName.
func ContainerExistsByName ¶
ContainerExistsByName reports whether a container with the given name exists (running or stopped). It returns false — never an error — when the container engine is unreachable or no such container exists, so callers can use it to detect container run mode on any host without a hard dependency on a reachable engine (a host-service install on a box with no engine simply reports false).
func ContainerLogTail ¶ added in v1.2.3
ContainerLogTail returns the last lines KubeSolo logged in the named instance's container, for reporting why it failed to come up.
func ContainerNameFor ¶
ContainerNameFor returns the Docker container name for a given instance name. The default name ("kubesolo") is used as-is; any other name is prefixed with "kubesolo-" to namespace it away from unrelated Docker workloads.
func ContainerVersion ¶ added in v1.2.3
ContainerVersion returns the version of KubeSolo in the named instance's running container, as the binary reports it.
func FilePath ¶ added in v1.2.1
func FilePath(init detect.InitSystem) string
FilePath returns the service definition an init system was installed with, or empty if the init system is not one KubeSolo writes a file for.
It exists so that an upgrade can read back the command line a previous install wrote, and convert it into a configuration file.
func FinishRestore ¶ added in v1.2.3
FinishRestore drops the backup a healthy restored container now runs. undo is true when the upgrade that took the backup failed: the backup it replaced becomes the rollback target again.
func GetContainerAPIPort ¶
GetContainerAPIPort returns the host port Docker mapped to the container's API server (6443/tcp). Call this after Install to discover the port.
func GetContainerD2KPort ¶
GetContainerD2KPort returns the host port Docker mapped to the container's D2K endpoint (2376/tcp). Returns an error if D2K was not enabled on this instance (port not published), guiding the user to reinstall with --d2k.
func InspectInstance ¶ added in v1.2.3
func InspectInstance(name string) (*container.InspectResponse, error)
InspectInstance returns the named instance's container as the engine reports it.
func InstanceExists ¶ added in v1.2.3
InstanceExists reports whether anything of the named container instance is left: its container, network, data volume or configuration volume. A container removed by hand leaves the other two behind, and uninstall must still find them.
func LoadImages ¶ added in v1.2.3
LoadImages copies images from the engine into the named instance's KubeSolo, as kind load docker-image does for a kind node: the engine saves them as an archive, which KubeSolo imports inside the container. It returns the names the images were imported under.
func LockInstance ¶ added in v1.2.3
LockInstance takes the lock that serialises the commands which replace the named instance's container — install, upgrade, rollback, reset, uninstall — so that two of them cannot interleave their stops, backups and replacements. It fails at once when another holds it, and returns the function that releases it. The lock is a file in this user's cache directory, keyed by the engine and the container: it serialises kubesoloctl on this machine, not clients of a remote engine elsewhere.
func ParseContainerMounts ¶ added in v1.2.3
ParseContainerMounts parses a comma-separated list of SRC:DST[:ro|rw] host directory mounts for the KubeSolo container — kind's extraMounts — into Docker binds. Both paths must be absolute. KubeSolo's data and configuration volumes and kernel modules cannot be replaced, but a directory inside the data volume can be mounted over, for example containerd's registry configuration.
func ParseContainerPorts ¶
ParseContainerPorts turns a --container-ports value into the exposed-port set and host port bindings to publish on the KubeSolo container.
The value is a comma-separated list of entries. Each entry is one of:
9001 bare port → host 9001 : container 9001 9000-9100 range → host range : same container range (1:1) 8080:80 explicit → host 8080 : container 80 127.0.0.1:80:80 bound IP → only that host IP 53/udp protocol → tcp is assumed when omitted
Bare ports and ranges map host==container (the common case for exposing a workload, like Kind's extraPortMappings). Explicit host:container and ip:host:container forms are passed through to Docker's standard parser.
func ReadContainerConfig ¶ added in v1.2.3
ReadContainerConfig returns the configuration file of the named instance's container, running or not.
func RemoveContainerConfigVolume ¶ added in v1.2.3
RemoveContainerConfigVolume removes the configuration volume of the named instance, reporting whether there was one.
func RemoveContainerNetwork ¶ added in v1.2.3
RemoveContainerNetwork removes the named instance's network, reporting whether there was one to remove.
func RemoveContainerVolume ¶
RemoveContainerVolume removes the data volume for the named instance. Called during uninstall --purge to delete all cluster state.
func ReplaceContainer ¶ added in v1.2.3
func ReplaceContainer(name string, cfg *config.Config, cmdArgs []string, configDoc []byte, prev *container.InspectResponse) error
ReplaceContainer replaces the named instance's container, if it has one, with a new one running cfg's image with cmdArgs. A non-nil configDoc becomes its configuration file; nil keeps the one in its configuration volume. The hostname, host ports and proxy carry over from prev, the container being replaced as it was before anything changed; nil means there is none. An upgrade passes the snapshot it took before stopping the container, so a rollback restores them even when the new container could not be created.
func ResetContainer ¶
ResetContainer wipes cluster state and starts fresh: it captures the existing container's image and CMD, removes the container and data volume, then re-creates the container with the same configuration.
func RestoreDatastore ¶ added in v1.2.3
RestoreDatastore puts a copy of the backup's datastore in place of the named instance's, whose container must be stopped. The backup itself is kept, so that a restored container which fails to come up can be rolled back again; FinishRestore drops it once the restored container is healthy.
func RollbackImage ¶ added in v1.2.3
func RollbackImage(t RollbackTarget) (string, error)
RollbackImage returns the image a rollback to t restores: its tag while the tag still names the image that ran before the upgrade, so the restored container looks as it did, and otherwise that image by its ID. A target recorded without an ID only has its tag.
func SettleBackup ¶ added in v1.2.3
SettleBackup drops the backup an upgrade replaced, once the upgrade has proven healthy.
func StartContainer ¶ added in v1.2.3
StartContainer starts the named instance's container.
func StopContainer ¶ added in v1.2.3
StopContainer stops the named instance's container, giving KubeSolo time to shut down cleanly.
func StreamLogs ¶ added in v1.2.3
StreamLogs writes what KubeSolo logged in the named instance's container to w: the last tail lines ("all" for everything), and, with follow, everything it logs afterwards until it stops.
func WriteContainerConfig ¶ added in v1.2.3
WriteContainerConfig replaces the configuration file of the named instance's container, running or not. KubeSolo reads it when it next starts.
Types ¶
type Instance ¶ added in v1.2.3
type Instance struct {
Name string `json:"name"`
Container string `json:"container"`
Image string `json:"image"`
State string `json:"state"`
APIServer string `json:"apiServer,omitempty"`
}
Instance is a KubeSolo container instance as the engine reports it.
func ListInstances ¶ added in v1.2.3
ListInstances returns the KubeSolo container instances on the engine: the containers named as ContainerNameFor names them that hold a KubeSolo data volume.
type Manager ¶
type Manager interface {
// Install writes service files and configures the service to start on boot.
Install(cfg *config.Config, cmdArgs []string) error
// Uninstall removes service files and disables the service.
Uninstall() error
}
Manager is the interface every service backend must implement.
type RollbackTarget ¶ added in v1.2.3
type RollbackTarget struct {
Image string `json:"image"`
// ImageID is the image that ran, which a tag such as :develop can stop
// naming when the upgrade pulls it again.
ImageID string `json:"imageID,omitempty"`
Args []string `json:"args"`
Version string `json:"version,omitempty"`
Created time.Time `json:"created"`
}
RollbackTarget is what a container upgrade replaced, and what a rollback restores.
func ReadRollbackTarget ¶ added in v1.2.3
func ReadRollbackTarget(name string) (*RollbackTarget, error)
ReadRollbackTarget returns the named instance's rollback target, or nil when it has none.