kube

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(client Client, namespace string, files ...string) error

Apply deploys one or more Kubernetes manifests to a cluster

func CreateOrUpdateSecret

func CreateOrUpdateSecret(client Client, namespace, secretName string, data, labels map[string]string) (result *corev1.Secret, err error)

CreateOrUpdateSecret either creates a secret if one does not exist OR it updates a secret that does exist, overwriting its data

func CreateSecret

func CreateSecret(client *rest.RESTClient, namespace string, secret *corev1.Secret) (result *corev1.Secret, err error)

CreateSecret creates a secret

func DefaultSafeContexts

func DefaultSafeContexts() []string

DefaultSafeContexts returns known safe Kubernetes contexts

func Delete

func Delete(client Client, namespace string, timeout time.Duration, files ...string) error

Delete removes Kubernetes resources from a cluster based on a set of provided manifests

func DeleteSecret

func DeleteSecret(client *rest.RESTClient, namespace, secretName string) error

DeleteSecret removes a secret

func GetPodsByLabel

func GetPodsByLabel(client Client, namespace, labelKey, labelValue string) ([]v1.Pod, error)

GetPodsByLabel returns a slice of pod objects that match a label FIXME: this function should use the k8s namespace on the client

func GetSecret

func GetSecret(client *rest.RESTClient, namespace, secretName string) (result *corev1.Secret, err error)

GetSecret checks for the existence of a secret

func NormalizeNamespace

func NormalizeNamespace(namespace string) string

NormalizeNamespace cleans a namespace to ensure kubernetes compatibility

func PortForward

func PortForward(opts ForwardingOptions) (err error)

PortForward builds out all of the required options to port forward, aggregates them into the ForwardingOptions struct and then runs the Execute() function to run the port forward operation

func RolloutStatus

func RolloutStatus(client Client, namespace string, timeout time.Duration, resourceType, resourceName string) error

RolloutStatus polls Kubernetes for a rollout status for Deployments, DaemonSets and StatefulSets; the function exits when the rollout has completed or the timeout threshold is met

func SubscribeToResources

func SubscribeToResources(
	ctx context.Context,
	client Client,
	subscribeOpts SubscribeOptions,
) error

SubscribeToResources start informers

func UpdateSecret

func UpdateSecret(client *rest.RESTClient, namespace string, secret *corev1.Secret) (result *corev1.Secret, err error)

UpdateSecret updates a secret that already exists

Types

type Client

type Client struct {
	Factory           cmdutil.Factory
	NamespaceOverride string
	OutputWriter      io.Writer
}

Client is a container for a kubernetes cmdutil factory

func Init

Init creates a new domain k8s kube.Client This will attempt to match the server API version

func InitWithSafeContexts

func InitWithSafeContexts(namespace string, safeContexts []string) (Client, error)

InitWithSafeContexts initializes a new kubernetes client set

func (*Client) CurrentContext

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

CurrentContext returns the current context from the kube config

func (*Client) GetPodByResource

func (c *Client) GetPodByResource(
	resourceType, resourceName string,
	timeout time.Duration,
) (*corev1.Pod, error)

GetPodByResource queries a kubernetes cluster for a corev1.pod by deployment

func (*Client) Namespace

func (c *Client) Namespace() string

Namespace returns the current clients namespace - Checks namespace override - Checks kube config namespace - Defaults to v1.NamespaceDefault

func (*Client) NewNamespacedBuilder

func (c *Client) NewNamespacedBuilder() *resource.Builder

NewNamespacedBuilder returns a new resource builder for structured api objects.

type ForwardingOptions

type ForwardingOptions struct {
	Namespace    string
	Pod          v1.Pod
	Client       Client
	Ports        []string
	StopChannel  chan struct{}
	ReadyChannel chan struct{}
	DoneChannel  chan error
	// contains filtered or unexported fields
}

ForwardingOptions a container for options and channels that help orchestrate the port forwarder

func (*ForwardingOptions) Stop

func (f *ForwardingOptions) Stop()

type InformerHandlers

type InformerHandlers = map[Resource]ResourceEventHandler

InformerHandlers a map for resources and handlers

type ObservableResource

type ObservableResource struct {
	Kind string
	Name string
}

ObservableResource provides a container for passing around resource kinds and names

func GetObservableResourceNamesByLabel

func GetObservableResourceNamesByLabel(client Client, namespace, labelKey, labelValue string) ([]ObservableResource, error)

GetObservableResourceNamesByLabel returns a map of resources that have a specific label this is used to provide name and kind information to the RolloutStatus function

type Resource

type Resource int64

Resource is base type of a enum

const (
	//Pod is a resource type  that matches k8s pod resource type
	Pod Resource = iota
)

type ResourceEventHandler

type ResourceEventHandler interface {
	OnAddFunc(obj interface{})
	OnUpdateFunc(oldObj, newObj interface{})
	OnDeleteFunc(obj interface{})
	GetIndexes() map[string]func(interface{}) ([]string, error)
	AddIndex(string, func(interface{}) ([]string, error))
}

ResourceEventHandler is the contract that all resources need to implement in order to be used as an informer

type SubscribeOptions

type SubscribeOptions struct {
	InformerHnadlers InformerHandlers
	Duration         time.Duration
}

SubscribeOptions holds the handlers that will be used and the refresh rate of the informers

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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