client

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Overview

Package client provides an implementation of a restricted subset of kubernetes API client

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrReadNamespace is returned when the names could not be read from service account
	ErrReadNamespace = errors.New("Could not read namespace from service account secret")
	// DefaultImage is default micro image
	DefaultImage = "micro/go-micro"
	// DefaultNamespace is the default k8s namespace
	DefaultNamespace = "default"
)

Functions

func CertPoolFromFile

func CertPoolFromFile(filename string) (*x509.CertPool, error)

CertPoolFromFile returns an x509.CertPool containing the certificates in the given PEM-encoded file. Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates

func CertsFromPEM

func CertsFromPEM(pemCerts []byte) ([]*x509.Certificate, error)

CertsFromPEM returns the x509.Certificates contained in the given PEM-encoded byte array Returns an error if a certificate could not be parsed, or if the data does not contain any certificates

func Format

func Format(v string) string

Format is used to format a string value into a k8s valid name

func NewClusterClient

func NewClusterClient() *client

NewClusterClient creates a Kubernetes client for use from within a k8s pod.

func NewLocalClient

func NewLocalClient(hosts ...string) *client

NewLocalClient returns a client that can be used with `kubectl proxy`

func SerializeResourceName added in v2.6.0

func SerializeResourceName(ns string) string

SerializeResourceName removes all spacial chars from a string so it can be used as a k8s resource name

Types

type Client

type Client interface {
	// Create creates new API resource
	Create(*Resource, ...CreateOption) error
	// Get queries API resrouces
	Get(*Resource, ...GetOption) error
	// Update patches existing API object
	Update(*Resource, ...UpdateOption) error
	// Delete deletes API resource
	Delete(*Resource, ...DeleteOption) error
	// List lists API resources
	List(*Resource, ...ListOption) error
	// Log gets log for a pod
	Log(*Resource, ...LogOption) (io.ReadCloser, error)
	// Watch for events
	Watch(*Resource, ...WatchOption) (Watcher, error)
}

Kubernetes client

type Condition added in v2.4.0

type Condition struct {
	Started string `json:"startedAt,omitempty"`
	Reason  string `json:"reason,omitempty"`
	Message string `json:"message,omitempty"`
}

type Container

type Container struct {
	Name    string          `json:"name"`
	Image   string          `json:"image"`
	Env     []EnvVar        `json:"env,omitempty"`
	Command []string        `json:"command,omitempty"`
	Args    []string        `json:"args,omitempty"`
	Ports   []ContainerPort `json:"ports,omitempty"`
}

Container defined container runtime values

type ContainerPort

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

ContainerPort

type ContainerState added in v2.4.0

type ContainerState struct {
	Running    *Condition `json:"running"`
	Terminated *Condition `json:"terminated"`
	Waiting    *Condition `json:"waiting"`
}

type ContainerStatus added in v2.4.0

type ContainerStatus struct {
	State ContainerState `json:"state"`
}

type CreateOption added in v2.6.0

type CreateOption func(*CreateOptions)

func CreateNamespace added in v2.6.0

func CreateNamespace(ns string) CreateOption

CreateNamespace sets the namespace for creating a resource

type CreateOptions added in v2.6.0

type CreateOptions struct {
	Namespace string
}

type DeleteOption added in v2.6.0

type DeleteOption func(*DeleteOptions)

func DeleteNamespace added in v2.6.0

func DeleteNamespace(ns string) DeleteOption

DeleteNamespace sets the namespace for deleting a resource

type DeleteOptions added in v2.6.0

type DeleteOptions struct {
	Namespace string
}

type Deployment

type Deployment struct {
	Metadata *Metadata         `json:"metadata"`
	Spec     *DeploymentSpec   `json:"spec,omitempty"`
	Status   *DeploymentStatus `json:"status,omitempty"`
}

Deployment is Kubernetes deployment

func NewDeployment

func NewDeployment(name, version, typ, namespace string) *Deployment

NewService returns default micro kubernetes deployment definition

type DeploymentCondition

type DeploymentCondition struct {
	LastUpdateTime string `json:"lastUpdateTime"`
	Type           string `json:"type"`
	Reason         string `json:"reason,omitempty"`
	Message        string `json:"message,omitempty"`
}

DeploymentCondition describes the state of deployment

type DeploymentList

type DeploymentList struct {
	Items []Deployment `json:"items"`
}

DeploymentList

type DeploymentSpec

type DeploymentSpec struct {
	Replicas int            `json:"replicas,omitempty"`
	Selector *LabelSelector `json:"selector"`
	Template *Template      `json:"template,omitempty"`
}

DeploymentSpec defines micro deployment spec

type DeploymentStatus

type DeploymentStatus struct {
	Replicas            int                   `json:"replicas,omitempty"`
	UpdatedReplicas     int                   `json:"updatedReplicas,omitempty"`
	ReadyReplicas       int                   `json:"readyReplicas,omitempty"`
	AvailableReplicas   int                   `json:"availableReplicas,omitempty"`
	UnavailableReplicas int                   `json:"unavailableReplicas,omitempty"`
	Conditions          []DeploymentCondition `json:"conditions,omitempty"`
}

DeploymentStatus is returned when querying deployment

type EnvVar

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

EnvVar is environment variable

type Event

type Event struct {
	Type   EventType       `json:"type"`
	Object json.RawMessage `json:"object"`
}

Event represents a single event to a watched resource.

type EventType

type EventType string

EventType defines the possible types of events.

const (
	// EventTypes used
	Added    EventType = "ADDED"
	Modified EventType = "MODIFIED"
	Deleted  EventType = "DELETED"
	Error    EventType = "ERROR"
)

type GetOption added in v2.6.0

type GetOption func(*GetOptions)

func GetLabels added in v2.6.0

func GetLabels(ls map[string]string) GetOption

GetLabels sets the labels for when getting a resource

func GetNamespace added in v2.6.0

func GetNamespace(ns string) GetOption

GetNamespace sets the namespace for getting a resource

type GetOptions added in v2.6.0

type GetOptions struct {
	Namespace string
	Labels    map[string]string
}

type ImagePullSecret added in v2.6.0

type ImagePullSecret struct {
	Name string `json:"name"`
}

ImagePullSecret

type LabelSelector

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

LabelSelector is a label query over a set of resources NOTE: we do not support MatchExpressions at the moment

type ListOption added in v2.6.0

type ListOption func(*ListOptions)

func ListNamespace added in v2.6.0

func ListNamespace(ns string) ListOption

ListNamespace sets the namespace for listing resources

type ListOptions added in v2.6.0

type ListOptions struct {
	Namespace string
}

type LoadBalancerIngress

type LoadBalancerIngress struct {
	IP       string `json:"ip,omitempty"`
	Hostname string `json:"hostname,omitempty"`
}

type LoadBalancerStatus

type LoadBalancerStatus struct {
	Ingress []LoadBalancerIngress `json:"ingress,omitempty"`
}

type LogOption

type LogOption func(*LogOptions)

func LogNamespace added in v2.6.0

func LogNamespace(ns string) LogOption

LogNamespace sets the namespace for logging a resource

func LogParams

func LogParams(p map[string]string) LogOption

LogParams provides additional params for logs

type LogOptions

type LogOptions struct {
	Namespace string
	Params    map[string]string
}

type Metadata

type Metadata struct {
	Name        string            `json:"name,omitempty"`
	Namespace   string            `json:"namespace,omitempty"`
	Version     string            `json:"version,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

Metadata defines api object metadata

type Namespace added in v2.5.0

type Namespace struct {
	Metadata *Metadata `json:"metadata,omitempty"`
}

Namespace is a Kubernetes Namespace

type NamespaceList added in v2.6.0

type NamespaceList struct {
	Items []Namespace `json:"items"`
}

NamespaceList

type Pod

type Pod struct {
	Metadata *Metadata  `json:"metadata"`
	Spec     *PodSpec   `json:"spec,omitempty"`
	Status   *PodStatus `json:"status"`
}

Pod is the top level item for a pod

type PodCondition added in v2.3.0

type PodCondition struct {
	Type    string `json:"type"`
	Reason  string `json:"reason,omitempty"`
	Message string `json:"message,omitempty"`
}

PodCondition describes the state of pod

type PodList

type PodList struct {
	Items []Pod `json:"items"`
}

PodList

type PodSpec

type PodSpec struct {
	Containers         []Container `json:"containers"`
	ServiceAccountName string      `json:"serviceAccountName"`
}

PodSpec is a pod

type PodStatus

type PodStatus struct {
	Conditions []PodCondition    `json:"conditions,omitempty"`
	Containers []ContainerStatus `json:"containerStatuses"`
	PodIP      string            `json:"podIP"`
	Phase      string            `json:"phase"`
	Reason     string            `json:"reason"`
}

PodStatus

type Resource

type Resource struct {
	Name  string
	Kind  string
	Value interface{}
}

Resource is API resource

type Secret added in v2.6.0

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

Secret

type Service

type Service struct {
	Metadata *Metadata      `json:"metadata"`
	Spec     *ServiceSpec   `json:"spec,omitempty"`
	Status   *ServiceStatus `json:"status,omitempty"`
}

Service is kubernetes service

func NewService

func NewService(name, version, typ, namespace string) *Service

NewService returns default micro kubernetes service definition

type ServiceAccount added in v2.6.0

type ServiceAccount struct {
	Metadata         *Metadata         `json:"metadata,omitempty"`
	ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets,omitempty"`
}

ServiceAccount

type ServiceList

type ServiceList struct {
	Items []Service `json:"items"`
}

ServiceList

type ServicePort

type ServicePort struct {
	Name     string `json:"name,omitempty"`
	Port     int    `json:"port"`
	Protocol string `json:"protocol,omitempty"`
}

ServicePort configures service ports

type ServiceSpec

type ServiceSpec struct {
	ClusterIP string            `json:"clusterIP"`
	Type      string            `json:"type,omitempty"`
	Selector  map[string]string `json:"selector,omitempty"`
	Ports     []ServicePort     `json:"ports,omitempty"`
}

ServiceSpec provides service configuration

type ServiceStatus

type ServiceStatus struct {
	LoadBalancer LoadBalancerStatus `json:"loadBalancer,omitempty"`
}

ServiceStatus

type Template

type Template struct {
	Metadata *Metadata `json:"metadata,omitempty"`
	PodSpec  *PodSpec  `json:"spec,omitempty"`
}

Template is micro deployment template

type UpdateOption added in v2.6.0

type UpdateOption func(*UpdateOptions)

func UpdateNamespace added in v2.6.0

func UpdateNamespace(ns string) UpdateOption

UpdateNamespace sets the namespace for updating a resource

type UpdateOptions added in v2.6.0

type UpdateOptions struct {
	Namespace string
}

type WatchOption

type WatchOption func(*WatchOptions)

func WatchNamespace added in v2.6.0

func WatchNamespace(ns string) WatchOption

WatchNamespace sets the namespace for watching a resource

func WatchParams

func WatchParams(p map[string]string) WatchOption

WatchParams used for watch params

type WatchOptions

type WatchOptions struct {
	Namespace string
	Params    map[string]string
}

type Watcher

type Watcher interface {
	// A channel of events
	Chan() <-chan Event
	// Stop the watcher
	Stop()
}

Watcher is used to watch for events

Jump to

Keyboard shortcuts

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