hooks

package
v0.0.0-...-3bfe646 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 32 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// InitContainerName is the name for the init container
	InitContainerName = "init"

	// ContainerHostBinDir is where /usr/bin directory from host gets mounted inside hook containers
	ContainerHostBinDir = "/opt/bin"

	// ContainerPath is the default PATH inside hook containers
	ContainerPath = "/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

	// ResourcesDir is where the app's resources directory is mounted inside a hook container
	ResourcesDir = "/var/lib/gravity/resources"

	// HelmDir is the directory inside hooks where helm values files is mounted
	HelmDir = "/var/lib/gravity/helm"

	// GravityDir is the root directory with gravity state
	GravityDir = "/var/lib/gravity"

	// StateDir specifies the directory for temporary state during hook's lifetime
	StateDir = "/tmp/state"

	// ContainerBackupDir defines a directory mounted inside a hook container that the backup/restore hooks
	// store/read backup results to/from
	ContainerBackupDir = "/var/lib/gravity/backup"

	// KubectlPath is where kubectl binary gets mounted inside hook containers
	KubectlPath = "/usr/local/bin/kubectl"

	// HelmPath is where helm binary gets mounted inside hook containers
	HelmPath = "/usr/local/bin/helm"

	// Helm3Path is where helm3 binary gets mounted inside hook containers
	Helm3Path = "/usr/local/bin/helm3"

	// HelmValuesFile is the name of the file with helm values
	HelmValuesFile = "values.yaml"

	// VolumeBin is the name of the volume with host's /usr/bin dir
	VolumeBin = "bin"

	// VolumeKubectlBin is the name of the volume with kubectl
	VolumeKubectlBin = "kubectl-bin"

	// VolumeHelmBin is the name of the volume with helm binary
	VolumeHelmBin = "helm-bin"

	// VolumeHelm3Bin is the name of the volume with helm3 binary
	VolumeHelm3Bin = "helm-3-bin"

	// VolumeHelm is the name of the volume with helm values file
	VolumeHelm = "helm"

	// VolumeBackup is the name of the volume that stores results of the backup hook
	// as mounted inside the hook container
	VolumeBackup = "backup"

	// VolumeCerts is the name of the volume with host's certificates
	VolumeCerts = "certs"

	// VolumeGravity is the name of the volume with local gravity state
	VolumeGravity = "gravity"

	// VolumeResources is the name of the volume with unpacked app resources
	VolumeResources = "resources"

	// VolumeStateDir is the name of the volume for temporary state
	VolumeStateDir = "state-dir"

	// ApplicationPackageEnv specifies the name of the environment variable
	// that defines the name of the application package the hook originated from.
	// This environment variable is made available to the hook job's init container
	ApplicationPackageEnv = "APP_PACKAGE"

	// PodIPEnv specifies the name of variable associated with Pod IP address
	PodIPEnv = "POD_IP"
)

Variables

View Source
var InitContainerImage = fmt.Sprintf("%v/gravitational/debian-tall:buster", defaults.DockerRegistry)

InitContainerImage is the image for the init container

Functions

This section is empty.

Types

type DeleteJobRequest

type DeleteJobRequest struct {
	// JobRef identifies the job to delete.
	JobRef
	// Cascade specifies whether dependent objects should be deleted.
	Cascade bool
}

DeleteJobRequest combines parameters for job deletion.

type JobRef

type JobRef struct {
	// Name is a job name
	Name string
	// Namespace is a namespace where job was launched
	Namespace string
}

JobRef is a reference to a hook job

type Params

type Params struct {
	// Hook is job hook
	Hook *schema.Hook
	// Locator is a locator for the app this runner is running hooks for.
	Locator loc.Locator
	// Env contains environment variables that will be made available inside
	// hooks containers
	Env map[string]string
	// Volumes lists additional volumes to add inside a hook job
	Volumes []v1.Volume
	// Mounts lists additional mounts to create inside a hook job
	Mounts []v1.VolumeMount
	// NodeSelector defines the optional set of labels to specify as a node selector
	// instead of the one used by default
	NodeSelector map[string]string
	// SkipInitContainers skips injection of init containers
	SkipInitContainers bool
	// HostNetwork tells the job to use the host network
	HostNetwork bool
	// JobDeadline allows to set specific hook job deadline
	JobDeadline time.Duration
	// AgentUser is the agent username for logging into local cluster
	AgentUser string
	// AgentPassword is the agent password for logging into local cluster
	AgentPassword string
	// GravityPackage references the gravity binary package to run hooks with.
	// If empty, the binary mapped from host is used.
	GravityPackage loc.Locator
	// ServiceUser specifies the service user which overrides the default
	// security context for the job's Pod
	ServiceUser storage.OSUser
	// Values are helm values in a marshaled yaml format
	Values []byte
}

Params specifies hook parameters

func (*Params) CheckAndSetDefaults

func (p *Params) CheckAndSetDefaults() error

CheckAndSetDefaults checks and sets defaults for client

type Runner

type Runner struct {
	*log.Entry
	// contains filtered or unexported fields
}

Runner encapsulates the process of running an application hook

func NewRunner

func NewRunner(client *kubernetes.Clientset) (*Runner, error)

NewRunner creates a new application hook runner instance

func (*Runner) DeleteJob

func (r *Runner) DeleteJob(ctx context.Context, req DeleteJobRequest) error

DeleteJob deletes job by ref

func (*Runner) Start

func (r *Runner) Start(ctx context.Context, p Params) (*JobRef, error)

Start configures and starts job, does not wait until job is complete or fails, the call does not wait for the job to complete

func (*Runner) StreamLogs

func (r *Runner) StreamLogs(ctx context.Context, ref JobRef, out io.Writer) error

StreamLogs streams logs until the job is either failed or done

func (*Runner) Wait

func (r *Runner) Wait(ctx context.Context, ref JobRef) error

Wait waits for job to complete or fail, cancel on the context cancels the wait call that is otherwise blocking

Jump to

Keyboard shortcuts

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