comms

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2017 License: MIT Imports: 24 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ImageBucket = "images"
)

Variables

View Source
var (
	ErrContainerNotFound        = e.New("Requested container couldn't be found")
	ErrDeploymentNotFound       = e.New("Requested deployment couldn't be found")
	ErrNoDeploymentsInNamespace = e.New("No deployments found in specified namespace")
)

Functions

func GetDockerTag

func GetDockerTag() (string, error)

GetDockerTag combines a configured Docker repository name, the current working directory, the current time, and a git hash to create a Docker tag appropriate to gzr Output format: `repository/$CWD:YYYYMMDD.SHORT_HASH`

Types

type BoltStorage

type BoltStorage struct {
	// contains filtered or unexported fields
}

BoltStorage implements GzrMetadataStore and has an un-exported bolt.db pointer

func (*BoltStorage) Cleanup

func (store *BoltStorage) Cleanup()

Cleanup closes the Bolt connection

func (*BoltStorage) CommitTransaction

func (store *BoltStorage) CommitTransaction() error

CommitTransaction commits the active transaction

func (*BoltStorage) Delete

func (store *BoltStorage) Delete(imageName string) (int, error)

Delete deletes all information related to IMAGE_NAME:VERSION

func (*BoltStorage) Get

func (store *BoltStorage) Get(imageName string) (*Image, error)

Get returns a single image based on a name

func (*BoltStorage) GetLatest

func (store *BoltStorage) GetLatest(imageName string) (*Image, error)

GetLatest returns the latest image from a name

func (*BoltStorage) List

func (store *BoltStorage) List(imageName string) (*ImageList, error)

List queries the Bolt store for all images stored under a particular name

func (*BoltStorage) StartTransaction

func (store *BoltStorage) StartTransaction() error

StartTransaction starts a new Bolt transaction and adds it to the Storage

func (*BoltStorage) Store

func (store *BoltStorage) Store(imageName string, meta ImageMetadata) error

Store stores the metadata about an image associated with its name

type DeploymentContainerInfo

type DeploymentContainerInfo struct {
	// Namespace is the Deployment's k8s namespace
	Namespace string
	// DeploymentName is the name of the Deployment
	DeploymentName string
	// ContainerName is the name of a Pod's container in the Deployment spec
	ContainerName string
	// Image is the name of the image (current or intended) for the container identified by ContainerName
	Image string
}

DeploymentContainerInfo holds information about a Deployment sufficient for updating a Pod's container by name

type DockerManager

type DockerManager struct{}

DockerManager implements ImageManager in order to manage images for Docker

func NewDockerManager

func NewDockerManager() *DockerManager

NewDockerManager returns a pointer to an initialized DockerManager

func (*DockerManager) Build

func (docker *DockerManager) Build(args ...string) error

Build takes a series of arguments to be sent to Docker and builds an image

func (*DockerManager) Push

func (docker *DockerManager) Push(name string) error

Push takes a name and pushes this to Docker

type EtcdStorage

type EtcdStorage struct {
	Client *clientv3.Client
	KV     clientv3.KV
	// contains filtered or unexported fields
}

EtcdStorage implements GzrMetadataStore and has exported Etcd clients and KV accessors

func (*EtcdStorage) Cleanup

func (store *EtcdStorage) Cleanup()

Cleanup closes the etcd client connection

func (*EtcdStorage) CommitTransaction

func (store *EtcdStorage) CommitTransaction() error

CommitTransaction commits the active transaction

func (*EtcdStorage) Delete

func (store *EtcdStorage) Delete(imageName string) (int, error)

Delete deletes all information related to IMAGE_NAME:VERSION

func (*EtcdStorage) Get

func (store *EtcdStorage) Get(imageName string) (*Image, error)

Get returns a single image based on a name

func (*EtcdStorage) GetLatest

func (store *EtcdStorage) GetLatest(imageName string) (*Image, error)

GetLatest returns the latest image from a name

func (*EtcdStorage) List

func (store *EtcdStorage) List(imageName string) (*ImageList, error)

List queries the etcd store for all images stored under a particular name

func (*EtcdStorage) StartTransaction

func (store *EtcdStorage) StartTransaction() error

StartTransaction sets a new transaction on the EtcdStorage

func (*EtcdStorage) Store

func (store *EtcdStorage) Store(imageName string, meta ImageMetadata) error

Store stores the metadata about an image associated with its name in etcd

type GitManager

type GitManager interface {
	CommitHash() (string, error)
	Remote() (string, error)
	Tags() ([]string, []string, error)
	SetPath(string)
	GetPath() string
}

GitManager is an interface to retrieve data from a git repo

type GzrDeployment

type GzrDeployment v1beta1.Deployment

GzrDeployment is just here to let us declare methods on k8s Deployments

func (GzrDeployment) SerializeForCLI

func (d GzrDeployment) SerializeForCLI(wr io.Writer) error

SerializeForCLI takes an io.Writer and writes templatized data to it representing a Deployment

func (GzrDeployment) SerializeForWire

func (d GzrDeployment) SerializeForWire() ([]byte, error)

SerializeForWire returns a JSON representation of the Deployment

type GzrDeploymentList

type GzrDeploymentList struct {
	Deployments []GzrDeployment `json:"deployments"`
}

GzrDeploymentList is a collection of GzrDeployments

func (*GzrDeploymentList) SerializeForWire

func (dl *GzrDeploymentList) SerializeForWire() ([]byte, error)

SerializeForWire returns a JSON representation of the DeploymentList

type GzrMetadataStore

type GzrMetadataStore interface {
	// Store stores image metadata with a name
	Store(string, ImageMetadata) error
	// List lists all of the images under a name
	List(string) (*ImageList, error)
	// Cleanup allows the storage backend to clean up any connections, etc
	Cleanup()
	// Delete deletes all images under a nmae, returns number of deleted entries
	Delete(string) (int, error)
	// Get gets a single image with a version
	Get(string) (*Image, error)
	// GetLatest gets the most recent image from a name
	GetLatest(string) (*Image, error)
	// StartTransaction starts a new transaction within the GzrMetadataStore
	StartTransaction() error
	// CommitTransaction commits the active transaction
	CommitTransaction() error
}

GzrMetadataStore is the interface that should be implemented for any backend that needs to handle image data storage

func NewBoltStorage

func NewBoltStorage() (GzrMetadataStore, error)

NewBoltStorage initializes a BoltDB connection, makes sure the correct buckets exist, and returns a BoltStorage pointer with the established connection

func NewEtcdStorage

func NewEtcdStorage() (GzrMetadataStore, error)

NewEtcdStorage initializes and returns a pointer to an EtcdStorage with a connected Client and KV

type Image

type Image struct {
	// Name is the image's full name
	Name string `json:"name"`
	// Meta is the metadata related to the image
	Meta ImageMetadata `json:"metadata"`
}

Image is a struct unifying an image name with its metadata

func (*Image) SerializeForCLI

func (l *Image) SerializeForCLI(wr io.Writer) error

SerializeForCLI takes an io.Writer and writes templated data to it representing an Image

func (*Image) SerializeForWire

func (image *Image) SerializeForWire() ([]byte, error)

SerializeForWire returns a JSON representation of the Image

type ImageList

type ImageList struct {
	Images []*Image `json:"images"`
}

ImageList is a collection of Images

func (*ImageList) SerializeForCLI

func (l *ImageList) SerializeForCLI(wr io.Writer) error

SerializeForCLI takes an io.Writer and writes templatized data to it representing an ImageList

func (*ImageList) SerializeForWire

func (imageList *ImageList) SerializeForWire() ([]byte, error)

SerializeForWire returns a JSON representation of the ImageList

type ImageManager

type ImageManager interface {
	Build(...string) error
	Push(string) error
}

ImageManager is an interface for building an application's image

func NewDefaultMockManager

func NewDefaultMockManager() ImageManager

NewDefaultMockManager returns an initialized MockManager with no-ops for all methods

type ImageMetadata

type ImageMetadata struct {
	// GitCommit is the commit related to the built image
	GitCommit string `json:"git-commit"`
	// GitTag is the tag related to the built image if it exists
	GitTag []string `json:"git-tag"`
	// GitAnnotation is the annotation related to the built image if it exists
	GitAnnotation []string `json:"git-annotation"`
	// GitOrigin is the remote origin for the git repo associated with the image
	GitOrigin string `json:"git-origin"`
	// CreatedAt is the time the metadata was stored, with day granularity
	CreatedAt string `json:"created-at"`
}

ImageMetadata is a struct containing necessary metadata about a particular image

func CreateMeta

func CreateMeta(reader io.ReadWriter) (ImageMetadata, error)

CreateMeta takes a ReadWriter and returns an instance of ImageMetadata after parsing

func NewImageMetadata

func NewImageMetadata() (ImageMetadata, error)

NewImageMetadata returns a populated ImageMetadata based on a LocalGitManager

type K8sCommunicator

type K8sCommunicator interface {
	// ListDeployments returns the list of Deployments in the cluster
	ListDeployments() (*GzrDeploymentList, error)
	// GetDeployment returns the Deployment matching the given name
	GetDeployment(string) (*GzrDeployment, error)
	// UpdateDeployment updates the Deployment's container in the manner specified by the argument
	UpdateDeployment(*DeploymentContainerInfo) (*GzrDeployment, error)
	// GetNamespace returns the namespace
	GetNamespace() string
}

K8sCommunicator defines an interface for retrieving data from a k8s cluster

type K8sConnection

type K8sConnection struct {
	// contains filtered or unexported fields
}

K8sConnection implements the K8sCommunicator interface and holds a live connection to a k8s cluster

func NewK8sConnection

func NewK8sConnection() (*K8sConnection, error)

NewK8sConnection returns a K8sConnection with an active v1.Clientset.

  • assumes gzr is running in a Kubernetes cluster
  • looks at $HOME/.kube/config for kubeconfig, falls back to inclusterconfig if file missing
  • panics if neither configuration can be used to connect to a k8s cluster.

func (*K8sConnection) GetDeployment

func (k *K8sConnection) GetDeployment(deploymentName string) (*GzrDeployment, error)

GetDeployment returns a GzrDeployment matching the deploymentName in the given namespace

func (*K8sConnection) GetNamespace

func (k *K8sConnection) GetNamespace() string

GetNamespace returns the namespace for the connection

func (*K8sConnection) ListDeployments

func (k *K8sConnection) ListDeployments() (*GzrDeploymentList, error)

ListDeployments returns the active k8s Deployments for the given namespace

func (*K8sConnection) UpdateDeployment

func (k *K8sConnection) UpdateDeployment(dci *DeploymentContainerInfo) (*GzrDeployment, error)

UpdateDeployment updates a Deployment on the server to the structure represented by the argument TODO: verify that requested image exists in the store TODO: verify that requested image exists in the registry

type LocalGitManager

type LocalGitManager struct {
	// contains filtered or unexported fields
}

LocalGitManager implements GitManager

func NewLocalGitManager

func NewLocalGitManager(path ...string) *LocalGitManager

NewLocalGitManager returns a pointer to an initialized LocalGitManager and takes a `path`

func (*LocalGitManager) CommitHash

func (gm *LocalGitManager) CommitHash() (string, error)

CommitHash returns the commit hash of a git repo at either the set path or current working directory

func (*LocalGitManager) Remote

func (gm *LocalGitManager) Remote() (string, error)

Remote returns the remote of a git repo at either the set path or current working directory

func (*LocalGitManager) RepoName

func (gm *LocalGitManager) RepoName() (string, error)

RepoName returns the name of the repository extracted from the remote TODO: support multiple remotes (by ignoring all but origin) TODO: treat "origin" as a standard special case of remote that we will treat as the canonical name

func (*LocalGitManager) Tags

func (gm *LocalGitManager) Tags() ([]string, []string, error)

Tags returns the tags and accompanying annotations of a git repo at either the set path or current working directory

type MockK8sCommunicator

type MockK8sCommunicator struct {
	OnGetDeployment    func(string) (*GzrDeployment, error)
	OnListDeployments  func() (*GzrDeploymentList, error)
	OnUpdateDeployment func(*DeploymentContainerInfo) (*GzrDeployment, error)
	// contains filtered or unexported fields
}

func (*MockK8sCommunicator) GetDeployment

func (mock *MockK8sCommunicator) GetDeployment(deploymentName string) (*GzrDeployment, error)

func (*MockK8sCommunicator) GetNamespace

func (mock *MockK8sCommunicator) GetNamespace() string

func (*MockK8sCommunicator) ListDeployments

func (mock *MockK8sCommunicator) ListDeployments() (*GzrDeploymentList, error)

func (*MockK8sCommunicator) UpdateDeployment

func (mock *MockK8sCommunicator) UpdateDeployment(dci *DeploymentContainerInfo) (*GzrDeployment, error)

type MockManager

type MockManager struct {
	OnBuild func(...string) error
	OnPush  func(string) error
}

func (*MockManager) Build

func (mock *MockManager) Build(args ...string) error

func (*MockManager) Push

func (mock *MockManager) Push(name string) error

type MockStore

type MockStore struct {
	OnStore             func(string, ImageMetadata) error
	OnList              func(string) (*ImageList, error)
	OnCleanup           func()
	OnDelete            func(string) (int, error)
	OnGet               func(string) (*Image, error)
	OnGetLatest         func(string) (*Image, error)
	OnStartTransaction  func() error
	OnCommitTransaction func() error
}

func (*MockStore) Cleanup

func (mock *MockStore) Cleanup()

func (*MockStore) CommitTransaction

func (mock *MockStore) CommitTransaction() error

func (*MockStore) Delete

func (mock *MockStore) Delete(imageName string) (int, error)

func (*MockStore) Get

func (mock *MockStore) Get(imageName string) (*Image, error)

func (*MockStore) GetLatest

func (mock *MockStore) GetLatest(imageName string) (*Image, error)

func (*MockStore) List

func (mock *MockStore) List(imageName string) (*ImageList, error)

func (*MockStore) StartTransaction

func (mock *MockStore) StartTransaction() error

func (*MockStore) Store

func (mock *MockStore) Store(imageName string, meta ImageMetadata) error

type Serializer

type Serializer interface {
	// SerializeForCLI writes templatized information to the provided io.Writer
	SerializeForCLI(io.Writer) error
	// SerializeForWire kicks out JSON as a byte slice
	SerializeForWire() ([]byte, error)
}

Serializer knows how to serialize for web (JSON) and CLI (templatized strings)

type StorageTransaction

type StorageTransaction interface {
	// Commit persists the operations from the transaction
	Commit() error
}

StorageTransaction is an interface to manage transactions around storage concerns

Jump to

Keyboard shortcuts

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