k8s

package
v0.20.5 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 64 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateKubeConfig

func CreateKubeConfig(clusterName string, ca certs.CertificateAuthority, endpoint string, group string, user string, expiry time.Duration) ([]byte, error)

func CreateMultiKubeConfig added in v0.17.13

func CreateMultiKubeConfig(ca certs.CertificateAuthority, clusters map[string]string, group string, user string, expiry time.Duration) ([]byte, error)

CreateMultiKubeConfig creates a kubeconfig file contents for a map of cluster name -> cluster API endpoint hosts, all with a shared user name, group and cert expiry. NOTE: these clusters all need to share the same plaform CA

func CreateOIDCKubeConfig

func CreateOIDCKubeConfig(clusterName string, ca certs.CertificateAuthority, endpoint, idpURL, idToken, accessToken, refreshToken string) ([]byte, error)

func GetContainerStatus added in v0.17.12

func GetContainerStatus(pod v1.Pod) string

func GetCurrentClusterNameFrom

func GetCurrentClusterNameFrom(kubeConfigPath string) string

GetCurrentClusterNameFrom returns the name of the cluster associated with the currentContext of the specified kubeconfig file

func GetLastRestartTime added in v0.17.10

func GetLastRestartTime(pod v1.Pod) *time.Time

func GetNodeStatus

func GetNodeStatus(node v1.Node) string

func GetPodStatus added in v0.17.10

func GetPodStatus(pod v1.Pod) string

func GetUnstructuredObjects

func GetUnstructuredObjects(data []byte) ([]unstructured.Unstructured, error)

func GetValidName

func GetValidName(name string) string

func HasTaint added in v0.17.10

func HasTaint(node v1.Node, name string) bool

func IsDeleted

func IsDeleted(object metav1.Object) bool

func IsMasterNode

func IsMasterNode(node v1.Node) bool

func IsPodCrashLoopBackoff

func IsPodCrashLoopBackoff(pod v1.Pod) bool

func IsPodDaemonSet

func IsPodDaemonSet(pod v1.Pod) bool

func IsPodFinished

func IsPodFinished(pod v1.Pod) bool

func IsPodHealthy

func IsPodHealthy(pod v1.Pod) bool

func IsPodPending

func IsPodPending(pod v1.Pod) bool

func IsPodReady added in v0.17.10

func IsPodReady(pod v1.Pod) bool

func IsStaticPod added in v0.17.14

func IsStaticPod(pod v1.Pod) bool

IsStaticPod returns true if the pod is static i.e. declared in /etc/kubernetes/manifests and read directly by the kubelet

func LowResourceRequirements

func LowResourceRequirements() v1.ResourceRequirements

func NewCommandJob

func NewCommandJob(node, command string) v1.PodSpec

func NewDeployment

func NewDeployment(ns, name, image string, labels map[string]string, port int32, args ...string) *apps.Deployment

func NewObjectMeta

func NewObjectMeta(ns, name string) metav1.ObjectMeta

func RemoveTaint added in v0.17.10

func RemoveTaint(taints []v1.Taint, name string) []v1.Taint

func TestDeploy added in v0.16.7

func TestDeploy(client kubernetes.Interface, ns string, deploymentName string, t *console.TestResults)

func TestNamespace

func TestNamespace(client kubernetes.Interface, ns string, t *console.TestResults)

func TestPod added in v0.16.7

func TestPod(testName string, client kubernetes.Interface, events typedv1.EventInterface, pod v1.Pod, t *console.TestResults)

func WaitForNamespace

func WaitForNamespace(client kubernetes.Interface, ns string, timeout time.Duration)

Types

type ApplyHook

type ApplyHook func(namespace string, obj unstructured.Unstructured)

type Builder

type Builder struct {
	Objects     []runtime.Object
	Namespace   string
	Labels      map[string]string
	Annotations map[string]string
}

func (*Builder) AddAnnotations

func (b *Builder) AddAnnotations(annotations map[string]string) *Builder

func (*Builder) AddLabels

func (b *Builder) AddLabels(labels map[string]string) *Builder

func (*Builder) Append

func (b *Builder) Append(objects ...runtime.Object) *Builder

func (*Builder) ConfigMap

func (b *Builder) ConfigMap(name string, data map[string]string) *Builder

func (*Builder) Deployment

func (b *Builder) Deployment(name, image string) *DeploymentBuilder

func (*Builder) ObjectMeta

func (b *Builder) ObjectMeta(name string) metav1.ObjectMeta

func (*Builder) Secret

func (b *Builder) Secret(name string, data map[string][]byte) *Builder

func (*Builder) ServiceAccount

func (b *Builder) ServiceAccount(name string) *ServiceAccountBuilder

func (*Builder) SetNamespace

func (b *Builder) SetNamespace(namespace string) *Builder

type CRD

type CRD struct {
	Kind       string                 `yaml:"kind,omitempty"`
	APIVersion string                 `yaml:"apiVersion,omitempty"`
	Metadata   Metadata               `yaml:"metadata,omitempty"`
	Spec       map[string]interface{} `yaml:"spec,omitempty"`
}

type Client

type Client struct {
	logger.Logger
	GetKubeConfigBytes  func() ([]byte, error)
	ApplyDryRun         bool
	ApplyHook           ApplyHook
	Trace               bool
	GetKustomizePatches func() ([]string, error)
	// contains filtered or unexported fields
}

func (*Client) Annotate

func (c *Client) Annotate(obj runtime.Object, annotations map[string]string) error

func (*Client) Apply

func (c *Client) Apply(namespace string, objects ...runtime.Object) error

func (*Client) ApplyUnstructured

func (c *Client) ApplyUnstructured(namespace string, objects ...*unstructured.Unstructured) error

func (*Client) Cordon

func (c *Client) Cordon(nodeName string) error

func (*Client) CreateOrUpdateConfigMap

func (c *Client) CreateOrUpdateConfigMap(name, ns string, data map[string]string) error

func (*Client) CreateOrUpdateNamespace

func (c *Client) CreateOrUpdateNamespace(name string, labels, annotations map[string]string) error

func (*Client) CreateOrUpdateSecret

func (c *Client) CreateOrUpdateSecret(name, ns string, data map[string][]byte) error

func (*Client) DeleteUnstructured

func (c *Client) DeleteUnstructured(namespace string, objects ...*unstructured.Unstructured) error

func (*Client) Drain

func (c *Client) Drain(nodeName string, timeout time.Duration) error

func (*Client) EvictNode

func (c *Client) EvictNode(nodeName string) error

func (*Client) EvictPod

func (c *Client) EvictPod(pod v1.Pod) error

func (*Client) ExecutePodf

func (c *Client) ExecutePodf(namespace, pod, container string, command ...string) (string, string, error)

ExecutePodf runs the specified shell command inside a container of the specified pod

func (*Client) Executef

func (c *Client) Executef(node string, timeout time.Duration, command string, args ...interface{}) (string, error)

Executef runs the specified shell command on a node by creating a pre-scheduled pod that runs in the host namespace

func (*Client) ExposeIngress

func (c *Client) ExposeIngress(namespace, service string, domain string, port int, annotations map[string]string) error

func (*Client) ForceDeleteNamespace added in v0.16.3

func (c *Client) ForceDeleteNamespace(ns string, timeout time.Duration) error

ForceDeleteNamespace deletes a namespace forcibly by overriding it's finalizers first

func (*Client) Get

func (c *Client) Get(namespace string, name string, obj runtime.Object) error

func (*Client) GetAPIResource added in v0.20.5

func (c *Client) GetAPIResource(name string) (*metav1.APIResource, error)

func (*Client) GetClientByKind added in v0.16.3

func (c *Client) GetClientByKind(kind string) (dynamic.NamespaceableResourceInterface, error)

func (*Client) GetClientset

func (c *Client) GetClientset() (*kubernetes.Clientset, error)

GetClientset creates a new k8s client

func (*Client) GetConditionsForNode

func (c *Client) GetConditionsForNode(name string) (map[v1.NodeConditionType]v1.ConditionStatus, error)

func (*Client) GetConfigMap

func (c *Client) GetConfigMap(namespace, name string) *map[string]string

GetConfigMap returns the data of a secret or nil for any error

func (*Client) GetDynamicClient

func (c *Client) GetDynamicClient() (dynamic.Interface, error)

GetDynamicClient creates a new k8s client

func (*Client) GetDynamicClientForUser added in v0.17.8

func (c *Client) GetDynamicClientForUser(namespace string, obj runtime.Object, user string) (dynamic.ResourceInterface, *schema.GroupVersionResource, *unstructured.Unstructured, error)

func (*Client) GetEtcdClient added in v0.20.5

func (c *Client) GetEtcdClient(ctx context.Context) (*etcd.Client, error)

func (*Client) GetEtcdClientGenerator

func (c *Client) GetEtcdClientGenerator(ca *certs.Certificate) (*etcd.EtcdClientGenerator, error)

func (*Client) GetEventsFor added in v0.17.12

func (c *Client) GetEventsFor(kind string, object metav1.Object) ([]v1.Event, error)

func (*Client) GetFirstPodByLabelSelector

func (c *Client) GetFirstPodByLabelSelector(namespace string, labelSelector string) (*v1.Pod, error)

Returns the first pod found by label

func (*Client) GetHealth

func (c *Client) GetHealth() Health

func (*Client) GetKustomize

func (c *Client) GetKustomize() (*kustomize.Manager, error)

func (*Client) GetMasterNode

func (c *Client) GetMasterNode() (string, error)

GetMasterNode returns the name of the first node found labelled as a master

func (*Client) GetMasterNodes

func (c *Client) GetMasterNodes() ([]string, error)

GetMasterNode returns a list of all master nodes

func (*Client) GetOrCreatePVC

func (c *Client) GetOrCreatePVC(namespace, name, size, class string) error

func (*Client) GetOrCreateSecret

func (c *Client) GetOrCreateSecret(name, ns string, data map[string][]byte) error

func (*Client) GetPodReplicas

func (c *Client) GetPodReplicas(pod v1.Pod) (int, error)

func (*Client) GetProxyDialer

func (c *Client) GetProxyDialer(p proxy.Proxy) (*proxy.Dialer, error)

func (*Client) GetRESTConfig

func (c *Client) GetRESTConfig() (*rest.Config, error)

func (*Client) GetRestClient

func (c *Client) GetRestClient(obj unstructured.Unstructured) (*cliresource.Helper, error)

func (*Client) GetRestMapper

func (c *Client) GetRestMapper() (meta.RESTMapper, error)

func (*Client) GetSecret

func (c *Client) GetSecret(namespace, name string) *map[string][]byte

GetSecret returns the data of a secret or nil for any error

func (*Client) HasConfigMap

func (c *Client) HasConfigMap(ns, name string) bool

func (*Client) HasSecret

func (c *Client) HasSecret(ns, name string) bool

func (*Client) Label

func (c *Client) Label(obj runtime.Object, labels map[string]string) error

func (*Client) Orphan added in v0.20.5

func (c *Client) Orphan(kind, name, namespace string, object types.RuntimeObjectWithMetadata) error

Orphan an object by removing ownerReferences

func (*Client) OrphanCRD added in v0.20.5

func (c *Client) OrphanCRD(kind, name, namespace string) error

Orphan an object by removing ownerReferences

func (*Client) PingMaster

func (c *Client) PingMaster() bool

PingMaster attempts to connect to the API server and list nodes and services to ensure the API server is ready to accept any traffic

func (*Client) ResetConnection

func (c *Client) ResetConnection()

func (*Client) ScalePod

func (c *Client) ScalePod(pod v1.Pod, replicas int32) error

func (*Client) StreamLogs

func (c *Client) StreamLogs(namespace, name string) error

func (*Client) Uncordon

func (c *Client) Uncordon(nodeName string) error

func (*Client) Undelete added in v0.20.5

func (c *Client) Undelete(kind, name, namespace string, object types.RuntimeObjectWithMetadata) error

Undelete an object by removing terminationTimestamp and gracePeriod

func (*Client) UndeleteCRD added in v0.20.5

func (c *Client) UndeleteCRD(kind, name, namespace string) error

Undelete an object by removing terminationTimestamp and gracePeriod

func (*Client) WaitForDeployment added in v0.18.2

func (c *Client) WaitForDeployment(ns, name string, timeout time.Duration) error

WaitForDeployment waits for a deployment to have at least 1 ready replica, or returns an error if the timeout is exceeded

func (*Client) WaitForNode

func (c *Client) WaitForNode(name string, timeout time.Duration, condition v1.NodeConditionType, statii ...v1.ConditionStatus) (map[v1.NodeConditionType]v1.ConditionStatus, error)

WaitForNode waits for a pod to be in the specified phase, or returns an error if the timeout is exceeded

func (*Client) WaitForPod

func (c *Client) WaitForPod(ns, name string, timeout time.Duration, phases ...v1.PodPhase) error

WaitForPod waits for a pod to be in the specified phase, or returns an error if the timeout is exceeded

func (*Client) WaitForPodCommand

func (c *Client) WaitForPodCommand(ns, name string, container string, timeout time.Duration, command ...string) error

WaitForPodCommand waits for a command executed in pod to succeed with an exit code of 9 error if the timeout is exceeded

func (*Client) WaitForResource added in v0.16.3

func (c *Client) WaitForResource(kind, namespace, name string, timeout time.Duration) error

func (*Client) WaitForTaintRemoval added in v0.17.10

func (c *Client) WaitForTaintRemoval(name string, timeout time.Duration, taintKey string) error

WaitForNode waits for a pod to be in the specified phase, or returns an error if the timeout is exceeded

type DeploymentBuilder

type DeploymentBuilder struct {
	Builder     *Builder
	Name, Image string
	// contains filtered or unexported fields
}

func Deployment

func Deployment(name, image string) *DeploymentBuilder

func (*DeploymentBuilder) Annotations

func (d *DeploymentBuilder) Annotations(annotations map[string]string) *DeploymentBuilder

func (*DeploymentBuilder) Args

func (d *DeploymentBuilder) Args(args ...string) *DeploymentBuilder

func (*DeploymentBuilder) AsCronJob

func (d *DeploymentBuilder) AsCronJob(schedule string) *batchv1beta1.CronJob

func (*DeploymentBuilder) AsOneShotJob

func (d *DeploymentBuilder) AsOneShotJob() *v1.Pod

func (*DeploymentBuilder) Build

func (d *DeploymentBuilder) Build() *Builder

func (*DeploymentBuilder) Command

func (d *DeploymentBuilder) Command(cmd ...string) *DeploymentBuilder

func (*DeploymentBuilder) EnvVarFromConfigMap

func (d *DeploymentBuilder) EnvVarFromConfigMap(env, configmap, key string) *DeploymentBuilder

func (*DeploymentBuilder) EnvVarFromField

func (d *DeploymentBuilder) EnvVarFromField(env, field string) *DeploymentBuilder

func (*DeploymentBuilder) EnvVarFromSecret

func (d *DeploymentBuilder) EnvVarFromSecret(env, secret, key string) *DeploymentBuilder

func (*DeploymentBuilder) EnvVars

func (d *DeploymentBuilder) EnvVars(env map[string]string) *DeploymentBuilder

func (*DeploymentBuilder) Expose

func (d *DeploymentBuilder) Expose(ports ...int32) *DeploymentBuilder

func (*DeploymentBuilder) GetLabels

func (d *DeploymentBuilder) GetLabels() map[string]string

func (*DeploymentBuilder) Labels

func (d *DeploymentBuilder) Labels(labels map[string]string) *DeploymentBuilder

func (*DeploymentBuilder) MountConfigMap

func (d *DeploymentBuilder) MountConfigMap(cm, path string) *DeploymentBuilder

func (*DeploymentBuilder) MountSecret

func (d *DeploymentBuilder) MountSecret(secret, path string, mode int32) *DeploymentBuilder

func (*DeploymentBuilder) NodeAffinity

func (d *DeploymentBuilder) NodeAffinity(nodeReadinessLabel map[string]string) *DeploymentBuilder

func (*DeploymentBuilder) ObjectMeta

func (d *DeploymentBuilder) ObjectMeta() metav1.ObjectMeta

func (*DeploymentBuilder) PodAffinity

func (d *DeploymentBuilder) PodAffinity(labels map[string]string, topologyKey string) *DeploymentBuilder

func (*DeploymentBuilder) PodSpec

func (d *DeploymentBuilder) PodSpec() v1.PodSpec

func (*DeploymentBuilder) PodTemplate

func (d *DeploymentBuilder) PodTemplate() v1.PodTemplateSpec

func (*DeploymentBuilder) Ports

func (d *DeploymentBuilder) Ports(ports ...int32) *DeploymentBuilder

func (*DeploymentBuilder) Replicas

func (d *DeploymentBuilder) Replicas(replicas int) *DeploymentBuilder

func (*DeploymentBuilder) Resources

func (*DeploymentBuilder) ServiceAccount

func (d *DeploymentBuilder) ServiceAccount(name string) *DeploymentBuilder

type DynamicKind

type DynamicKind struct {
	APIVersion, Kind string
}

func (DynamicKind) GroupVersionKind

func (dk DynamicKind) GroupVersionKind() schema.GroupVersionKind

func (DynamicKind) SetGroupVersionKind

func (dk DynamicKind) SetGroupVersionKind(gvk schema.GroupVersionKind)

type Health

type Health struct {
	RunningPods, PendingPods, ErrorPods, CrashLoopBackOff int
	ReadyNodes, UnreadyNodes                              int
	Error                                                 error
}

func (Health) GetNonReadyPods added in v0.17.12

func (h Health) GetNonReadyPods() int

func (Health) IsDegradedComparedTo

func (h Health) IsDegradedComparedTo(h2 Health, tolerance int) bool

func (Health) String

func (h Health) String() string

type Metadata

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

type ServiceAccountBuilder

type ServiceAccountBuilder struct {
	*Builder
	Name string
}

func (*ServiceAccountBuilder) AddClusterRole

func (s *ServiceAccountBuilder) AddClusterRole(role string) *ServiceAccountBuilder

func (*ServiceAccountBuilder) AddRole

type Spec

type Spec struct {
	Path  string
	Items []unstructured.Unstructured
}

type Specs

type Specs []Spec

func Walk

func Walk(path string) (Specs, error)

Walk iterates recursively over each file in path and returns all of the objects contained

func (Specs) FilterBy

func (specs Specs) FilterBy(kind string) []unstructured.Unstructured

Directories

Path Synopsis
Package etcd provides a connection to an etcd member.
Package etcd provides a connection to an etcd member.
Package kustomize contains helpers for working with embedded kustomize commands Package kustomize contains helpers for working with embedded kustomize commands
Package kustomize contains helpers for working with embedded kustomize commands Package kustomize contains helpers for working with embedded kustomize commands

Jump to

Keyboard shortcuts

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