helper

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 26 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HTTP_VERBOSE_ENVVAR = "THREESCALE_DEBUG"
)

Variables

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

Functions

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 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 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(vars []v1.EnvVar, name string) (v1.EnvVar, bool)

func GetEnvVar added in v0.4.0

func GetEnvVar(key, def string) string

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 IsInvalidSpecError added in v0.6.0

func IsInvalidSpecError(err error) bool

func IsOrphanSpecError added in v0.6.0

func IsOrphanSpecError(err error) bool

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, componentVersion string, componentType ComponentType) map[string]string

func ParseVersion added in v0.6.0

func ParseVersion(image string) string

func PortFromURL

func PortFromURL(url *url.URL) int

PortFromURL infers port number if it is not explict

func PortaClient

func PortaClient(providerAccount *ProviderAccount) (*threescaleapi.ThreeScaleClient, error)

PortaClient instantiate porta_client.ThreeScaleClient from ProviderAccount object

func PortaClientFromURL added in v0.6.0

func PortaClientFromURL(url *url.URL, token string) (*threescaleapi.ThreeScaleClient, error)

PortaClientFromURL instantiates porta_client.ThreeScaleClient from admin url object

func PortaClientFromURLString

func PortaClientFromURLString(adminURLStr, token string) (*threescaleapi.ThreeScaleClient, error)

func SanitizeBackendSystemName added in v0.6.0

func SanitizeBackendSystemName(systemName string) string

func SanitizeProductSystemName added in v0.6.0

func SanitizeProductSystemName(systemName string) string

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 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 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 ApplicationPlanEntity added in v0.6.0

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

func NewApplicationPlanEntity added in v0.6.0

func NewApplicationPlanEntity(productID int64, obj threescaleapi.ApplicationPlanItem, cl *threescaleapi.ThreeScaleClient, logger logr.Logger) *ApplicationPlanEntity

func (*ApplicationPlanEntity) ApprovalRequired added in v0.6.0

func (b *ApplicationPlanEntity) ApprovalRequired() bool

func (*ApplicationPlanEntity) CostPerMonth added in v0.6.0

func (b *ApplicationPlanEntity) CostPerMonth() float64

func (*ApplicationPlanEntity) CreateLimit added in v0.6.0

func (b *ApplicationPlanEntity) CreateLimit(metricID int64, params threescaleapi.Params) error

func (*ApplicationPlanEntity) CreatePricingRule added in v0.6.0

func (b *ApplicationPlanEntity) CreatePricingRule(metricID int64, params threescaleapi.Params) error

func (*ApplicationPlanEntity) DeleteLimit added in v0.6.0

func (b *ApplicationPlanEntity) DeleteLimit(metricID, id int64) error

func (*ApplicationPlanEntity) DeletePricingRule added in v0.6.0

func (b *ApplicationPlanEntity) DeletePricingRule(metricID, id int64) error

func (*ApplicationPlanEntity) ID added in v0.6.0

func (b *ApplicationPlanEntity) ID() int64

func (*ApplicationPlanEntity) Limits added in v0.6.0

func (*ApplicationPlanEntity) Name added in v0.6.0

func (b *ApplicationPlanEntity) Name() string

func (*ApplicationPlanEntity) PricingRules added in v0.6.0

func (*ApplicationPlanEntity) SetupFee added in v0.6.0

func (b *ApplicationPlanEntity) SetupFee() float64

func (*ApplicationPlanEntity) TrialPeriodDays added in v0.6.0

func (b *ApplicationPlanEntity) TrialPeriodDays() int

func (*ApplicationPlanEntity) Update added in v0.6.0

func (b *ApplicationPlanEntity) Update(params threescaleapi.Params) error

type BackendAPIEntity added in v0.6.0

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

func NewBackendAPIEntity added in v0.6.0

func NewBackendAPIEntity(backendAPIObj *threescaleapi.BackendApi, client *threescaleapi.ThreeScaleClient, logger logr.Logger) *BackendAPIEntity

func (*BackendAPIEntity) CreateMappingRule added in v0.6.0

func (b *BackendAPIEntity) CreateMappingRule(params threescaleapi.Params) error

func (*BackendAPIEntity) CreateMethod added in v0.6.0

func (b *BackendAPIEntity) CreateMethod(params threescaleapi.Params) error

func (*BackendAPIEntity) CreateMetric added in v0.6.0

func (b *BackendAPIEntity) CreateMetric(params threescaleapi.Params) error

func (*BackendAPIEntity) DeleteMappingRule added in v0.6.0

func (b *BackendAPIEntity) DeleteMappingRule(id int64) error

func (*BackendAPIEntity) DeleteMethod added in v0.6.0

func (b *BackendAPIEntity) DeleteMethod(id int64) error

func (*BackendAPIEntity) DeleteMetric added in v0.6.0

func (b *BackendAPIEntity) DeleteMetric(id int64) error

func (*BackendAPIEntity) Description added in v0.6.0

func (b *BackendAPIEntity) Description() string

func (*BackendAPIEntity) FindMethodMetricIDBySystemName added in v0.6.0

func (b *BackendAPIEntity) FindMethodMetricIDBySystemName(systemName string) (int64, error)

FindMethodMetricIDBySystemName returns metric or method ID from system name. -1 if metric and method is not found

func (*BackendAPIEntity) ID added in v0.6.0

func (b *BackendAPIEntity) ID() int64

func (*BackendAPIEntity) MappingRules added in v0.6.0

func (*BackendAPIEntity) Methods added in v0.6.0

func (*BackendAPIEntity) Metrics added in v0.6.0

func (*BackendAPIEntity) MetricsAndMethods added in v0.6.0

func (b *BackendAPIEntity) MetricsAndMethods() (*threescaleapi.MetricJSONList, error)

func (*BackendAPIEntity) Name added in v0.6.0

func (b *BackendAPIEntity) Name() string

func (*BackendAPIEntity) PrivateEndpoint added in v0.6.0

func (b *BackendAPIEntity) PrivateEndpoint() string

func (*BackendAPIEntity) SystemName added in v0.6.0

func (b *BackendAPIEntity) SystemName() string

func (*BackendAPIEntity) Update added in v0.6.0

func (b *BackendAPIEntity) Update(params threescaleapi.Params) error

func (*BackendAPIEntity) UpdateMappingRule added in v0.6.0

func (b *BackendAPIEntity) UpdateMappingRule(id int64, params threescaleapi.Params) error

func (*BackendAPIEntity) UpdateMethod added in v0.6.0

func (b *BackendAPIEntity) UpdateMethod(id int64, params threescaleapi.Params) error

func (*BackendAPIEntity) UpdateMetric added in v0.6.0

func (b *BackendAPIEntity) UpdateMetric(id int64, params threescaleapi.Params) error

type BackendAPIRemoteIndex added in v0.6.0

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

func NewBackendAPIRemoteIndex added in v0.6.0

func NewBackendAPIRemoteIndex(client *threescaleapi.ThreeScaleClient, logger logr.Logger) (*BackendAPIRemoteIndex, error)

func (*BackendAPIRemoteIndex) CreateBackendAPI added in v0.6.0

func (b *BackendAPIRemoteIndex) CreateBackendAPI(params threescaleapi.Params) (*BackendAPIEntity, error)

CreateBackendAPI create remote backendAPI

func (*BackendAPIRemoteIndex) FindByID added in v0.6.0

func (b *BackendAPIRemoteIndex) FindByID(id int64) (*BackendAPIEntity, bool)

FindByID finds remote backendAPI item by ID

func (*BackendAPIRemoteIndex) FindBySystemName added in v0.6.0

func (b *BackendAPIRemoteIndex) FindBySystemName(systemName string) (*BackendAPIEntity, bool)

FindBySystemName finds remote backendAPI item by SystenName

type ComponentType added in v0.6.0

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

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 ProductEntity added in v0.6.0

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

func NewProductEntity added in v0.6.0

func NewProductEntity(obj *threescaleapi.Product, cl *threescaleapi.ThreeScaleClient, logger logr.Logger) *ProductEntity

func (*ProductEntity) ApplicationPlans added in v0.6.0

func (b *ProductEntity) ApplicationPlans() (*threescaleapi.ApplicationPlanJSONList, error)

func (*ProductEntity) BackendUsages added in v0.6.0

func (b *ProductEntity) BackendUsages() (threescaleapi.BackendAPIUsageList, error)

func (*ProductEntity) BackendVersion added in v0.6.0

func (b *ProductEntity) BackendVersion() string

func (*ProductEntity) CreateApplicationPlan added in v0.6.0

func (b *ProductEntity) CreateApplicationPlan(params threescaleapi.Params) (*threescaleapi.ApplicationPlan, error)

func (*ProductEntity) CreateBackendUsage added in v0.6.0

func (b *ProductEntity) CreateBackendUsage(params threescaleapi.Params) error

func (*ProductEntity) CreateMappingRule added in v0.6.0

func (b *ProductEntity) CreateMappingRule(params threescaleapi.Params) error

func (*ProductEntity) CreateMethod added in v0.6.0

func (b *ProductEntity) CreateMethod(params threescaleapi.Params) error

func (*ProductEntity) CreateMetric added in v0.6.0

func (b *ProductEntity) CreateMetric(params threescaleapi.Params) error

func (*ProductEntity) DeleteApplicationPlan added in v0.6.0

func (b *ProductEntity) DeleteApplicationPlan(id int64) error

func (*ProductEntity) DeleteBackendUsage added in v0.6.0

func (b *ProductEntity) DeleteBackendUsage(id int64) error

func (*ProductEntity) DeleteMappingRule added in v0.6.0

func (b *ProductEntity) DeleteMappingRule(id int64) error

func (*ProductEntity) DeleteMethod added in v0.6.0

func (b *ProductEntity) DeleteMethod(id int64) error

func (*ProductEntity) DeleteMetric added in v0.6.0

func (b *ProductEntity) DeleteMetric(id int64) error

func (*ProductEntity) DeploymentOption added in v0.6.0

func (b *ProductEntity) DeploymentOption() string

func (*ProductEntity) Description added in v0.6.0

func (b *ProductEntity) Description() string

func (*ProductEntity) FindMethodMetricIDBySystemName added in v0.6.0

func (b *ProductEntity) FindMethodMetricIDBySystemName(systemName string) (int64, error)

FindMethodMetricIDBySystemName returns metric or method ID from system name. -1 if metric and method is not found

func (*ProductEntity) ID added in v0.6.0

func (b *ProductEntity) ID() int64

func (*ProductEntity) MappingRules added in v0.6.0

func (b *ProductEntity) MappingRules() (*threescaleapi.MappingRuleJSONList, error)

func (*ProductEntity) Methods added in v0.6.0

func (b *ProductEntity) Methods() (*threescaleapi.MethodList, error)

func (*ProductEntity) Metrics added in v0.6.0

func (*ProductEntity) MetricsAndMethods added in v0.6.0

func (b *ProductEntity) MetricsAndMethods() (*threescaleapi.MetricJSONList, error)

func (*ProductEntity) Name added in v0.6.0

func (b *ProductEntity) Name() string

func (*ProductEntity) PromoteProxyToStaging added in v0.6.0

func (b *ProductEntity) PromoteProxyToStaging() error

func (*ProductEntity) Proxy added in v0.6.0

func (b *ProductEntity) Proxy() (*threescaleapi.ProxyJSON, error)

func (*ProductEntity) State added in v0.6.0

func (b *ProductEntity) State() string

func (*ProductEntity) Update added in v0.6.0

func (b *ProductEntity) Update(params threescaleapi.Params) error

func (*ProductEntity) UpdateBackendUsage added in v0.6.0

func (b *ProductEntity) UpdateBackendUsage(id int64, params threescaleapi.Params) error

func (*ProductEntity) UpdateMappingRule added in v0.6.0

func (b *ProductEntity) UpdateMappingRule(id int64, params threescaleapi.Params) error

func (*ProductEntity) UpdateMethod added in v0.6.0

func (b *ProductEntity) UpdateMethod(id int64, params threescaleapi.Params) error

func (*ProductEntity) UpdateMetric added in v0.6.0

func (b *ProductEntity) UpdateMetric(id int64, params threescaleapi.Params) error

func (*ProductEntity) UpdateProxy added in v0.6.0

func (b *ProductEntity) UpdateProxy(params threescaleapi.Params) error

type ProviderAccount added in v0.6.0

type ProviderAccount struct {
	AdminURLStr string
	Token       string
}

func LookupProviderAccount added in v0.6.0

func LookupProviderAccount(cl client.Client, ns string, providerAccountRef *corev1.LocalObjectReference, logger logr.Logger) (*ProviderAccount, error)

LookupProviderAccount looks up for account provider url and credentials If provider_account_reference is provided, it must exist and required fields must exists If no provider_account_reference is provided, defaul provider account secret with hardcoded name will be looked up in the namespace. If no provider_account_reference is provided AND default provider account secret is not found either, then, 3scale default provider account (3scale-admin) will be looked up using system-seed secret in the current namespace. If nothing is successfully found, return error

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 client.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.

Jump to

Keyboard shortcuts

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