k8s

package
v0.0.3 Latest Latest
Warning

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

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

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

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

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

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

func GetNodeStatus

func GetNodeStatus(node v1.Node) string

func GetPodStatus

func GetPodStatus(pod v1.Pod) string

func GetUnstructuredObjects

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

func GetValidName

func GetValidName(name string) string

func HasTaint

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

func IsPodReady(pod v1.Pod) bool

func IsStaticPod

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

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

func WaitForNamespace

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

Types

type ApplyHook

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

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 NewClient

func NewClient(config *rest.Config, logger logger.Logger) *Client

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) 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

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) GetClientByKind

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

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

func (*Client) GetEventsFor

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) 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) 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) WaitForDeployment

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

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

func (*Client) WaitForTaintRemoval

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 Health

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

func (Health) GetNonReadyPods

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 PatchApplier

type PatchApplier struct {
	Clientset *kubernetes.Clientset
	Log       logr.Logger
	FuncMap   template.FuncMap
}

func NewPatchApplier

func NewPatchApplier(clientset *kubernetes.Clientset, log logr.Logger) *PatchApplier

func (*PatchApplier) Apply

func (p *PatchApplier) Apply(resource *unstructured.Unstructured, patchStr string, patchType PatchType) (*unstructured.Unstructured, error)

func (*PatchApplier) JSONPath

func (p *PatchApplier) JSONPath(object interface{}, jsonpath string) string

func (*PatchApplier) KGet

func (p *PatchApplier) KGet(path, jsonpath string) string

type PatchType

type PatchType string
var (
	PatchTypeYaml PatchType = "yaml"
	PatchTypeJSON PatchType = "json"
)

type ResourcePatch

type ResourcePatch struct {
	Resource   *unstructured.Unstructured
	Patch      string
	Kind       string
	APIVersion string
	PatchType  PatchType
}

type TemplateManager

type TemplateManager struct {
	Client *Client
	kubernetes.Interface
	Log          logr.Logger
	PatchApplier *PatchApplier
}

func NewTemplateManager

func NewTemplateManager(c *Client, log logr.Logger) *TemplateManager

func (*TemplateManager) Run

func (tm *TemplateManager) Run(ctx context.Context, template *templatev1.Template) error

Jump to

Keyboard shortcuts

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