kubernetesutils

package
v0.322.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

kubernetesutils

Work with kubernetes.

Examples

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInClusterAuthenticationAvailable added in v0.305.0

func IsInClusterAuthenticationAvailable(ctx context.Context) bool

func SecretByNameExists added in v0.320.0

func SecretByNameExists(ctx context.Context, namespace string, secretName string)

func SortResourcesYaml

func SortResourcesYaml(resourcesYaml string) (sortedResourcesYaml string, err error)

Sort resources in given multi yaml string. Resources are sorted by:

  1. Namespace
  2. Resource name
  3. Kind

Types

type ConfigMap added in v0.322.0

type ConfigMap interface {
	Exists(ctx context.Context) (bool, error)
}

type CreateConfigMapOptions added in v0.322.0

type CreateConfigMapOptions struct {
	ConfigMapData map[string]string
}

func (*CreateConfigMapOptions) GetConfigMapData added in v0.322.0

func (c *CreateConfigMapOptions) GetConfigMapData() (map[string]string, error)

type CreateResourceOptions added in v0.308.0

type CreateResourceOptions struct {
	YamlString string

	// Do not check nor try to create missing namespaces.
	// Usefull if the user has no rights to list or create namespaces but requiers to ensure namespaces already exists.
	SkipNamespaceCreation bool
}

func (CreateResourceOptions) GetYamlString added in v0.308.0

func (c CreateResourceOptions) GetYamlString() (string, error)

type CreateRoleOptions

type CreateRoleOptions struct {
	Name     string
	Verbs    []string
	Resorces []string
}

func NewCreateRoleOptions

func NewCreateRoleOptions() (c *CreateRoleOptions)

func (*CreateRoleOptions) GetName

func (c *CreateRoleOptions) GetName() (name string, err error)

func (*CreateRoleOptions) GetResorces

func (c *CreateRoleOptions) GetResorces() (resorces []string, err error)

func (*CreateRoleOptions) GetVerbs

func (c *CreateRoleOptions) GetVerbs() (verbs []string, err error)

func (*CreateRoleOptions) SetName

func (c *CreateRoleOptions) SetName(name string) (err error)

func (*CreateRoleOptions) SetResorces

func (c *CreateRoleOptions) SetResorces(resorces []string) (err error)

func (*CreateRoleOptions) SetVerbs

func (c *CreateRoleOptions) SetVerbs(verbs []string) (err error)

type CreateSecretOptions added in v0.320.0

type CreateSecretOptions struct {
	SecretData map[string][]byte
}

func (*CreateSecretOptions) GetSecretData added in v0.320.0

func (c *CreateSecretOptions) GetSecretData() (map[string][]byte, error)

type KubectlContext

type KubectlContext struct {
	// contains filtered or unexported fields
}

func NewKubectlContext

func NewKubectlContext() (k *KubectlContext)

func (*KubectlContext) GetCluster

func (k *KubectlContext) GetCluster() (cluster string, err error)

func (*KubectlContext) GetName

func (k *KubectlContext) GetName() (name string, err error)

func (*KubectlContext) SetCluster

func (k *KubectlContext) SetCluster(cluster string) (err error)

func (*KubectlContext) SetName

func (k *KubectlContext) SetName(name string) (err error)

type KubernetesCluster

type KubernetesCluster interface {
	ConfigMapByNameExists(ctx context.Context, namespaceName string, configMapName string) (exists bool, err error)
	CreateConfigMap(ctx context.Context, namespaceName string, configMapName string, options *CreateConfigMapOptions) (createdConfigMap ConfigMap, err error)
	CreateNamespaceByName(ctx context.Context, namespaceName string) (createdNamespace Namespace, err error)
	CreateSecret(ctx context.Context, namespaceName string, secretName string, options *CreateSecretOptions) (createdSecret Secret, err error)
	DeleteNamespaceByName(ctx context.Context, namespaceName string) (err error)
	DeleteSecretByName(ctx context.Context, namespaceName string, secretName string) (err error)
	GetKubectlContext(ctx context.Context) (contextName string, err error)
	GetName() (name string, err error)
	GetNamespaceByName(name string) (namespace Namespace, err error)
	GetResourceByNames(resourceName string, resourceType string, namespaceName string) (resource Resource, err error)
	ListNamespaces(ctx context.Context) (namespaces []Namespace, err error)
	ListNamespaceNames(ctx context.Context) (namespaceNames []string, err error)
	ListResources(options *parameteroptions.ListKubernetesResourcesOptions) (resources []Resource, err error)
	ListResourceNames(options *parameteroptions.ListKubernetesResourcesOptions) (resourceNames []string, err error)
	NamespaceByNameExists(ctx context.Context, namespaceName string) (exists bool, err error)
	SecretByNameExists(ctx context.Context, namespaceName string, secretName string) (exists bool, err error)
}

type KubernetesControlplaneHost

type KubernetesControlplaneHost struct {
	hosts.Host
}

func GetKubernetesControlplaneByHost

func GetKubernetesControlplaneByHost(host hosts.Host) (kubernetesControlplaneHost *KubernetesControlplaneHost, err error)

func GetKubernetesControlplaneByHostname

func GetKubernetesControlplaneByHostname(hostname string) (kubernetesControlplaneHost *KubernetesControlplaneHost, err error)

func NewKubernetesControlplaneHost

func NewKubernetesControlplaneHost() (kubernetesControlplaneHost *KubernetesControlplaneHost)

func (*KubernetesControlplaneHost) CheckIsKubernetesControlplane

func (k *KubernetesControlplaneHost) CheckIsKubernetesControlplane(verbose bool) (isKubernetesControlplane bool, err error)

func (*KubernetesControlplaneHost) GetJoinCommandAsString

func (k *KubernetesControlplaneHost) GetJoinCommandAsString(verbose bool) (joinCommand string, err error)

func (*KubernetesControlplaneHost) GetJoinCommandAsStringSlice

func (k *KubernetesControlplaneHost) GetJoinCommandAsStringSlice(verbose bool) (joinCommand []string, err error)

func (*KubernetesControlplaneHost) IsKubernetesControlplane

func (k *KubernetesControlplaneHost) IsKubernetesControlplane(verbose bool) (isKubernetesControlplane bool, err error)

type KubernetesNodeHost

type KubernetesNodeHost struct {
	hosts.Host
}

func GetKubernetesNodeByHost

func GetKubernetesNodeByHost(host hosts.Host) (kubernetesNodeHost *KubernetesNodeHost, err error)

func GetKubernetesNodeByHostname

func GetKubernetesNodeByHostname(hostname string) (kubernetesNodeHost *KubernetesNodeHost, err error)

func NewKubernetesNodeHost

func NewKubernetesNodeHost() (kubernetesNodeHost *KubernetesNodeHost)

func (*KubernetesNodeHost) CheckIsKubernetesNode

func (k *KubernetesNodeHost) CheckIsKubernetesNode(verbose bool) (isKubernetesNode bool, err error)

func (*KubernetesNodeHost) IsKubernetesNode

func (k *KubernetesNodeHost) IsKubernetesNode(verbose bool) (isKubernetesNode bool, err error)

type Namespace

type Namespace interface {
	ConfigMapByNameExists(ctx context.Context, name string) (exits bool, err error)
	Create(ctx context.Context) (err error)
	CreateConfigMap(ctx context.Context, name string, options *CreateConfigMapOptions) (createdConfigMap ConfigMap, err error)
	CreateRole(ctx context.Context, createOptions *CreateRoleOptions) (createdRole Role, err error)
	CreateSecret(ctx context.Context, name string, options *CreateSecretOptions) (createdSecret Secret, err error)
	DeleteConfigMapByName(ctx context.Context, name string) (err error)
	DeleteRoleByName(ctx context.Context, name string) (err error)
	DeleteSecretByName(ctx context.Context, name string) (err error)
	GetClusterName() (clusterName string, err error)
	GetConfigMapByName(name string) (configMap ConfigMap, err error)
	GetKubectlContext(ctx context.Context) (contextName string, err error)
	GetName() (name string, err error)
	GetResourceByNames(resourceName string, resourceType string) (resource Resource, err error)
	GetRoleByName(name string) (role Role, err error)
	GetSecretByName(name string) (secret Secret, err error)
	ListRoleNames(ctx context.Context) (roleNames []string, err error)
	RoleByNameExists(ctx context.Context, name string) (exists bool, err error)
	SecretByNameExists(ctx context.Context, name string) (exits bool, err error)
}

type Resource

type Resource interface {
	CreateByYamlString(ctx context.Context, options *CreateResourceOptions) (err error)
	Delete(ctx context.Context) (err error)
	Exists(ctx context.Context) (exists bool, err error)
	GetAsYamlString() (yamlString string, err error)
}

a generic representation of a kubernetes resource like a pod, ingress, role...

type ResourceYamlEntry

type ResourceYamlEntry struct {
	Content string
}

func UnmarshalResourceYaml

func UnmarshalResourceYaml(resourceYaml string) (resources []*ResourceYamlEntry, err error)

func (*ResourceYamlEntry) Kind

func (r *ResourceYamlEntry) Kind() (name string)

func (*ResourceYamlEntry) Name

func (r *ResourceYamlEntry) Name() (name string)

func (*ResourceYamlEntry) Namespace

func (r *ResourceYamlEntry) Namespace() (namespace string)

func (*ResourceYamlEntry) Validate

func (r *ResourceYamlEntry) Validate() (err error)

type Role

type Role interface{}

type Secret added in v0.320.0

type Secret interface {
	Exists(ctx context.Context) (bool, error)
}

Represents a secret in kubernetes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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