attribute

package
v0.0.0-...-f843765 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

the attribute package deals with everything that is related to operations on K8s object labels and env. vars

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEnvVars        = errors.New("the object has no .cluster.local env vars")
	ErrEmptyParam       = errors.New("a required parameter is empty")
	ErrResourceNotFound = errors.New("this resource does not exist")
	ErrTypeNotSupported = errors.New("this type is not supported")
)

Functions

func Contains

func Contains[T comparable](elems []T, v T) bool

helper function to check if []T contains T

func MapsEqual

func MapsEqual[K comparable, V comparable](a, b map[K]V) bool

helper function to check if two maps are equal or not

Types

type Handler

type Handler struct {
	Client kubernetes.Interface
}

func (*Handler) ConvertLabels

func (h *Handler) ConvertLabels(targetPodLabels map[string]string) map[string][]string

ConvertMap converts K8s object labels (map[string]string) to map[string][]string. e.g {"label":"value"} -> label: {"value"}

func (*Handler) GetLabelsFromEnvVars

func (h *Handler) GetLabelsFromEnvVars(envVars map[string]string) (map[string][]string, error)

GetLabelsFromEnvVars takes in the environment variables containing "<name>.<namespace>.svc.cluster.local" and "<name>.<namespace>.pod.cluster.local". Then for PODs, it returns all the labels it has and for services it looks at the .spec.Selector (which are esentially the POD labels it targets) and returns those. It returns a map[string][]string because it can happen that two pods have the same label keys with different values.

e.g	{
	    "app": ["test", "frontend", "backend"],
	    "version": ["1.0", "2.0"],
	    "env": ["prod"],
	}

func (*Handler) GetLocalEnvVars

func (h *Handler) GetLocalEnvVars(obj metav1.Object) (map[string]string, error)

GetLocalEnvVars fetches all env. vars with the values of <name>.<namespace>.svc/pod.cluster.local

func (*Handler) MergeLabels

func (h *Handler) MergeLabels(targetLabels ...map[string][]string) (map[string][]string, error)

MergeLabels merges a variadic number of labels into one

Jump to

Keyboard shortcuts

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