Documentation ¶
Overview ¶
Package client provides an implementation of a restricted subset of kubernetes API client
Index ¶
- Variables
- func CertPoolFromFile(filename string) (*x509.CertPool, error)
- func CertsFromPEM(pemCerts []byte) ([]*x509.Certificate, error)
- func Format(v string) string
- func NewClusterClient() *client
- func NewLocalClient(hosts ...string) *client
- type Client
- type Condition
- type Container
- type ContainerPort
- type ContainerState
- type ContainerStatus
- type CreateOption
- type CreateOptions
- type DeleteOption
- type DeleteOptions
- type Deployment
- type DeploymentCondition
- type DeploymentList
- type DeploymentSpec
- type DeploymentStatus
- type EnvVar
- type EnvVarSource
- type Event
- type EventType
- type GetOption
- type GetOptions
- type ImagePullSecret
- type IngressRuleSelector
- type LabelSelector
- type ListOption
- type ListOptions
- type LoadBalancerIngress
- type LoadBalancerStatus
- type LogOption
- type LogOptions
- type Metadata
- type Namespace
- type NamespaceList
- type NetworkPolicy
- type NetworkPolicyRule
- type NetworkPolicySpec
- type PersistentVolumeClaimVolumeSource
- type Pod
- type PodCondition
- type PodList
- type PodSpec
- type PodStatus
- type Probe
- type Resource
- type ResourceLimits
- type ResourceQuota
- type ResourceQuotaSpec
- type ResourceQuotaSpecs
- type ResourceRequirements
- type Secret
- type SecretKeySelector
- type Selector
- type Service
- type ServiceAccount
- type ServiceList
- type ServicePort
- type ServiceSpec
- type ServiceStatus
- type TCPSocketAction
- type Template
- type UpdateOption
- type UpdateOptions
- type Volume
- type VolumeMount
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
This section is empty.
Variables ¶
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 = "ghcr.io/micro/cells:v3" // DefaultNamespace is the default k8s namespace DefaultNamespace = "default" // DefaultPort to expose on a service DefaultPort = 8080 )
Functions ¶
func CertPoolFromFile ¶
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 ¶
Format is used to format a string value into a k8s valid name https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
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`
Types ¶
type Client ¶
type Client interface { // Create creates new API resource Create(*Resource, ...CreateOption) error // Get queries API resources 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 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"` ReadinessProbe *Probe `json:"readinessProbe,omitempty"` Resources *ResourceRequirements `json:"resources,omitempty"` VolumeMounts []VolumeMount `json:"volumeMounts,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 ¶
type ContainerStatus ¶
type ContainerStatus struct {
State ContainerState `json:"state"`
}
type CreateOption ¶
type CreateOption func(*CreateOptions)
func CreateNamespace ¶
func CreateNamespace(ns string) CreateOption
CreateNamespace sets the namespace for creating a resource
type CreateOptions ¶
type CreateOptions struct {
Namespace string
}
type DeleteOption ¶
type DeleteOption func(*DeleteOptions)
func DeleteNamespace ¶
func DeleteNamespace(ns string) DeleteOption
DeleteNamespace sets the namespace for deleting a resource
type DeleteOptions ¶
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
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"` 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"` ValueFrom *EnvVarSource `json:"valueFrom,omitempty"` }
EnvVar is environment variable
type EnvVarSource ¶
type EnvVarSource struct {
SecretKeyRef *SecretKeySelector `json:"secretKeyRef,omitempty"`
}
EnvVarSource represents a source for the value of an EnvVar.
type Event ¶
type Event struct { Type EventType `json:"type"` Object json.RawMessage `json:"object"` }
Event represents a single event to a watched resource.
type GetOption ¶
type GetOption func(*GetOptions)
func GetNamespace ¶
GetNamespace sets the namespace for getting a resource
type GetOptions ¶
type IngressRuleSelector ¶
type IngressRuleSelector struct { NamespaceSelector *Selector `json:"namespaceSelector,omitempty"` PodSelector *Selector `json:"podSelector,omitempty"` }
IngressRuleSelector defines a namespace or pod selector for ingress
type LabelSelector ¶
LabelSelector is a label query over a set of resources NOTE: we do not support MatchExpressions at the moment
type ListOption ¶
type ListOption func(*ListOptions)
func ListNamespace ¶
func ListNamespace(ns string) ListOption
ListNamespace sets the namespace for listing resources
type ListOptions ¶
type ListOptions struct {
Namespace string
}
type LoadBalancerIngress ¶
type LoadBalancerStatus ¶
type LoadBalancerStatus struct {
Ingress []LoadBalancerIngress `json:"ingress,omitempty"`
}
type LogOption ¶
type LogOption func(*LogOptions)
func LogNamespace ¶
LogNamespace sets the namespace for logging a resource
type LogOptions ¶
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 ¶
type Namespace struct {
Metadata *Metadata `json:"metadata,omitempty"`
}
Namespace is a Kubernetes Namespace
type NetworkPolicy ¶
type NetworkPolicy struct { Metadata *Metadata `json:"metadata,omitempty"` Spec *NetworkPolicySpec `json:"spec,omitempty"` }
NetworkPolicy defines label-based filtering for network ingress
func NewNetworkPolicy ¶
func NewNetworkPolicy(name, namespace string, allowedLabels map[string]string) *NetworkPolicy
NewNetworkPolicy returns a network policy allowing ingress from the given labels
type NetworkPolicyRule ¶
type NetworkPolicyRule struct { From []IngressRuleSelector `json:"from,omitempty"` To []IngressRuleSelector `json:"to,omitempty"` }
NetworkPolicyRule defines egress or ingress
type NetworkPolicySpec ¶
type NetworkPolicySpec struct { Ingress []NetworkPolicyRule `json:"ingress,omitempty"` Egress []NetworkPolicyRule `json:"egress,omitempty"` PodSelector *Selector `json:"podSelector,omitempty"` PolicyTypes []string `json:"policyTypes,omitempty"` }
NetworkPolicySpec is the spec for a NetworkPolicy
type PersistentVolumeClaimVolumeSource ¶
type PersistentVolumeClaimVolumeSource struct {
ClaimName string `json:"claimName"`
}
PersistentVolumeClaimVolumeSource represents a reference to a PersistentVolumeClaim in the same namespace
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 ¶
type PodCondition struct { Type string `json:"type"` Reason string `json:"reason,omitempty"` Message string `json:"message,omitempty"` }
PodCondition describes the state of pod
type PodSpec ¶
type PodSpec struct { Containers []Container `json:"containers,omitempty"` RuntimeClassName string `json:"runtimeClassName,omitempty"` ServiceAccountName string `json:"serviceAccountName,omitempty"` Volumes []Volume `json:"volumes,omitempty"` }
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 Probe ¶
type Probe struct { TCPSocket *TCPSocketAction `json:"tcpSocket,omitempty"` PeriodSeconds int `json:"periodSeconds"` InitialDelaySeconds int `json:"initialDelaySeconds"` }
Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.
type Resource ¶
Resource is API resource
func NewDeployment ¶
func NewDeployment(s *runtime.Service, opts *runtime.CreateOptions) *Resource
NewDeployment returns default micro kubernetes deployment definition
func NewService ¶
func NewService(s *runtime.Service, opts *runtime.CreateOptions) *Resource
NewService returns default micro kubernetes service definition
type ResourceLimits ¶
type ResourceLimits struct { Memory string `json:"memory,omitempty"` CPU string `json:"cpu,omitempty"` EphemeralStorage string `json:"ephemeral-storage,omitempty"` }
ResourceLimits describes the limits for a service
type ResourceQuota ¶
type ResourceQuota struct { Metadata *Metadata `json:"metadata,omitempty"` Spec *ResourceQuotaSpec `json:"spec,omitempty"` }
ResourceQuota defines resource limits for a namespace
func NewResourceQuota ¶
func NewResourceQuota(resourceQuota *runtime.ResourceQuota) *ResourceQuota
type ResourceQuotaSpec ¶
type ResourceQuotaSpec struct {
Hard *ResourceQuotaSpecs `json:"hard,omitempty"`
}
ResourceQuotaSpec
type ResourceQuotaSpecs ¶
type ResourceQuotaSpecs struct { LimitsCPU string `json:"limits.cpu,omitempty"` LimitsEphemeralStorage string `json:"limits.ephemeral-storage,omitempty"` LimitsMemory string `json:"limits.memory,omitempty"` RequestsCPU string `json:"requests.cpu,omitempty"` RequestsEphemeralStorage string `json:"requests.ephemeral-storage,omitempty"` RequestsMemory string `json:"requests.memory,omitempty"` }
ResourceQuotaSpecs defines requests and limits
type ResourceRequirements ¶
type ResourceRequirements struct { Limits *ResourceLimits `json:"limits,omitempty"` Requests *ResourceLimits `json:"requests,omitempty"` }
ResourceRequirements describes the compute resource requirements.
type Secret ¶
type Secret struct { Type string `json:"type,omitempty"` Data map[string]string `json:"data"` Metadata *Metadata `json:"metadata,omitempty"` }
Secret
type SecretKeySelector ¶
type SecretKeySelector struct { Key string `json:"key"` Name string `json:"name"` Optional bool `json:"optional,omitempty"` }
SecretKeySelector selects a key of a Secret.
type Service ¶
type Service struct { Metadata *Metadata `json:"metadata"` Spec *ServiceSpec `json:"spec,omitempty"` Status *ServiceStatus `json:"status,omitempty"` }
Service is kubernetes service
type ServiceAccount ¶
type ServiceAccount struct { Metadata *Metadata `json:"metadata,omitempty"` ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets,omitempty"` }
ServiceAccount
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 TCPSocketAction ¶
type TCPSocketAction struct { Host string `json:"host,omitempty"` Port interface{} `json:"port,omitempty"` }
TCPSocketAction describes an action based on opening a socket
type Template ¶
type Template struct { Metadata *Metadata `json:"metadata,omitempty"` PodSpec *PodSpec `json:"spec,omitempty"` }
Template is micro deployment template
type UpdateOption ¶
type UpdateOption func(*UpdateOptions)
func UpdateNamespace ¶
func UpdateNamespace(ns string) UpdateOption
UpdateNamespace sets the namespace for updating a resource
type UpdateOptions ¶
type UpdateOptions struct {
Namespace string
}
type Volume ¶
type Volume struct { Name string `json:"name"` PersistentVolumeClaim PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty"` }
Volume describes a volume which can be mounted to a pod
type VolumeMount ¶
VolumeMount describes a mounting of a Volume within a container.
type WatchOption ¶
type WatchOption func(*WatchOptions)
func WatchNamespace ¶
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