common

package
v0.0.0-...-b4e7bf2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0, MIT Imports: 57 Imported by: 17

Documentation

Index

Constants

View Source
const (
	// ReconciliationSucceededReason represents the fact that the reconciliation of
	// the resource has succeeded.
	ReconciliationSuccessReason string = "Success"

	// ReconciliationSuccessReason represents the fact that the reconciliation of
	// the resource has succeeded and is ready. Expectation is that the resource
	// checks itself for readiness before attaching this condition.
	ConditionTypeReady string = "Ready"

	// comes into play to catch something that is taking too long to become Ready
	// ReconciliationFailedReason represents the fact that the reconciliation of
	// the resource has failed.
	ReconciliationFailedReason string = "Reconciling"
)
View Source
const (
	Period1m  = "1m"  // 1 minute
	Period5m  = "5m"  // 5 minutes
	Period15m = "15m" // 15 minutes
	Period30m = "30m" // 30 minutes
	Period1h  = "1h"  // 1 hour
	Period4h  = "4h"  // 4 hours
	Period12h = "12h" // 12 hours
	Period24h = "24h" // 24 hours
	Period7d  = "7d"  // 7 days
	Period14d = "14d" // 14 days
	Period30d = "30d" // 30 days
)
View Source
const (
	ConditionStatusSuccess = "True"
)

Variables

This section is empty.

Functions

func ClickHouseCloudPassword

func ClickHouseCloudPassword(s int) string

ClickHouseCloudPassword generates ClickHouse Cloud specific password which requires special characters. We already use secure random generated string which is then appended by special chars.

func GetEnv

func GetEnv(key, fallback string) string

func InferTimelines

func InferTimelines(refTime time.Time, statsPeriod string) (int64, int64, int64, string)

func IsIngressReady

func IsIngressReady(ingress *netv1.Ingress) bool

func LookupEnvOrBool

func LookupEnvOrBool(key string, defaultVal bool) bool

func LookupEnvOrString

func LookupEnvOrString(key string, defaultVal string) string

func MergeMap

func MergeMap(base map[string]string, overrides map[string]string) map[string]string

func MustParse

func MustParse(in string) *url.URL

MustParse parses a URL and panics if error occurs.

func NewCustomJobStatusReader

func NewCustomJobStatusReader(mapper meta.RESTMapper) engine.StatusReader

func ParseFeatureAsBool

func ParseFeatureAsBool(features map[string]string, k string) (bool, error)

func ParseYaml

func ParseYaml(yamlString string) ([]client.Object, error)

Parses a file with multiple yaml declarations and decodes the declarations into kubernetes client.Objects.

func PatchBytes

func PatchBytes(defaults, overrides []byte) ([]byte, error)

patch the default spec (as defined in code) with the overrides (as provided by an SRE).

func PatchObject

func PatchObject(base, overrides interface{}) error

func Ptr

func Ptr[T any](v T) *T

func RBACObjectMutator

func RBACObjectMutator(current, desired client.Object) error

func RandStringASCIIBytes

func RandStringASCIIBytes(n int) (string, error)

func RandStringRunes

func RandStringRunes(s int) string

func RandStringRunesRaw

func RandStringRunesRaw(s int) string

func ReadyHandler

func ReadyHandler(isReady *atomic.Bool) http.HandlerFunc

func RenderTemplate

func RenderTemplate(t *template.Template, tmpl string, values map[string]interface{}) (string, error)

Helper to render a go template.

func RouteMetricsOtel

func RouteMetricsOtel(m metric.Meter) gin.HandlerFunc

Use set gin metrics middleware.

func RouteMetricsPrometheus

func RouteMetricsPrometheus(registry prometheus.Registerer) gin.HandlerFunc

Use set gin metrics middleware.

func ServeWithGracefulShutdown

func ServeWithGracefulShutdown(
	ctx context.Context,
	logger simpleLogger,
	srvs ...*http.Server,
) error

func SeverityTextToNumber

func SeverityTextToNumber(severityText string) plog.SeverityNumber

func ValidateServiceName

func ValidateServiceName(string string) bool

Types

type Action

type Action interface {
	Run(runner ActionRunner) (string, ActionOperation, error)
}

type ActionOperation

type ActionOperation string
const (
	OperationCreated ActionOperation = "(created)"
	OperationUpdated ActionOperation = "(updated)"
	OperationDeleted ActionOperation = "(deleted)"
	OperationNoop    ActionOperation = "(unchanged)"
	OperationLog     ActionOperation = "(log)"
)

type ActionRunner

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

func NewActionRunner

func NewActionRunner(
	ctx context.Context,
	client client.Client,
	scheme *k8s_runtime.Scheme,
	cr client.Object,
	resourceManager *ssa.ResourceManager,
	t trace.Tracer,
) ActionRunner

func (*ActionRunner) RunAll

func (i *ActionRunner) RunAll(ctx context.Context, desiredState DesiredState) error

type CheckGoneAction

type CheckGoneAction struct {
	Ref client.Object
	Msg string
}

func (CheckGoneAction) Run

type ClickHouseAction

type ClickHouseAction struct {
	URL                   url.URL
	SQL                   string
	Msg                   string
	Database              string
	ForgetErrorIfContains string
}

func (ClickHouseAction) Run

type ClickHouseCloudMigrationAction

type ClickHouseCloudMigrationAction struct {
	Msg                     string
	ClickHouseDSN           string
	GoMigrationsToRun       []*goose.Migration
	MigrationsToRun         fs.FS
	SetLastMigrationApplied func(string)
}

func (ClickHouseCloudMigrationAction) Run

type ClickHouseMigrationAction

type ClickHouseMigrationAction struct {
	Msg                     string
	ClickHouseDSN           string
	MigrationsToRun         fs.FS
	GoMigrationsToRun       []*goose.Migration
	SetLastMigrationApplied func(string)
}

func (ClickHouseMigrationAction) Run

type DNSLookupFailAction

type DNSLookupFailAction struct {
	DNSName string
	Msg     string
}

func (DNSLookupFailAction) Run

type DeploymentReadyAction

type DeploymentReadyAction struct {
	Ref client.Object
	Msg string
}

func (DeploymentReadyAction) Run

Note(Arun): I'm not sure what would be best to statisfy unparam linter

type DesiredState

type DesiredState []Action

The desired state is defined by a list of actions that have to be run to get from the current state to the desired state.

func (*DesiredState) AddAction

func (d *DesiredState) AddAction(action Action) DesiredState

func (*DesiredState) AddActions

func (d *DesiredState) AddActions(actions []Action) DesiredState

type EnvironmentTarget

type EnvironmentTarget string
var (
	AWS   EnvironmentTarget = "aws"
	GCP   EnvironmentTarget = "gcp"
	KIND  EnvironmentTarget = "kind"
	DEVVM EnvironmentTarget = "devvm"
)

Supported platform targets.

type GenericCreateAction

type GenericCreateAction struct {
	Ref client.Object
	Msg string
}

An action to create generic kubernetes resources.

func (GenericCreateAction) Run

type GenericCreateOrUpdateAction

type GenericCreateOrUpdateAction struct {
	Ref          client.Object
	Msg          string
	Mutator      controllerutil.MutateFn
	SkipOwnerRef bool
}

An action to create generic kubernetes resources (resources that don't require special treatment).

func (GenericCreateOrUpdateAction) Run

type GenericDeleteAction

type GenericDeleteAction struct {
	Ref client.Object
	Msg string
}

An action to delete generic kubernetes resources (resources that don't require special treatment).

func (GenericDeleteAction) Run

type GenericUpdateAction

type GenericUpdateAction struct {
	Ref client.Object
	Msg string
}

An action to update generic kubernetes resources.

func (GenericUpdateAction) Run

type GetInventoryFunc

type GetInventoryFunc func() *v1beta2.ResourceInventory

We use closures, as Actions are type-agnostic and the cr object that is accessible in the runner is of type Object. TODO(prozlach): Is there a better way to approach this?

type GracefulServer

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

func NewGracefulServer

func NewGracefulServer(
	logger *zap.Logger,
	servers []*http.Server,
	wait int,
) *GracefulServer

func (*GracefulServer) Start

func (g *GracefulServer) Start()

func (*GracefulServer) Stop

func (g *GracefulServer) Stop()

type IngressReadyAction

type IngressReadyAction struct {
	Ref client.Object
	Msg string
}

func (IngressReadyAction) Run

type LogAction

type LogAction struct {
	Msg string
	// if error is set, the runner will immediately stop at this action and
	// enqueue another reconciliation
	Error error
}

Log a message and optionally an error. If an error is present, the runner will immediately stop at this action and enqueue another reconciliation.

func (LogAction) Run

type ManifestsEnsureAction

type ManifestsEnsureAction struct {
	HealthcheckTimeout time.Duration
	ComponentName      string
	Manifests          []*unstructured.Unstructured
	GetInventory       GetInventoryFunc
	SetInventory       SetInventoryFunc
	Msg                string
	Log                logr.Logger
}

func (ManifestsEnsureAction) Run

type ManifestsPruneAction

type ManifestsPruneAction struct {
	ComponentName string
	GetInventory  GetInventoryFunc
	Msg           string
	Log           logr.Logger
}

func (ManifestsPruneAction) Run

type SetInventoryFunc

type SetInventoryFunc func(*v1beta2.ResourceInventory)

type StatefulSetReadyAction

type StatefulSetReadyAction struct {
	Ref client.Object
	Msg string
}

func (StatefulSetReadyAction) Run

Jump to

Keyboard shortcuts

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