kubernetes

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAttached = errors2.Sentinel("not attached to instance")

Functions

This section is empty.

Types

type Environment

type Environment struct {

	// The public identifier for this environment. In this case it is the Docker container
	// name that will be used for all instances created under it.
	Id string

	// The environment configuration.
	Configuration *environment.Configuration
	// contains filtered or unexported fields
}

func New

New creates a new base Kubernetes environment. The ID passed through will be the ID that is used to reference the container from here on out. This should be unique per-server (we use the UUID by default). The container does not need to exist at this point.

func (*Environment) Attach

func (e *Environment) Attach(ctx context.Context) error

Attach attaches to the docker container itself and ensures that we can pipe data in and out of the process stream. This should always be called before you have started the container, but after you've ensured it exists.

Calling this function will poll resources for the container in the background until the container is stopped. The context provided to this function is used for the purposes of attaching to the container, a second context is created within the function for managing polling.

func (*Environment) Config

func (e *Environment) Config() *environment.Configuration

Config returns the environment configuration allowing a process to make modifications of the environment on the fly.

func (*Environment) Create

func (e *Environment) Create() error

Create creates a new container for the server using all the data that is currently available for it. If the container already exists it will be returned.

func (*Environment) CreateSFTP

func (e *Environment) CreateSFTP(ctx context.Context) error

func (*Environment) CreateService

func (e *Environment) CreateService() error

Google GKE Autopilot May not contain more than 1 protocol when type is 'LoadBalancer'.

func (*Environment) CreateServiceWithUniquePort

func (e *Environment) CreateServiceWithUniquePort() (int, error)

func (*Environment) Destroy

func (e *Environment) Destroy() error

Destroy will remove all K8s resources of this server. If the pod is currently running it will be forcibly stopped.

func (*Environment) Events

func (e *Environment) Events() *events.Bus

Events returns an event bus for the environment.

func (*Environment) Exists

func (e *Environment) Exists() (bool, error)

Exists determines if the container exists in this environment. The ID passed through should be the server UUID since containers are created utilizing the server UUID as the name and docker will work fine when using the container name as the lookup parameter in addition to the longer ID auto-assigned when the container is created.

func (*Environment) ExitState

func (e *Environment) ExitState() (uint32, bool, error)

ExitState returns the container exit state, the exit code and whether or not the container was killed by the OOM killer.

func (*Environment) GetServiceDetails

func (e *Environment) GetServiceDetails() []v1.Service

func (*Environment) InSituUpdate

func (e *Environment) InSituUpdate() error

func (*Environment) IsAttached

func (e *Environment) IsAttached() bool

IsAttached determines if this process is currently attached to the container instance by checking if the stream is nil or not.

func (*Environment) IsRunning

func (e *Environment) IsRunning(ctx context.Context) (bool, error)

IsRunning determines if the server's process container is currently running. If there is no container present, an error will be raised (since this shouldn't be a case that ever happens under correctly developed circumstances).

func (*Environment) OnBeforeStart

func (e *Environment) OnBeforeStart(ctx context.Context) error

OnBeforeStart run before the container starts and get the process configuration from the Panel. This is important since we use this to check configuration files as well as ensure we always have the latest version of a rocket available for server processes.

This process will also confirm that the server environment exists and is in a bootable state. This ensures that unexpected container deletion while Kuber is running does not result in the server becoming un-bootable.

func (*Environment) Readlog

func (e *Environment) Readlog(lines int) ([]string, error)

Readlog reads the log file for the server. This does not care if the server is running or not, it will simply try to read the last X bytes of the file and return them.

func (*Environment) SendCommand

func (e *Environment) SendCommand(c string) error

SendCommand sends the specified command to the stdin of the running container instance. There is no confirmation that this data is sent successfully, only that it gets pushed into the stdin.

func (*Environment) SetImage

func (e *Environment) SetImage(i string)

func (*Environment) SetLogCallback

func (e *Environment) SetLogCallback(f func([]byte))

func (*Environment) SetState

func (e *Environment) SetState(state string)

SetState sets the state of the environment. This emits an event that server's can hook into to take their own actions and track their own state based on the environment.

func (*Environment) SetStopConfiguration

func (e *Environment) SetStopConfiguration(c remote.ProcessStopConfiguration)

SetStopConfiguration sets the stop configuration for the environment.

func (*Environment) SetStream

func (e *Environment) SetStream(s remotecommand.Executor)

SetStream sets the current stream value from the Kubernetes remotecommand.Executor. If a nil value is provided we assume that the stream is no longer operational and the instance is effectively offline.

func (*Environment) Start

func (e *Environment) Start(ctx context.Context) error

Start will start the server environment and begins piping output to the event listeners for the console. If a container does not exist, or needs to be rebuilt that will happen in the call to OnBeforeStart().

func (*Environment) State

func (e *Environment) State() string

func (*Environment) Stop

func (e *Environment) Stop(ctx context.Context) error

Stop stops the container that the server is running in. This will allow up to 30 seconds to pass before the container is forcefully terminated if we are trying to stop it without using a command sent into the instance.

You most likely want to be using WaitForStop() rather than this function, since this will return as soon as the command is sent, rather than waiting for the process to be completed stopped.

func (*Environment) Terminate

func (e *Environment) Terminate(ctx context.Context) error

Terminate forcefully terminates the container using the signal provided.

func (*Environment) Type

func (e *Environment) Type() string

func (*Environment) Uptime

func (e *Environment) Uptime(ctx context.Context) (int64, error)

Uptime returns the current uptime of the container in milliseconds. If the container is not currently running this will return 0.

func (*Environment) WaitForStop

func (e *Environment) WaitForStop(ctx context.Context, duration time.Duration, terminate bool) error

WaitForStop attempts to gracefully stop a server using the defined stop command. If the server does not stop after seconds have passed, an error will be returned, or the instance will be terminated forcefully depending on the value of the second argument.

Calls to Environment.Terminate() in this function use the context passed through since we don't want to prevent termination of the server instance just because the context.WithTimeout() has expired.

func (*Environment) WatchPodEvents

func (e *Environment) WatchPodEvents(ctx context.Context) error

type Metadata

type Metadata struct {
	Image string
	Stop  remote.ProcessStopConfiguration
}

Jump to

Keyboard shortcuts

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