k8sutil

package
v0.0.0-...-e7c744b Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KubeSystemNamespace          = "kube-system"
	TokenSecretTypeFieldSelector = "type=bootstrap.kubernetes.io/token"
)

Variables

This section is empty.

Functions

func EnsureNamespace

func EnsureNamespace(client kubernetes.Interface, namespace string) error

EnsureNamespace creates a namespace on a cluster if it does not exist.

func EnsureNamespaceWithLabel

func EnsureNamespaceWithLabel(client kubernetes.Interface, namespace string, labels map[string]string) error

EnsureNamespaceWithLabel creates a namespace with optional labels

func FormatResourceQuantity

func FormatResourceQuantity(resourceName v1.ResourceName, q *resource.Quantity) string

func GetOrCreateBootstrapToken

func GetOrCreateBootstrapToken(ctx context.Context, log logrus.FieldLogger, client kubernetes.Interface) (string, error)

GetOrCreateBootstrapToken This function will ensure to have at least 1 token that expire at least 1 hour from now GetOrCreateBootstrapToken returns a token for joining the cluster, creating a new one if there isn't any with enough time until expiration

func GetOrCreateClusterRole

func GetOrCreateClusterRole(log logrus.FieldLogger, client *kubernetes.Clientset, name string, rules []rbacv1.PolicyRule) (*rbacv1.ClusterRole, error)

GetOrCreateClusterRole gets the cluster role with the given name if exists otherwise creates new one and returns it

func GetOrCreateClusterRoleBinding

func GetOrCreateClusterRoleBinding(log logrus.FieldLogger,
	client *kubernetes.Clientset,
	name string, serviceAccount *v1.ServiceAccount,
	clusterRole *rbacv1.ClusterRole,
) (*rbacv1.ClusterRoleBinding, error)

GetOrCreateClusterRoleBinding creates the cluster role binding given its name, service account and cluster role if not exists. It returns the found cluster role binding if one already exists or the newly created one.

func GetOrCreateServiceAccount

func GetOrCreateServiceAccount(log logrus.FieldLogger, client *kubernetes.Clientset, namespace, name string) (*v1.ServiceAccount, error)

GetOrCreateServiceAccount checks is service account with given name exists in the specified namespace and returns it. if it doesn't exists it creates a new one and returns it to the caller.

func GetPodName

func GetPodName(client corev1.PodsGetter, namespace string, selector labels.Selector) (string, error)

GetPodName fetches the name of a pod running in the given namespace.

func GetResourceQuantityInBytes

func GetResourceQuantityInBytes(q *resource.Quantity) int

func IsK8sErrorPermanent

func IsK8sErrorPermanent(err error) bool

IsK8sErrorPermanent checks if the given error is permanent error or not

func NewKubeTunnel

func NewKubeTunnel(namespace string, client kubernetes.Interface, config *rest.Config, selector labels.Selector, internalPort int) (*kube.Tunnel, error)

New creates a new and initialized tunnel.

Types

type AuthInfoFactory

type AuthInfoFactory interface {
	CreateAuthInfo(string) *clientcmdapi.AuthInfo
}

type ConfigBase

type ConfigBase struct {
	ClusterName              string
	APIEndpoint              string
	CertificateAuthorityData []byte
}

func ExtractConfigBase

func ExtractConfigBase(config *clientcmdapi.Config) *ConfigBase

func (*ConfigBase) CreateConfigFromTemplate

func (configBase *ConfigBase) CreateConfigFromTemplate(authInfo AuthInfoFactory) *clientcmdapi.Config

CreateConfigFromTemplate creates a minimal Kubernetes Config based on the given information

type CreateAuthInfoFunc

type CreateAuthInfoFunc func(clusterName string) *clientcmdapi.AuthInfo

CreateAuthInfoFunc creates a provider specific AuthInfo object for the given cluster

func (CreateAuthInfoFunc) CreateAuthInfo

func (f CreateAuthInfoFunc) CreateAuthInfo(clusterName string) *clientcmdapi.AuthInfo

CreateAuthInfo implements AuthInfoFactory for CreateAuthInfoFunc

type TunnelDestinationNotFoundError

type TunnelDestinationNotFoundError error

Jump to

Keyboard shortcuts

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