Documentation ¶
Index ¶
- Constants
- func InWRPod() bool
- type AuthConfig
- type CmdOptions
- type ConfigMapOpts
- type FilePair
- type Kubernetesp
- func (p *Kubernetesp) AttachCmd(ctx context.Context, opts *CmdOptions) error
- func (p *Kubernetesp) Authenticate(ctx context.Context, config AuthConfig) (kubernetes.Interface, *rest.Config, error)
- func (p *Kubernetesp) CheckWRDeploymentExists(namespace string) (bool, error)
- func (p *Kubernetesp) CheckWRDeploymentHealthy(namespace string) (bool, error)
- func (p *Kubernetesp) CopyTar(ctx context.Context, files []FilePair, pod *apiv1.Pod) error
- func (p *Kubernetesp) CreateInitScriptConfigMap(script string) (*apiv1.ConfigMap, error)
- func (p *Kubernetesp) CreateInitScriptConfigMapFromFile(scriptPath string) (*apiv1.ConfigMap, error)
- func (p *Kubernetesp) CreateNewNamespace(name string) error
- func (p *Kubernetesp) CreateService(opts *ServiceOpts) error
- func (p *Kubernetesp) Deploy(ctx context.Context, tempMountPath string, command string, cmdArgs []string, ...) error
- func (p *Kubernetesp) DestroyPod(ctx context.Context, podName string) error
- func (p *Kubernetesp) ExecCmd(opts *CmdOptions, namespace string) error
- func (p *Kubernetesp) ExecInPod(podName string, containerName, namespace string, command []string) (string, string, error)
- func (p *Kubernetesp) GetLog(pod *apiv1.Pod, lines int) (string, error)
- func (p *Kubernetesp) Initialize(ctx context.Context, clientset kubernetes.Interface, namespace ...string) error
- func (p *Kubernetesp) NewConfigMap(opts *ConfigMapOpts) (*apiv1.ConfigMap, error)
- func (p *Kubernetesp) PortForward(ctx context.Context, pod *apiv1.Pod, requiredPorts []int) error
- func (p *Kubernetesp) Spawn(ctx context.Context, baseContainerImage string, tempMountPath string, ...) (*apiv1.Pod, error)
- func (p *Kubernetesp) TearDown(ctx context.Context, namespace string) error
- type ResourceRequest
- type ServiceOpts
- type StreamOptions
- type Writer
Constants ¶
const ( ScriptTop = "#!/usr/bin/env bash\nset -euo pipefail\necho \"Running init script\"\n" ScriptBottom = "\necho \"Init Script complete, executing arguments provided\"\nexec $@" )
ScriptTop and ScriptBottom sandwich the user's script when creating a config map to boot from
const DefaultScriptName = "wr-boot"
DefaultScriptName is the name to use as the default script in the create configmap functions.
const MinimalImage = "ubuntu:17.10"
MinimalImage is the image to use when deploying wr manager and for init containers. It does not run user jobs. It needs tar, cat, bash, ca-certificates, fuse and other basic things.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthConfig ¶
type AuthConfig struct {
KubeConfigPath string
}
AuthConfig holds configuration information necessary for using the client library.
func (AuthConfig) ConfigPath ¶
func (ac AuthConfig) ConfigPath() string
ConfigPath returns the set KubeConfigPath, or a default otherwise.
type CmdOptions ¶
type CmdOptions struct { StreamOptions Command []string }
CmdOptions contains StreamOptions for use in AttachCmd() or ExecCmd(). The first item in the command slice must be the command to execute only, any following will be arguments.
type ConfigMapOpts ¶
type ConfigMapOpts struct { // BinaryData for potential later use BinaryData []byte Data map[string]string Name string }
ConfigMapOpts defines the name and Data (Binary, or strings) to store in a ConfigMap.
type FilePair ¶
type FilePair struct {
Src, Dest string
}
FilePair is a source, destination pair of file paths.
type Kubernetesp ¶
type Kubernetesp struct { RESTClient rest.Interface StopChannel chan struct{} ReadyChannel chan struct{} NewNamespaceName string // contains filtered or unexported fields }
Kubernetesp is the implementation for the kubernetes client library. It provides access to all methods defined in this package
func (*Kubernetesp) AttachCmd ¶
func (p *Kubernetesp) AttachCmd(ctx context.Context, opts *CmdOptions) error
AttachCmd attaches to a running container and pipes StdIn to the command running on that container if StdIn is supplied. Should work only after calling Authenticate().
func (*Kubernetesp) Authenticate ¶
func (p *Kubernetesp) Authenticate(ctx context.Context, config AuthConfig) (kubernetes.Interface, *rest.Config, error)
Authenticate with cluster, return clientset and RESTConfig. Can be called from within or outside of a cluster, should still work. Optionally supply a logger.
func (*Kubernetesp) CheckWRDeploymentExists ¶
func (p *Kubernetesp) CheckWRDeploymentExists(namespace string) (bool, error)
CheckWRDeploymentExists checks if a wr deployment exists in a given namespace. If the deployment exists, it returns true. If no deployment is found it returns false and silences the not found error. If the deployment exists but an error is returned it returns true with the error.
func (*Kubernetesp) CheckWRDeploymentHealthy ¶
func (p *Kubernetesp) CheckWRDeploymentHealthy(namespace string) (bool, error)
CheckWRDeploymentHealthy checks if the wr deployment in a given namespace is healthy. It does this by getting the deployment object for 'wr-manager' and checking the DeploymentAvailable condition is true.
func (*Kubernetesp) CopyTar ¶
CopyTar copies the files defined in each filePair in files to the pod provided. Called by controller when initContainer status is running.
func (*Kubernetesp) CreateInitScriptConfigMap ¶
func (p *Kubernetesp) CreateInitScriptConfigMap(script string) (*apiv1.ConfigMap, error)
CreateInitScriptConfigMap performs very basic string fudging. This allows a wr pod to execute some arbitrary script before starting the runner / manager. So far it appears to work.
func (*Kubernetesp) CreateInitScriptConfigMapFromFile ¶
func (p *Kubernetesp) CreateInitScriptConfigMapFromFile(scriptPath string) (*apiv1.ConfigMap, error)
CreateInitScriptConfigMapFromFile is the same as CreateInitScriptConfigMap but takes a path to a file as input.
func (*Kubernetesp) CreateNewNamespace ¶
func (p *Kubernetesp) CreateNewNamespace(name string) error
CreateNewNamespace Creates a new namespace with the provided name.
func (*Kubernetesp) CreateService ¶
func (p *Kubernetesp) CreateService(opts *ServiceOpts) error
CreateService Creates a service with the defined options from ServiceOpts.
func (*Kubernetesp) Deploy ¶
func (p *Kubernetesp) Deploy(ctx context.Context, tempMountPath string, command string, cmdArgs []string, configMapName string, configMountPath string, requiredPorts []int) error
Deploy creates the wr-manager deployment and service. It creates a ClusterRoleBinding to allow the default service account in the namespace rights to manage the cluster. (ToDo: Write own ClusterRole / Role) This allows copying of wr to initcontainer, done by controller when ready (assumes tar is available). Portforwarding done by controller when ready. TempMountPath is the path at which the 'wr-tmp' directory is set to. It is also set to $HOME. Command is the command to be executed in the container. CmdArgs are the arguments to pass to the supplied command. ConfigMapName is the name of the configmap to mount at the configMountPath provided.
func (*Kubernetesp) DestroyPod ¶
func (p *Kubernetesp) DestroyPod(ctx context.Context, podName string) error
DestroyPod deletes the given pod, doesn't check it exists first.
func (*Kubernetesp) ExecCmd ¶
func (p *Kubernetesp) ExecCmd(opts *CmdOptions, namespace string) error
ExecCmd executes the provided command inside a running container, if StdIn is supplied pipes StdIn to the command. Should work after only calling Authenticate().
func (*Kubernetesp) ExecInPod ¶
func (p *Kubernetesp) ExecInPod(podName string, containerName, namespace string, command []string) (string, string, error)
ExecInPod is a convenience function to call ExecCmd without needing to set up writers for stdOut/Err. Accepts a pod name, container name, namespace and command. If you want to pass StdIn or have a need for a reader / writer then you'll need to use ExecCmd. If the command executes in the container and stdErr is not nil, the command will return an error containing the contents of stdErr.
func (*Kubernetesp) GetLog ¶
GetLog Gets the logs from a container with the name 'wr-runner' Returns the last n lines.
func (*Kubernetesp) Initialize ¶
func (p *Kubernetesp) Initialize(ctx context.Context, clientset kubernetes.Interface, namespace ...string) error
Initialize uses the passed clientset to create some authenticated clients used in other methods. Creates a new namespace for wr to work in. Optionally pass a namespace as a string.
func (*Kubernetesp) NewConfigMap ¶
func (p *Kubernetesp) NewConfigMap(opts *ConfigMapOpts) (*apiv1.ConfigMap, error)
NewConfigMap creates a new configMap. It checks the contents are not identical to a previously created config map by comparing hashes of the data. Kubernetes 1.10 (Released Late March 2018) provides a BinaryData field that could be used to replace the initContainer method for copying the executable. At the moment is not appropriate as it's not likely most users are running 1.10. It's a good idea once enough users are using 1.10+ as it simplifies the copy step considerably, and removes much complexity.
func (*Kubernetesp) PortForward ¶
PortForward sets up port forwarding to the manager that is running inside the cluster.
func (*Kubernetesp) Spawn ¶
func (p *Kubernetesp) Spawn(ctx context.Context, baseContainerImage string, tempMountPath string, binaryPath string, binaryArgs []string, configMapName string, configMountPath string, resources apiv1.ResourceRequirements) (*apiv1.Pod, error)
Spawn a new pod that expects an 'attach' command to tar some files across (Init container). It also names the pod 'wr-runner-xxxx' and mounts the provided config map at the path provided. The directory named 'wr-tmp' persists between the two containers, so any files that you want to survive the tar step should untar to this path only. This path is also set as $HOME. This path is set with the tempMountPath variable.
type ResourceRequest ¶
type ResourceRequest struct { Cores *resource.Quantity Disk *resource.Quantity RAM *resource.Quantity }
ResourceRequest specifies a request for resources. Used in Spawn().
type ServiceOpts ¶
type ServiceOpts struct { Name string Labels map[string]string Selector map[string]string ClusterIP string Ports []apiv1.ServicePort }
ServiceOpts defines basic options for a kubernetes service.