util

package
v0.0.0-...-9940484 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateOk            = "ok"
	StatePending       = "pending"
	StateFailed        = "failed"
	StateUnknown       = "unknown"
	StateNotRelevant   = "notRelevant"
	StateFinallyFailed = "finallyFailed"

	// Log level constants. Larger numbers represent less important logs.
	LogLevelDebug   = 1
	LogLevelWarning = -1

	// Strings for readable log levels
	LogLevelStringError   = "error"
	LogLevelStringWarning = "warning"
	LogLevelStringInfo    = "info"
	LogLevelStringDebug   = "debug"

	// Keys for logging common fields
	LogKeyClusterBomName        = "clusterbom-name"
	LogKeyDeployItemName        = "deployitem-name"
	LogKeyInstallationName      = "installation-name"
	LogKeyCorrelationID         = "correlation-id"
	LogKeyInterval              = "interval"
	LogKeyConfigmap             = "configmap"
	LogKeyResponseBody          = "response-body"
	LogKeySecretName            = "secret-name"
	LogKeyKappAppNamespacedName = "kappapp-name"

	TextShootNotExisting = "shoot cluster does not exist"

	APIVersionExtensionsV1beta1 = "extensions/v1beta1"
	APIVersionAppsV1beta1       = "apps/v1beta1"
	APIVersionAppsV1beta2       = "apps/v1beta2"
	APIVersionAppsV1            = "apps/v1"
	APIVersionBatchV1           = "batch/v1"

	KindDaemonSet   = "DaemonSet"
	KindDeployment  = "Deployment"
	KindStatefulSet = "StatefulSet"
	KindJob         = "Job"

	PurposeSecretValues = "secret-values"
	PurposeDiExportData = "di-export-data"

	// annotations
	AnnotationKeyReconcile   = "hub.k8s.sap.com/reconcile"
	AnnotationValueReconcile = "reconcile"

	AnnotationKeyInstallationHash = "potter.gardener.cloud/installation-hash"

	AnnotationActionIgnoreKey = "potter.gardener.cloud/action-ignore"
	Deactivate                = "deactivate"
	Reactivate                = "reactivate"

	AnnotationStatusIgnoreKey = "potter.gardener.cloud/status-ignore"
	Ignore                    = "ignore"

	// keys
	SecretValuesKey  = "secretValues"
	KeyDeletionToken = "deletionToken"

	OperationInstall = "install"
	OperationRemove  = "remove"

	ConfigTypeHelm = "helm"
	ConfigTypeKapp = "kapp"

	HubControllerFinalizer = "hub-controller"

	DeployItemConfigVersion = "potter.gardener.cloud/v1"
	DeployItemStatusVersion = "potter.gardener.cloud/v1"
)
View Source
const (
	Separator       = "-"
	DoubleSeparator = "--"
)

Variables

This section is empty.

Functions

func AddAnnotation

func AddAnnotation(obj v1.Object, key, value string)

func AddFinalizer

func AddFinalizer(obj v1.Object, finalizer string)

func AddLabels

func AddLabels(obj v1.Object, key, value string)

func CalculateRequeueDurationForPrematureRetry

func CalculateRequeueDurationForPrematureRetry(lastOp *hubv1.LastOperation) (bool, *time.Duration)

func CalculateRequeueTimeout

func CalculateRequeueTimeout(numberOfTries int32) time.Duration

func ComputeSecretDeletionToken

func ComputeSecretDeletionToken(secretDeletionKey []byte, secretName string) ([]byte, error)

func ContainsString

func ContainsString(s string, stringSlice []string) bool

func ContainsValue

func ContainsValue(value interface{}, values []interface{}) bool

func CreateDeployItemName

func CreateDeployItemName(clusterBomName, appID string) string

func CreateInitialLastOperation

func CreateInitialLastOperation() *hubv1.LastOperation

func CreateRawExtension

func CreateRawExtension(data map[string]interface{}) (*runtime.RawExtension, error)

func CreateRawExtensionOrPanic

func CreateRawExtensionOrPanic(data map[string]interface{}) *runtime.RawExtension

func CreateSecretName

func CreateSecretName(clusterBomName, appConfigID string) string

func DecodeBasicAuthCredentials

func DecodeBasicAuthCredentials(base64EncodedBasicAuthCredentials string) (string, string, error)

DecodeBasicAuthCredentials Decodes basic auth credential string and returns username, password or an error

func Decrypt

func Decrypt(ciphertext, key []byte) ([]byte, error)

func Encrypt

func Encrypt(plaintext, key []byte) ([]byte, error)

func EnrichContextAndLogger

func EnrichContextAndLogger(ctx context.Context, keysAndValues ...interface{}) (context.Context, logr.Logger)

func Example

func Example()

func GetAnnotation

func GetAnnotation(obj v1.Object, key string) (string, bool)

func GetAppCondition

func GetAppCondition(app *kapp.App, conditionType kapp.AppConditionType) *kapp.AppCondition

func GetAppConditionStatus

func GetAppConditionStatus(app *kapp.App, conditionType kapp.AppConditionType) v1.ConditionStatus

func GetAppConfigIDFromDeployItem

func GetAppConfigIDFromDeployItem(deployItem *v1alpha1.DeployItem) string

func GetApprepoNamespace

func GetApprepoNamespace() string

func GetClusterBomCondition

func GetClusterBomCondition(clusterbom *hubv1.ClusterBom, conditionType hubv1.ClusterBomConditionType) *hubv1.ClusterBomCondition

func GetClusterBomConditionFromStatus

func GetClusterBomConditionFromStatus(clusterbomStatus *hubv1.ClusterBomStatus, conditionType hubv1.ClusterBomConditionType) *hubv1.ClusterBomCondition

func GetClusterBomKeyFromClusterBomOrDeployItem

func GetClusterBomKeyFromClusterBomOrDeployItem(clusterBom *hubv1.ClusterBom, deployItem *v1alpha1.DeployItem) *types.NamespacedName

func GetClusterBomKeyFromDeployItem

func GetClusterBomKeyFromDeployItem(deployItem *v1alpha1.DeployItem) *types.NamespacedName

func GetClusterBomKeyFromDeployItemKey

func GetClusterBomKeyFromDeployItemKey(deployItemKey *types.NamespacedName) *types.NamespacedName

func GetDeployItemCondition

func GetDeployItemCondition(deployItem *v1alpha1.DeployItem, conditionType hubv1.HubDeploymentConditionType) *v1alpha1.Condition

func GetDeployItemConditionStatus

func GetDeployItemConditionStatus(c *v1alpha1.Condition) v1.ConditionStatus

func GetEnvBool

func GetEnvBool(name string, defaultValue bool, logger logr.Logger) bool

func GetEnvInteger

func GetEnvInteger(name string, defaultValue int, logger logr.Logger) int

func GetFieldsByJSONPath

func GetFieldsByJSONPath(obj map[string]interface{}, fieldPath string) ([][]reflect.Value, error)

func GetGCloudAccessToken

func GetGCloudAccessToken(gcloudServiceAccountJSON string) (string, error)

GetGCloudAccessToken returns an access token from a google service account json string. Returns the access token or error.

func GetKey

func GetKey(obj metav1.Object) *types.NamespacedName

func GetLabel

func GetLabel(obj v1.Object, key string) (string, bool)

func GetLoggerFromContext

func GetLoggerFromContext(ctx context.Context) logr.Logger

func GetPodNamespace

func GetPodNamespace() string

func GetSecretKeyFromClusterBom

func GetSecretKeyFromClusterBom(clusterBom *hubv1.ClusterBom) *types.NamespacedName

func HasAnnotation

func HasAnnotation(obj v1.Object, key, value string) bool

func HasFinalizer

func HasFinalizer(obj v1.Object, finalizer string) bool

func HasLabel

func HasLabel(obj v1.Object, key, value string) bool

func Hash256

func Hash256(phrase string) ([]byte, error)

Hash256 computes the SHA256 hash of the given string. The resulting []byte has length 32.

func HashObject256

func HashObject256(obj interface{}) (string, error)

func IsConcurrentModificationErr

func IsConcurrentModificationErr(err error) bool

func IsEqualClusterBomCondition

func IsEqualClusterBomCondition(c, d *hubv1.ClusterBomCondition) bool

func IsEqualClusterBomConditionList

func IsEqualClusterBomConditionList(oldConditions, newConditions []hubv1.ClusterBomCondition) bool

func IsEqualHdcConditionList

func IsEqualHdcConditionList(oldConditions, newConditions []hubv1.HubDeploymentCondition) bool

func IsStatusErrorConflict

func IsStatusErrorConflict(err error) bool

func IsStatusErrorWithCode

func IsStatusErrorWithCode(err error, code int32) bool

func MapToHdcCondition

func MapToHdcCondition(conditions []v1alpha1.Condition) []hubv1.HubDeploymentCondition

func NewContextAndLogger

func NewContextAndLogger(logger logr.Logger, keysAndValues ...interface{}) (context.Context, logr.Logger)

func ParseSuccessValues

func ParseSuccessValues(successValues []runtime.RawExtension) ([]interface{}, error)

func RemoveAnnotation

func RemoveAnnotation(obj v1.Object, key string)

func RemoveFinalizer

func RemoveFinalizer(obj v1.Object, finalizer string)

func RemoveLabel

func RemoveLabel(obj v1.Object, key string)

func Repeat

func Repeat(f func() bool, repetitions int, pause time.Duration) bool

func WithBasicAuth

func WithBasicAuth(handler http.HandlerFunc, username, password string) http.HandlerFunc

func WorseConditionStatus

func WorseConditionStatus(status1, status2 v1.ConditionStatus) v1.ConditionStatus

Types

type AuditLogKey

type AuditLogKey struct{}

type CRAndSecretClientKey

type CRAndSecretClientKey struct{}

type Clock

type Clock interface {
	Now() time.Time
}

type LoggerKey

type LoggerKey struct{}

type RealClock

type RealClock struct{}

func (*RealClock) Now

func (c *RealClock) Now() time.Time

type ThreadCounterMap

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

func NewThreadCounterMap

func NewThreadCounterMap(l logr.Logger) *ThreadCounterMap

func (*ThreadCounterMap) IncreaseEntryAndLog

func (r *ThreadCounterMap) IncreaseEntryAndLog(s string)

func (*ThreadCounterMap) ReduceEntry

func (r *ThreadCounterMap) ReduceEntry(s string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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