kube

package
v0.0.0-...-0b82c43 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RestartOnFailure is a Job Restart Policy that restarts the pods on failure
	RestartOnFailure RestartPolicyType = "OnFailure"

	// NeverRestart is a Job Restart Policy that will never restart a failed job
	NeverRestart RestartPolicyType = "Never"

	// UDP is a ProtocolType that defines a "udp" protocol
	UDP ProtocolType = "UDP"

	// TCP is a ProtocolType that defines a "tcp" protocol
	TCP ProtocolType = "TCP"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	Name            string           `json:"name,omitempty"`
	Image           string           `json:"image,omitempty"`
	ImagePullPolicy string           `json:"imagePullPolicy,omitempty"`
	WorkingDir      string           `json:"workingDir,omitempty"`
	Command         []string         `json:"command,omitempty"`
	Args            []string         `json:"args,omitempty"`
	Ports           []*ContainerPort `json:"ports,omitempty"`
	Env             []*EnvVar        `json:"env,omitempty"`
	VolumeMounts    []*VolumeMount   `json:"volumeMounts,omitempty"`
}

Container defines a container in a kubernetes pod

func (*Container) AddEnv

func (c *Container) AddEnv(name, value string)

AddEnv adds a new environment variable to the container

func (*Container) AddPort

func (c *Container) AddPort(name string, port int, protocol ProtocolType)

AddPort adds a new port to the container

func (*Container) AddVolumeMountPoint

func (c *Container) AddVolumeMountPoint(volume *Volume, mountPath string, readOnly bool)

AddVolumeMountPoint adds a mount point to the container for the given volume

func (*Container) SetArgs

func (c *Container) SetArgs(args ...string)

SetArgs sets the arguments for the container

func (*Container) SetCommand

func (c *Container) SetCommand(command ...string)

SetCommand sets the command for the container

type ContainerPort

type ContainerPort struct {
	Name          string       `json:"name,omitempty"`
	ContainerPort int          `json:"containerPort,omitempty"`
	Protocol      ProtocolType `json:"protocol,omitempty"`
}

ContainerPort defines a port exposed by a container

type EmptyDirVolume

type EmptyDirVolume struct {
	Medium string `json:"medium,omitempty"`
}

EmptyDirVolume is a empty directory used as a volume

type EnvVar

type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

EnvVar defines an environment variable for the container

type HostPathVolume

type HostPathVolume struct {
	Path string `json:"path,omitempty"`
}

HostPathVolume is a volume that is located on the host path

type Job

type Job struct {
	APIVersion string                 `json:"apiVersion,omitempty"`
	Kind       string                 `json:"kind,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
	Spec       *JobSpec               `json:"spec,omitempty"`
	Status     *struct {
		Active     int `json:"active,omitempty"`
		Succeeded  int `json:"succeeded,omitempty"`
		Failed     int `json:"failed,omitempty"`
		Conditions []struct {
			Status string `json:"status,omitempty"`
			Type   string `json:"type,omitempty"`
		} `json:"conditions,omitempty"`
	} `json:"status,omitempty"`
}

Job respresents a kubenertes Job

func NewJob

func NewJob(name, namespace string) *Job

NewJob creates a new Job with default values

func (*Job) AddAnnotations

func (j *Job) AddAnnotations(name, value string)

AddAnnotations adds annotations to the job

func (*Job) AddLabels

func (j *Job) AddLabels(name, value string)

AddLabels add labels to the job

func (*Job) AddMetadata

func (j *Job) AddMetadata(name string, value interface{})

AddMetadata adds a metadata to the job

func (*Job) AddPodContainer

func (j *Job) AddPodContainer(name, image string) *Container

AddPodContainer adds a new container to the pod. Reference to the created pod is returned

func (*Job) AddPodVolume

func (j *Job) AddPodVolume(name, path string) *Volume

AddPodVolume adds a new volume to the pod. Reference to the created volume is returned

func (*Job) AddSelectorMatchLabel

func (j *Job) AddSelectorMatchLabel(name, value string)

AddSelectorMatchLabel adds key=value labels to the selector and the job metadata

type JobSelector

type JobSelector struct {
	MatchLabels map[string]string `json:"matchLabels,omitempty"`
}

JobSelector defines a map of labels to select the pods for the job

type JobSpec

type JobSpec struct {
	Selector *JobSelector     `json:"selector,omitempty"`
	Template *JobSpecTemplate `json:"template,omitempty"`
}

JobSpec defines the job selector and template

type JobSpecTemplate

type JobSpecTemplate struct {
	Metadata map[string]interface{} `json:"metadata,omitempty"`
	Spec     *PodSpec               `json:"spec,omitempty"`
}

JobSpecTemplate defines the metadata and pod template

type KubeClient

type KubeClient interface {
	CreateJob(job *Job) error
	GetSecret(namespace string, secretName string) (map[string]string, error)
	GetLog(namespace, pod, container string) (string, error)
	GetPodNameBySelector(namespace string, selector map[string]string) (string, error)
	GetPodContainers(namespace, podName string) ([]string, error)
}

KubeClient is the interface to access the kubernetes job API

func NewClient

func NewClient(address string) (KubeClient, error)

NewClient returns a new KubeClient connecting to the address. This uses the service account credentials

type PodSpec

type PodSpec struct {
	Volumes       []*Volume         `json:"volumes,omitempty"`
	Containers    []*Container      `json:"containers,omitempty"`
	RestartPolicy RestartPolicyType `json:"restartPolicy,omitempty"`
}

PodSpec defines the specs of the pod

type ProtocolType

type ProtocolType string

ProtocolType is a custom string type defining supported protocols for the pod's exposed ports. Currently supports "udp" and "tcp"

type RestartPolicyType

type RestartPolicyType string

RestartPolicyType is a cumstom string type that defines Restart Policy for the Kuberentes job. Currently supported for Jobs are "OnFailure" and "Never"

type Secret

type Secret struct {
	Kind       string                 `json:"apiVersion",omitempty"`
	ApiVersion string                 `json:"apiVersion,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
	Data       map[string]string      `json:"data,omitempty"`
	Type       string                 `json:"type, omitempty"`
}

type Volume

type Volume struct {
	Name     string          `json:"name,omitempty"`
	HostPath *HostPathVolume `json:"hostPath,omitempty"`
	EmptyDir *EmptyDirVolume `json:"emptyDir,omitempty"`
}

Volume defines a kubernetes volume for the pod

type VolumeMount

type VolumeMount struct {
	Name      string `json:"name,omitempty"`
	MountPath string `json:"mountPath,omitempty"`
	ReadOnly  bool   `json:"readOnly,omitempty"`
}

VolumeMount defines where a volume will be mounted in a container

Jump to

Keyboard shortcuts

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