helper

package
Version: v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: Apache-2.0 Imports: 31 Imported by: 3

Documentation

Index

Constants

View Source
const ConsoleLinkMasterNamePrefix = "system-master-link"

ConsoleLinkMasterNamePrefix is the prefix applied to Console link for system master

View Source
const ConsoleLinkText = "APIManager - 3scale"

ConsoleLinkText is the text of the consoleLink shown on the webconsole

Variables

View Source
var (
	// NonWordCharRegexp not word characters (== [^0-9A-Za-z_])
	NonWordCharRegexp = regexp.MustCompile(`\W`)

	// TemplateRegexp used to render openapi server URLs
	TemplateRegexp = regexp.MustCompile(`{([\w]+)}`)

	// NonAlphanumRegexp not alphanumeric
	NonAlphanumRegexp = regexp.MustCompile(`[^0-9A-Za-z]`)
)
View Source
var DefaultTransport = &Transport{
	Transport: http.DefaultTransport,
}

DefaultTransport is the default logging transport that wraps http.DefaultTransport.

View Source
var (
	ErrNonExistentKey = errors.New("non-existent key")
)

Errors

View Source
var (
	// InvalidDNS1123Regexp not alphanumeric
	InvalidDNS1123Regexp = regexp.MustCompile(`[^0-9A-Za-z-]`)
)

Functions

func All added in v0.8.0

func All(arr []bool) bool

func Any added in v0.8.0

func Any(arr []bool) bool

func ArrayContains added in v0.7.0

func ArrayContains(a []string, x string) bool

ArrayContains tells whether a contains x.

func ArrayFind added in v0.7.0

func ArrayFind(a []string, x string) int

ArrayFind returns the smallest index i at which x == a[i], or len(a) if there is no such index.

func ArrayStringDifference added in v0.6.0

func ArrayStringDifference(a, b []string) []string

func ArrayStringIntersection added in v0.6.0

func ArrayStringIntersection(a, b []string) []string

func BasePathFromOpenAPI added in v0.8.0

func BasePathFromOpenAPI(obj *openapi3.T) (string, error)

func BaseURLFromOpenAPI added in v0.8.0

func BaseURLFromOpenAPI(obj *openapi3.T) (string, error)

func CmpResourceList added in v0.4.0

func CmpResourceList(a, b *v1.ResourceList) bool

CmpResourceList returns true if the resourceList a is equal to b,

func CmpResources added in v0.4.0

func CmpResources(a, b *v1.ResourceRequirements) bool

CmpResources returns true if the resource requirements a is equal to b,

func DNS1123Name added in v0.8.0

func DNS1123Name(in string) string

func EnsureEnvVar added in v0.8.0

func EnsureEnvVar(desired v1.EnvVar, existingEnvVars *[]v1.EnvVar) bool

EnsureEnvVar updates existingEnvVars with desired, reconciling any possible differences. It returns whether existingEnvVars has been modified.

func EnsureObjectMeta added in v0.4.0

func EnsureObjectMeta(existing, desired common.KubernetesObject) bool

EnsureObjectMeta ensure Labels, Annotations

func EnsureString added in v0.4.0

func EnsureString(modified *bool, existing *string, required string)

func EnvVarFromConfigMap added in v0.6.0

func EnvVarFromConfigMap(envVarName string, configMapName, configMapKey string) v1.EnvVar

func EnvVarFromConfigMapOptional added in v0.6.0

func EnvVarFromConfigMapOptional(envVarName string, configMapName, configMapKey string) v1.EnvVar

func EnvVarFromSecret added in v0.6.0

func EnvVarFromSecret(envVarName string, secretName, secretKey string) v1.EnvVar

func EnvVarFromSecretOptional added in v0.6.0

func EnvVarFromSecretOptional(envVarName string, secretName, secretKey string) v1.EnvVar

func EnvVarFromValue added in v0.6.0

func EnvVarFromValue(name string, value string) v1.EnvVar

func FindContainerPortByName added in v0.6.0

func FindContainerPortByName(ports []v1.ContainerPort, name string) (v1.ContainerPort, bool)

func FindEnvVar added in v0.6.0

func FindEnvVar(a []v1.EnvVar, x string) int

FindEnvVar returns the smallest index i at which x == a[i], or -1 if there is no such index.

func FindVolumeByName added in v0.8.0

func FindVolumeByName(a []v1.Volume, name string) int

FindVolumeByName returns the smallest index i at which x.Name == a[i].Name, or -1 if there is no such index.

func FindVolumeMountByMountPath added in v0.8.0

func FindVolumeMountByMountPath(a []v1.VolumeMount, x v1.VolumeMount) int

FindVolumeMountByMountPath returns the smallest index i at which x.MountPath == a[i].MountPath, or -1 if there is no such index.

func FindVolumeMountByName added in v0.8.0

func FindVolumeMountByName(a []v1.VolumeMount, name string) int

FindVolumeMountByMountPath returns the smallest index i at which x.MountPath == a[i].MountPath, or -1 if there is no such index.

func FirstServerFromOpenAPI added in v0.8.0

func FirstServerFromOpenAPI(obj *openapi3.T) *openapi3.Server

func GenericConsoleLinkMutator added in v0.7.0

func GenericConsoleLinkMutator(existingObj, desiredObj common.KubernetesObject) (bool, error)

GenericConsoleLinkMutator performs the reconciliation for consolelink objects

func GetEnvVar added in v0.4.0

func GetEnvVar(key, def string) string
func GetMasterConsoleLink(route *routev1.Route) *consolev1.ConsoleLink

GetMasterConsoleLink creates the consolelink obj for a target

func GetMasterConsoleLinkName added in v0.7.0

func GetMasterConsoleLinkName(namespace string) string

GetMasterConsoleLinkName returns the consolelink name

func GetSecret added in v0.5.0

func GetSecret(name string, namespace string, client k8sclient.Client) (*v1.Secret, error)

func GetSecretDataFromStringData added in v0.5.0

func GetSecretDataFromStringData(secretStringData map[string]string) map[string][]byte

func GetSecretDataValue added in v0.5.0

func GetSecretDataValue(secretData map[string][]byte, fieldName string) *string

func GetSecretDataValueOrDefault added in v0.5.0

func GetSecretDataValueOrDefault(secretData map[string][]byte, fieldName string, defaultValue string) string

func GetSecretStringDataFromData added in v0.5.0

func GetSecretStringDataFromData(secretData map[string][]byte) map[string]string

func GetStringPointerValueOrDefault added in v0.5.0

func GetStringPointerValueOrDefault(val *string, def string) string

func IsDeploymentConfigAvailable added in v0.8.0

func IsDeploymentConfigAvailable(dc *appsv1.DeploymentConfig) bool

IsDeploymentConfigAvailable returns true when the provided DeploymentConfig has the "Available" condition set to true

func IsEmailValid added in v0.8.0

func IsEmailValid(e string) bool

IsEmailValid checks the structure of the email address Based on regex by W3C https://www.w3.org/TR/2016/REC-html51-20161101/sec-forms.html#email-state-typeemail

func IsInvalidSpecError added in v0.6.0

func IsInvalidSpecError(err error) bool

func IsOrphanSpecError added in v0.6.0

func IsOrphanSpecError(err error) bool

func IsRouteReady added in v0.8.0

func IsRouteReady(route *routev1.Route) bool

IsRouteReady returns true when all Ingresses of the Route have the "Admitted" Condition set to true

func IsWaitError added in v0.8.0

func IsWaitError(err error) bool

func K8sNameFromOpenAPITitle added in v0.8.0

func K8sNameFromOpenAPITitle(obj *openapi3.T) string

func MarshalObjectToYAML added in v0.6.0

func MarshalObjectToYAML(object runtime.Object) ([]byte, error)

func MergeMapStringString added in v0.4.0

func MergeMapStringString(modified *bool, existing *map[string]string, desired map[string]string)

func MergeSecretData added in v0.5.0

func MergeSecretData(from, to map[string][]byte) map[string][]byte

Returns a new map containing the contents of `from` and the contents of `to`. The value for entries with duplicated keys will be that of `from`

func MeteringLabels added in v0.6.0

func MeteringLabels(componentName string, componentType ComponentType) map[string]string

func MethodNameFromOpenAPIOperation added in v0.8.0

func MethodNameFromOpenAPIOperation(path, opVerb string, op *openapi3.Operation) string

func MethodSystemNameFromOpenAPIOperation added in v0.8.0

func MethodSystemNameFromOpenAPIOperation(path, opVerb string, op *openapi3.Operation) string

func PortFromURL

func PortFromURL(url *url.URL) int

PortFromURL infers port number if it is not explict

func RenderOpenAPIServerURL added in v0.8.0

func RenderOpenAPIServerURL(server *openapi3.Server) (*url.URL, error)

func RenderOpenAPIServerURLStr added in v0.8.0

func RenderOpenAPIServerURLStr(server *openapi3.Server) (string, error)

func RouteFindByHost added in v0.8.0

func RouteFindByHost(a []routev1.Route, routeHost string) int

RouteFindByHost returns the smallest index i at which a route with a given host is found or -1 if there is no such index.

func SetURLDefaultPort

func SetURLDefaultPort(rawurl string) string

SetURLDefaultPort adds the default Port if not set

func SortedMapStringStringKeys added in v0.6.0

func SortedMapStringStringKeys(input map[string]string) []string

func SortedMapStringStringValues added in v0.6.0

func SortedMapStringStringValues(input map[string]string) []string

func StringSliceEqualWithoutOrder added in v0.8.0

func StringSliceEqualWithoutOrder(x, y []string) bool

https://newbedev.com/check-for-equality-on-slices-without-order

func SystemNameFromOpenAPITitle added in v0.8.0

func SystemNameFromOpenAPITitle(obj *openapi3.T) string

func UIDBasedJobName added in v0.6.0

func UIDBasedJobName(prefix string, uid types.UID) (string, error)

UIDBasedJobName returns a Job name that is compromised of the provided prefix, a hyphen and the provided uid: "<prefix>-<uid>". The returned name is a DNS1123 Label compliant name. Due to UIDs are 36 characters of length this means that the maximum prefix lenght that can be provided is of 26 characters. If the generated name is not DNS1123 compliant an error is returned

func UnwrapRawExtensions added in v0.3.0

func UnwrapRawExtensions(rawExts []runtime.RawExtension) []common.KubernetesObject

NOTE: remove when templates are gone

func ValidateTLSSecret added in v0.8.0

func ValidateTLSSecret(nn types.NamespacedName, client k8sclient.Client) error

func VolumeFromSecretEqual added in v0.8.0

func VolumeFromSecretEqual(a v1.Volume, b v1.Volume) bool

func WrapRawExtension added in v0.3.0

func WrapRawExtension(object runtime.Object) runtime.RawExtension

NOTE: remove when templates are gone

func WrapRawExtensions added in v0.3.0

func WrapRawExtensions(objects []common.KubernetesObject) []runtime.RawExtension

NOTE: remove when templates are gone

Types

type ComponentType added in v0.6.0

type ComponentType string
const (
	ApplicationType    ComponentType = "application"
	InfrastructureType ComponentType = "infrastructure"
)

type ExtendedSecurityRequirement added in v0.8.0

type ExtendedSecurityRequirement struct {
	*openapi3.SecuritySchemeRef

	Scopes []string
}

func NewExtendedSecurityRequirement added in v0.8.0

func NewExtendedSecurityRequirement(secSchemeRef *openapi3.SecuritySchemeRef, scopes []string) *ExtendedSecurityRequirement

func OpenAPIGlobalSecurityRequirements added in v0.8.0

func OpenAPIGlobalSecurityRequirements(openapiObj *openapi3.T) []*ExtendedSecurityRequirement

type FieldTypeError added in v0.6.0

type FieldTypeError int
const (
	// InvalidError represents that the combination of configuration in the resource spec
	// is not supported. This is not a transient error, but
	// indicates a state that must be fixed before progress can be made.
	// Example: the two mutually exclusive attributes have been set.
	InvalidError FieldTypeError = iota

	// OrphanError represents that the configuration in the resource spec
	// contains reference to some not existing resource.
	// This is (should be) a transient error, but
	// indicates a state that must be fixed before progress can be made.
	// Example: the product Spec references non existing backend resource
	OrphanError
)

type MemoryCache added in v0.6.0

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

MemoryCache implements a simple memory cache No expiration No eviction policies Not threadsafe

func NewMemoryCache added in v0.6.0

func NewMemoryCache() *MemoryCache

func (*MemoryCache) Exists added in v0.6.0

func (c *MemoryCache) Exists(key string) bool

func (*MemoryCache) Get added in v0.6.0

func (c *MemoryCache) Get(key string) (interface{}, error)

func (*MemoryCache) Put added in v0.6.0

func (c *MemoryCache) Put(key string, data interface{})

type SecretCacheElement added in v0.6.0

type SecretCacheElement struct {
	Secret *v1.Secret
	Err    error
}

type SecretSource added in v0.6.0

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

func NewSecretSource added in v0.6.0

func NewSecretSource(client k8sclient.Client, namespace string) *SecretSource

func (*SecretSource) CachedSecret added in v0.6.0

func (s *SecretSource) CachedSecret(secretName string) (*v1.Secret, error)

func (*SecretSource) FieldValue added in v0.6.0

func (s *SecretSource) FieldValue(secretName, fieldName string, def string) (string, error)

func (*SecretSource) FieldValueFromRequiredSecret added in v0.6.0

func (s *SecretSource) FieldValueFromRequiredSecret(secretName, fieldName string, def string) (string, error)

func (*SecretSource) RequiredFieldValueFromRequiredSecret added in v0.6.0

func (s *SecretSource) RequiredFieldValueFromRequiredSecret(secretName, fieldName string) (string, error)

type SpecError added in v0.6.0

type SpecError interface {
	error
	FieldType() FieldTypeError
}

SpecError is exposed by errors that can be converted to an api.Status object for finer grained details.

type SpecFieldError added in v0.6.0

type SpecFieldError struct {
	ErrorType      FieldTypeError
	FieldErrorList field.ErrorList
}

func (*SpecFieldError) Error added in v0.6.0

func (s *SpecFieldError) Error() string

Error implements the Error interface.

func (*SpecFieldError) FieldType added in v0.6.0

func (s *SpecFieldError) FieldType() FieldTypeError

FieldType implements the SpecError interface.

type TaskRunner added in v0.6.0

type TaskRunner interface {
	Run() error
	// AddTask register tasks to be executed sequentially
	// Tasks will be executed in order. First in, first to be executed.
	AddTask(string, func(interface{}) error)
}

TaskRunner abstracts task running engine

func NewTaskRunner added in v0.6.0

func NewTaskRunner(ctx interface{}, logger logr.Logger) TaskRunner

NewTaskRunner TaskRunner Constructor

type Transport added in v0.6.0

type Transport struct {
	Transport http.RoundTripper
}

Transport implements http.RoundTripper. When set as Transport of http.Client, it executes HTTP requests with logging. No field is mandatory.

func (*Transport) RoundTrip added in v0.6.0

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip is the core part of this module and implements http.RoundTripper. Executes HTTP request with request/response logging.

type WaitError added in v0.8.0

type WaitError struct {
	Err error
}

WaitError represents that the current cluster state is not ready to continue. This is (should be) a transient error. Example: expected resources have not been created by third party controllers

func (*WaitError) Error added in v0.8.0

func (s *WaitError) Error() string

Jump to

Keyboard shortcuts

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