k8sutil

package
v0.73.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 40 Imported by: 3

Documentation

Index

Constants

View Source
const KubeConfigEnv = "KUBECONFIG"

KubeConfigEnv (optionally) specify the location of kubeconfig file.

Variables

This section is empty.

Functions

func AddTypeInformationToObject added in v0.59.0

func AddTypeInformationToObject(obj runtime.Object) error

AddTypeInformationToObject adds TypeMeta information to a runtime.Object based upon the loaded scheme.Scheme See https://github.com/kubernetes/client-go/issues/308#issuecomment-700099260

func CreateOrUpdateEndpoints added in v0.6.0

func CreateOrUpdateEndpoints(ctx context.Context, eclient clientv1.EndpointsInterface, eps *v1.Endpoints) error

func CreateOrUpdateSecret added in v0.48.0

func CreateOrUpdateSecret(ctx context.Context, secretClient clientv1.SecretInterface, desired *v1.Secret) error

CreateOrUpdateSecret merges metadata of existing Secret with new one and updates it.

func CreateOrUpdateService added in v0.6.0

func CreateOrUpdateService(ctx context.Context, sclient clientv1.ServiceInterface, svc *v1.Service) error

func IsAPIGroupVersionResourceSupported added in v0.55.0

func IsAPIGroupVersionResourceSupported(discoveryCli discovery.DiscoveryInterface, groupVersion schema.GroupVersion, resource string) (bool, error)

IsAPIGroupVersionResourceSupported checks if given groupVersion and resource is supported by the cluster.

func IsAllowed added in v0.69.1

func IsAllowed(
	ctx context.Context,
	ssarClient clientauthv1.SelfSubjectAccessReviewInterface,
	namespaces []string,
	attributes ...ResourceAttribute,
) (bool, []error, error)

IsAllowed returns whether the user (e.g. the operator's service account) has been granted the required RBAC attributes. It returns true when the conditions are met for the namespaces (an empty namespace value means "all"). The second return value returns the list of permissions that are missing if the requirements aren't met.

func IsResourceNotFoundError

func IsResourceNotFoundError(err error) bool

func LabelSelectionHasChanged added in v0.48.0

func LabelSelectionHasChanged(old, current map[string]string, selector *metav1.LabelSelector) (bool, error)

LabelSelectionHasChanged returns true if the selector doesn't yield the same results for the old and current labels.

func LoadSecretRef added in v0.69.1

func LoadSecretRef(ctx context.Context, logger log.Logger, client clientv1.SecretInterface, sks *v1.SecretKeySelector) ([]byte, error)

LoadSecretRef returns the data from a secret key reference. If the reference is set as optional and the secret or key isn't found, the function returns no error.

func MergePatchContainers added in v0.42.0

func MergePatchContainers(base, patches []v1.Container) ([]v1.Container, error)

MergePatchContainers adds patches to base using a strategic merge patch and iterating by container name, failing on the first error.

func MustRegisterClientGoMetrics added in v0.42.0

func MustRegisterClientGoMetrics(registerer prometheus.Registerer)

MustRegisterClientGoMetrics registers k8s.io/client-go metrics. It panics if it encounters an error (e.g. metrics already registered).

func NewClusterConfig

func NewClusterConfig(host string, tlsConfig rest.TLSClientConfig, asUser string) (*rest.Config, error)

func PodRunningAndReady

func PodRunningAndReady(pod v1.Pod) (bool, error)

PodRunningAndReady returns whether a pod is running and each container has passed it's ready state.

func UpdateStatefulSet added in v0.46.0

func UpdateStatefulSet(ctx context.Context, sstClient clientappsv1.StatefulSetInterface, sset *appsv1.StatefulSet) error

UpdateStatefulSet merges metadata of existing StatefulSet with new one and updates it.

Types

type ResourceAttribute added in v0.69.1

type ResourceAttribute struct {
	Resource string
	Name     string
	Group    string
	Version  string
	Verbs    []string
}

ResourceAttribute represents authorization attributes to check on a given resource.

type ResourceNamer added in v0.59.0

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

ResourceNamer knows how to generate valid names for various Kubernetes resources.

func NewResourceNamerWithPrefix added in v0.59.0

func NewResourceNamerWithPrefix(p string) ResourceNamer

NewResourceNamerWithPrefix returns a ResourceNamer that adds a prefix followed by an hyphen character to all resource names.

func (ResourceNamer) DNS1123Label added in v0.63.0

func (rn ResourceNamer) DNS1123Label(name string) (string, error)

DNS1123Label returns a name that is a valid DNS-1123 label. It will sanitize a name, removing invalid characters and if the name is bigger than 63 chars it will truncate it.

func (ResourceNamer) UniqueDNS1123Label added in v0.63.0

func (rn ResourceNamer) UniqueDNS1123Label(name string) (string, error)

UniqueDNS1123Label returns a name that is a valid DNS-1123 label. The returned name has a hash-based suffix to ensure uniqueness in case the input name exceeds the 63-chars limit.

Jump to

Keyboard shortcuts

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