util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 16 Imported by: 77

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteTemplate

func ExecuteTemplate(templateFile string, data interface{}) (string, error)

ExecuteTemplate creates a template from the file and execute it with the specified data

func ExecuteTemplateData

func ExecuteTemplateData(templateData string, data interface{}) (string, error)

ExecuteTemplateData creates a template from string and execute it with the specified data

func ExecuteTemplateFile

func ExecuteTemplateFile(filename string, data interface{}) (string, error)

ExecuteTemplateFile - creates a template from the file and execute it with the specified data

func GetAllTemplates

func GetAllTemplates(path string, kind string, templateType string, version string) []string

GetAllTemplates - get all template files

The structur of the folder is, base path, the kind (CRD in lower case),

  • path - base path of the templates folder
  • kind - sub folder for the CRDs templates
  • templateType - TType of the templates. When the templates got rendered and added to a CM this information is e.g. used for the permissions they get mounted into the pod
  • version - if there need to be templates for different versions, they can be stored in a version subdir

Sub directories inside the specified directory with the above parameters get ignored.

func GetEnvVar

func GetEnvVar(key string, baseDefault string) string

GetEnvVar - Get the value associated with key from environment variables, but use baseDefault as a value in case the ENV variable is not defined.

func GetOr

func GetOr(m map[string]interface{}, key, fallback string) interface{}

GetOr returns the value of m[key] if it exists, fallback otherwise. As a special case, it also returns fallback if the value of m[key] is the empty string

func GetTemplateData

func GetTemplateData(t Template) (map[string]string, error)

GetTemplateData - Renders templates specified via Template struct

Check the TType const and Template type for more details on defining the template.

func GetTemplatesPath

func GetTemplatesPath() (string, error)

GetTemplatesPath get path to templates, either running local or deployed as container

func HashOfInputHashes

func HashOfInputHashes(
	hashes map[string]env.Setter,
) (string, error)

HashOfInputHashes - calculates the overall hash of hashes

func InitMap

func InitMap(m *map[string]string)

InitMap - Inititialise a map to an empty map if it is nil.

func IsJSON

func IsJSON(s string) error

IsJSON check if string is json format

func IsSet

func IsSet(m map[string]interface{}, key string) interface{}

IsSet returns the value of m[key] if key exists, otherwise false Different from getOr because it will return zero values.

func LogErrorForObject

func LogErrorForObject(
	h *helper.Helper,
	err error,
	msg string,
	object metav1.Object,
	params ...interface{},
)

LogErrorForObject - Error logging

func LogForObject

func LogForObject(
	h *helper.Helper,
	msg string,
	object metav1.Object,
	params ...interface{},
)

LogForObject - generic info level logging

func MergeStringMaps

func MergeStringMaps(baseMap map[string]string, extraMaps ...map[string]string) map[string]string

MergeStringMaps - merge two or more string->map maps NOTE: In case a key exists, the value in the first map is preserved.

func ObjectHash

func ObjectHash(i interface{}) (string, error)

ObjectHash creates a deep object hash and return it as a safe encoded string

func RemoveIndex

func RemoveIndex(s []string, index int) []string

RemoveIndex - remove int from slice

func SetHash

func SetHash(
	hashMap map[string]string,
	hashType string,
	hashStr string,
) (map[string]string, bool)

SetHash - set hashStr of type hashType on hashMap if it does not exist or hashStr is different from current stored value. Returns hashMap and bool which indicates if hashMap changed.

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice - is string in slice

func WrapErrorForObject

func WrapErrorForObject(msg string, object client.Object, err error) error

WrapErrorForObject -

Types

type Hash

type Hash struct {
	// Name of hash referencing the parameter
	Name string `json:"name,omitempty"`
	// Hash
	Hash string `json:"hash,omitempty"`
}

Hash - struct to add hashes to status

type List

type List []Pair

List -

func SortStringMapByValue

func SortStringMapByValue(in map[string]string) List

SortStringMapByValue - Creates a sorted List contain key/value of a map[string]string sorted by key

func (List) Len

func (p List) Len() int

func (List) Less

func (p List) Less(i, j int) bool

func (List) Swap

func (p List) Swap(i, j int)

type Pair

type Pair struct {
	Key   string
	Value string
}

Pair -

type TType

type TType string

TType - TemplateType

const (
	// TemplateTypeScripts - scripts type
	TemplateTypeScripts TType = "bin"
	// TemplateTypeConfig - config type
	TemplateTypeConfig TType = "config"
	// TemplateTypeCustom - custom config type, the secret/cm will not get upated as it is exected that the content is owned by a user
	// if the configmap/secret does not exist on first check, it gets created
	TemplateTypeCustom TType = "custom"
	// TemplateTypeNone - none type, don't add configs from a directory, only files from AdditionalData
	TemplateTypeNone TType = "none"
)

type Template

type Template struct {
	Name               string                 // name of the cm/secret to create based of the Template. Check secret/configmap pkg on details how it is used.
	Namespace          string                 // name of the nanmespace to create the cm/secret. Check secret/configmap pkg on details how it is used.
	Type               TType                  // type of the templates, see TTtypes
	InstanceType       string                 // the CRD name in lower case, to separate the templates for each CRD in /templates
	SecretType         corev1.SecretType      // Secrets only, defaults to "Opaque"
	AdditionalTemplate map[string]string      // templates which are common to multiple CRDs can be located in a shared folder and added via this type into the resulting CM/secret
	CustomData         map[string]string      // custom data which won't get rendered as a template and just added to the resulting cm/secret
	Labels             map[string]string      // labels to be set on the cm/secret
	Annotations        map[string]string      // Annotations set on cm/secret
	ConfigOptions      map[string]interface{} // map of parameters as input data to render the templates
	SkipSetOwner       bool                   // skip setting ownership on the associated configmap
	Version            string                 // optional version string to separate templates inside the InstanceType/Type directory. E.g. placementapi/config/18.0
}

Template - config map and secret details

Jump to

Keyboard shortcuts

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