v2

package
v0.0.0-...-b82b62a Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DisclaimerAnnotation = "reconciler.kyma-project.io/managed-by-reconciler-disclaimer"

	ManagedByLabel = "reconciler.kyma-project.io/managed-by"
)
View Source
const (
	ConditionTypeHelmCRDs               ConditionType   = "HelmCRDs"
	ConditionReasonHelmCRDsAreAvailable ConditionReason = "HelmCRDsAvailable"
)
View Source
const (
	FinalizerDefault          = "declarative.kyma-project.io/finalizer"
	FieldOwnerDefault         = "declarative.kyma-project.io/applier"
	EventRecorderDefault      = "declarative.kyma-project.io/events"
	DefaultSkipReconcileLabel = "declarative.kyma-project.io/skip-reconciliation"
	DefaultCacheKey           = "declarative.kyma-project.io/cache-key"
	DefaultInMemoryParseTTL   = 24 * time.Hour
)

Variables

View Source
var (
	ErrResourceSyncStateDiff                     = errors.New("resource syncTarget state diff detected")
	ErrInstallationConditionRequiresUpdate       = errors.New("installation condition needs an update")
	ErrDeletionTimestampSetButNotInDeletingState = errors.New("resource is not set to deleting yet")
	ErrObjectHasEmptyState                       = errors.New("object has an empty state")
)
View Source
var (
	ErrConditionsNotYetRegistered = errors.New("conditions have not yet been registered in status")
	ErrPrerequisitesNotFulfilled  = errors.New("prerequisites for installation are not fulfilled")
)
View Source
var ErrDeletionNotFinished = errors.New("deletion is not yet finished")
View Source
var ErrResourcesNotReady = errors.New("resources are not ready")

Functions

func SkipReconcileOnDefaultLabelPresentAndTrue

func SkipReconcileOnDefaultLabelPresentAndTrue(ctx context.Context, object Object) bool

SkipReconcileOnDefaultLabelPresentAndTrue determines SkipReconcile by checking if DefaultSkipReconcileLabel is true.

Types

type Cleanup

type Cleanup interface {
	Run(context.Context, []*resource.Info) error
}

func NewConcurrentCleanup

func NewConcurrentCleanup(clnt client.Client) Cleanup

type Client

type Client interface {
	kube.Factory
	Install() *action.Install
	KubeClient() *kube.Client

	resource.RESTClientGetter
	ResourceInfoConverter

	client.Client
}

type ClientCache

type ClientCache interface {
	GetClientFromCache(key any) Client
	SetClientInCache(key any, client Client)
}

type ClientCacheKeyFn

type ClientCacheKeyFn func(ctx context.Context, obj Object) any

type ClusterFn

type ClusterFn func(context.Context, Object) (*types.ClusterInfo, error)

type ConcurrentCleanup

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

func (*ConcurrentCleanup) Run

func (c *ConcurrentCleanup) Run(ctx context.Context, infos []*resource.Info) error

type ConditionReason

type ConditionReason string
const (
	ConditionReasonResourcesAreAvailable ConditionReason = "ResourcesAvailable"
	ConditionReasonReady                 ConditionReason = "Ready"
)

type ConditionType

type ConditionType string
const (
	ConditionTypeResources    ConditionType = "Resources"
	ConditionTypeInstallation ConditionType = "Installation"
)

type ConditionsNeedUpdate

type ConditionsNeedUpdate bool

type CustomSpecFns

type CustomSpecFns struct {
	ManifestNameFn func(ctx context.Context, obj Object) string
	PathFn         func(ctx context.Context, obj Object) string
	ValuesFn       func(ctx context.Context, obj Object) any
	ModeFn         func(ctx context.Context, obj Object) RenderMode
}

CustomSpecFns is a simple static resolver that always uses the same chart and values.

func DefaultSpec

func DefaultSpec(path string, values any, mode RenderMode) *CustomSpecFns

func (*CustomSpecFns) Spec

func (s *CustomSpecFns) Spec(
	ctx context.Context, obj Object,
) (*Spec, error)

type ExistsReadyCheck

type ExistsReadyCheck struct{}

func (*ExistsReadyCheck) Run

func (c *ExistsReadyCheck) Run(ctx context.Context, clnt Client, _ Object, resources []*resource.Info) error

type Helm

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

func (*Helm) EnsurePrerequisites

func (h *Helm) EnsurePrerequisites(ctx context.Context, obj Object) error

func (*Helm) Initialize

func (h *Helm) Initialize(obj Object) error

func (*Helm) RemovePrerequisites

func (h *Helm) RemovePrerequisites(ctx context.Context, obj Object) error

func (*Helm) Render

func (h *Helm) Render(ctx context.Context, obj Object) ([]byte, error)

type HelmReadyCheck

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

func (*HelmReadyCheck) Run

func (c *HelmReadyCheck) Run(ctx context.Context, _ Client, _ Object, resources []*resource.Info) error

type Hook

type Hook func(ctx context.Context, skr Client, kcp client.Client, obj Object) error

Hook defines a Hook into the declarative reconciliation skr is the runtime cluster kcp is the control-plane cluster obj is guaranteed to be the reconciled object and also to always preside in kcp.

type InMemoryManifestCache

type InMemoryManifestCache struct {
	TTL time.Duration
	*ttlcache.Cache[string, types.ManifestResources]
}

func NewInMemoryCachedManifestParser

func NewInMemoryCachedManifestParser(ttl time.Duration) *InMemoryManifestCache

func (*InMemoryManifestCache) Parse

func (c *InMemoryManifestCache) Parse(
	ctx context.Context, renderer Renderer, obj Object, spec *Spec,
) (*types.ManifestResources, error)

type InfoToResourceConverter

type InfoToResourceConverter interface {
	InfosToResources([]*resource.Info) []Resource
}

func NewInfoToResourceConverter

func NewInfoToResourceConverter() InfoToResourceConverter

type Kustomize

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

func (*Kustomize) EnsurePrerequisites

func (k *Kustomize) EnsurePrerequisites(_ context.Context, _ Object) error

func (*Kustomize) Initialize

func (k *Kustomize) Initialize(_ Object) error

func (*Kustomize) RemovePrerequisites

func (k *Kustomize) RemovePrerequisites(_ context.Context, _ Object) error

func (*Kustomize) Render

func (k *Kustomize) Render(_ context.Context, obj Object) ([]byte, error)

type LastOperation

type LastOperation struct {
	Operation      string      `json:"operation"`
	LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
}

LastOperation defines the last operation from the control-loop. +k8s:deepcopy-gen=true

func (*LastOperation) DeepCopy

func (in *LastOperation) DeepCopy() *LastOperation

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LastOperation.

func (*LastOperation) DeepCopyInto

func (in *LastOperation) DeepCopyInto(out *LastOperation)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type ManifestCache

type ManifestCache string
const NoManifestCache ManifestCache = "no-cache"

type ManifestParser

type ManifestParser interface {
	Parse(ctx context.Context, renderer Renderer, obj Object, spec *Spec) (*types.ManifestResources, error)
}

type MemoryClientCache

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

func NewMemorySingletonClientCache

func NewMemorySingletonClientCache() *MemoryClientCache

NewMemorySingletonClientCache returns a new instance of MemoryClientCache.

func (*MemoryClientCache) GetClientFromCache

func (r *MemoryClientCache) GetClientFromCache(key any) Client

func (*MemoryClientCache) SetClientInCache

func (r *MemoryClientCache) SetClientInCache(key any, client Client)

type Object

type Object interface {
	client.Object
	ComponentName() string
	GetStatus() Status
	SetStatus(Status)
}

type ObjectTransform

type ObjectTransform = func(context.Context, Object, []*unstructured.Unstructured) error

type Option

type Option interface {
	Apply(options *Options)
}

type Options

type Options struct {
	record.EventRecorder
	Config *rest.Config
	client.Client
	TargetCluster ClusterFn

	SpecResolver
	ClientCache
	ClientCacheKeyFn
	ManifestParser
	ManifestCache
	CustomReadyCheck ReadyCheck

	Namespace       string
	CreateNamespace bool

	Finalizer string

	ServerSideApply bool
	FieldOwner      client.FieldOwner

	PostRenderTransforms []ObjectTransform

	PostRuns   []PostRun
	PreDeletes []PreDelete

	DeletePrerequisites bool

	ShouldSkip SkipReconcile

	CtrlOnSuccess ctrl.Result
}

func DefaultOptions

func DefaultOptions() *Options

func (*Options) Apply

func (o *Options) Apply(options ...Option) *Options

type PostRenderTransformOption

type PostRenderTransformOption struct {
	ObjectTransforms []ObjectTransform
}

func WithPostRenderTransform

func WithPostRenderTransform(transforms ...ObjectTransform) PostRenderTransformOption

func (PostRenderTransformOption) Apply

func (o PostRenderTransformOption) Apply(options *Options)

type PostRun

type PostRun Hook

PostRun is executed after every successful render+reconciliation of the manifest.

type PreDelete

type PreDelete Hook

PreDelete is executed before any deletion of resources calculated from the status.

type Prerequisites

type Prerequisites []*resource.Info

type RawRenderer

type RawRenderer struct {
	record.EventRecorder
	Path string
}

func (*RawRenderer) EnsurePrerequisites

func (r *RawRenderer) EnsurePrerequisites(_ context.Context, _ Object) error

func (*RawRenderer) Initialize

func (r *RawRenderer) Initialize(_ Object) error

func (*RawRenderer) RemovePrerequisites

func (r *RawRenderer) RemovePrerequisites(_ context.Context, _ Object) error

func (*RawRenderer) Render

func (r *RawRenderer) Render(_ context.Context, obj Object) ([]byte, error)

type ReadyCheck

type ReadyCheck interface {
	Run(ctx context.Context, clnt Client, obj Object, resources []*resource.Info) error
}

func NewExistsReadyCheck

func NewExistsReadyCheck() ReadyCheck

func NewHelmReadyCheck

func NewHelmReadyCheck(factory kube.Factory) ReadyCheck

type Reconciler

type Reconciler struct {
	*Options
	// contains filtered or unexported fields
}

func NewFromManager

func NewFromManager(mgr manager.Manager, prototype Object, options ...Option) *Reconciler

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

func (*Reconciler) Spec

func (r *Reconciler) Spec(ctx context.Context, obj Object) (*Spec, error)

type RenderMode

type RenderMode string
const (
	RenderModeHelm      RenderMode = "helm"
	RenderModeKustomize RenderMode = "kustomize"
	RenderModeRaw       RenderMode = "raw"
)

type Renderer

type Renderer interface {
	Initialize(obj Object) error
	EnsurePrerequisites(ctx context.Context, obj Object) error
	Render(ctx context.Context, obj Object) ([]byte, error)
	RemovePrerequisites(ctx context.Context, obj Object) error
}

func NewHelmRenderer

func NewHelmRenderer(
	spec *Spec,
	clnt Client,
	options *Options,
) Renderer

func NewKustomizeRenderer

func NewKustomizeRenderer(
	spec *Spec,
	options *Options,
) Renderer

func NewRawRenderer

func NewRawRenderer(
	spec *Spec,
	options *Options,
) Renderer

func WrapWithRendererCache

func WrapWithRendererCache(
	renderer Renderer,
	spec *Spec,
	options *Options,
) Renderer

type RendererWithCache

type RendererWithCache struct {
	Renderer
	// contains filtered or unexported fields
}

func (RendererWithCache) Clean

func (c RendererWithCache) Clean() error

func (RendererWithCache) ReadYAML

func (c RendererWithCache) ReadYAML() *types.ParsedFile

func (*RendererWithCache) Render

func (k *RendererWithCache) Render(ctx context.Context, obj Object) ([]byte, error)

func (RendererWithCache) String

func (c RendererWithCache) String() string

type Resource

type Resource struct {
	Name                    string `json:"name"`
	Namespace               string `json:"namespace"`
	metav1.GroupVersionKind `json:",inline"`
}

func ResourcesDiff

func ResourcesDiff(resourcesA, resourcesB []Resource) []Resource

func (Resource) ID

func (r Resource) ID() string

func (Resource) ToUnstructured

func (r Resource) ToUnstructured() *unstructured.Unstructured

type ResourceInfoConverter

type ResourceInfoConverter interface {
	ResourceInfo(obj *unstructured.Unstructured, retryOnNoMatch bool) (*resource.Info, error)
}

type ResourceToInfoConverter

type ResourceToInfoConverter interface {
	ResourcesToInfos([]Resource) ([]*resource.Info, error)
	UnstructuredToInfos([]*unstructured.Unstructured) ([]*resource.Info, error)
}

func NewResourceToInfoConverter

func NewResourceToInfoConverter(converter ResourceInfoConverter, defaultNamespace string) ResourceToInfoConverter

type SSA

type SSA interface {
	Run(context.Context, []*resource.Info) error
}

func ConcurrentSSA

func ConcurrentSSA(clnt client.Client, owner client.FieldOwner) SSA

type SkipReconcile

type SkipReconcile func(context.Context, Object) (skip bool)

type Spec

type Spec struct {
	ManifestName string
	Path         string
	Values       any
	Mode         RenderMode
}

type SpecResolver

type SpecResolver interface {
	Spec(ctx context.Context, object Object) (*Spec, error)
}

type SpecResolverOption

type SpecResolverOption struct {
	SpecResolver
}

func WithSpecResolver

func WithSpecResolver(resolver SpecResolver) SpecResolverOption

func (SpecResolverOption) Apply

func (o SpecResolverOption) Apply(options *Options)

type State

type State string
const (
	// StateReady signifies CustomObject is ready and has been installed successfully.
	StateReady State = "Ready"
	// StateProcessing signifies CustomObject is reconciling and is in the process of installation.
	// Processing can also signal that the Installation previously encountered an error and is now recovering.
	StateProcessing State = "Processing"
	// StateError signifies an error for CustomObject. This signifies that the Installation
	// process encountered an error.
	// Contrary to Processing, it can be expected that this state should change on the next retry.
	StateError State = "Error"
	// StateDeleting signifies CustomObject is being deleted. This is the state that is used
	// when a deletionTimestamp was detected and Finalizers are picked up.
	StateDeleting State = "Deleting"
)

Valid States.

type Status

type Status struct {
	// State signifies current state of CustomObject.
	// Value can be one of ("Ready", "Processing", "Error", "Deleting").
	// +kubebuilder:validation:Required
	// +kubebuilder:validation:Enum=Processing;Deleting;Ready;Error
	State State `json:"state,omitempty"`

	// Conditions contain a set of conditionals to determine the State of Status.
	// If all Conditions are met, the State is expected to be in StateReady.
	// +patchMergeKey=type
	// +patchStrategy=merge
	// +listType=map
	// +listMapKey=type
	Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

	// Synced determine a list of Resources that are currently actively synced.
	// All resources that are synced are considered for orphan removal on configuration changes,
	// and it is used to determine effective differences from one state to the next.
	// +listType=atomic
	Synced        []Resource `json:"synced,omitempty"`
	LastOperation `json:"lastOperation,omitempty"`
}

Status defines the observed state of CustomObject. +k8s:deepcopy-gen=true

func (*Status) DeepCopy

func (in *Status) DeepCopy() *Status

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Status.

func (*Status) DeepCopyInto

func (in *Status) DeepCopyInto(out *Status)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (Status) WithErr

func (s Status) WithErr(err error) Status

func (Status) WithOperation

func (s Status) WithOperation(operation string) Status

func (Status) WithState

func (s Status) WithState(state State) Status

type WithClientCacheKeyOption

type WithClientCacheKeyOption struct {
	ClientCacheKeyFn
}

func WithClientCacheKeyFromLabelOrResource

func WithClientCacheKeyFromLabelOrResource(label string) WithClientCacheKeyOption

func (WithClientCacheKeyOption) Apply

func (o WithClientCacheKeyOption) Apply(options *Options)

type WithCustomReadyCheckOption

type WithCustomReadyCheckOption struct {
	ReadyCheck
}

func WithCustomReadyCheck

func WithCustomReadyCheck(check ReadyCheck) WithCustomReadyCheckOption

func (WithCustomReadyCheckOption) Apply

func (o WithCustomReadyCheckOption) Apply(options *Options)

type WithCustomResourceLabels

type WithCustomResourceLabels labels.Set

func (WithCustomResourceLabels) Apply

func (o WithCustomResourceLabels) Apply(options *Options)

type WithDeleteCRDs

type WithDeleteCRDs bool

func (WithDeleteCRDs) Apply

func (o WithDeleteCRDs) Apply(options *Options)

type WithFieldOwner

type WithFieldOwner client.FieldOwner

func (WithFieldOwner) Apply

func (o WithFieldOwner) Apply(options *Options)

type WithFinalizer

type WithFinalizer string

func (WithFinalizer) Apply

func (o WithFinalizer) Apply(options *Options)

type WithManagerOption

type WithManagerOption struct {
	manager.Manager
}

func WithManager

func WithManager(mgr manager.Manager) WithManagerOption

func (WithManagerOption) Apply

func (o WithManagerOption) Apply(options *Options)

type WithManifestCache

type WithManifestCache ManifestCache

func (WithManifestCache) Apply

func (o WithManifestCache) Apply(options *Options)

type WithManifestParserOption

type WithManifestParserOption struct {
	ManifestParser
}

func WithManifestParser

func WithManifestParser(parser ManifestParser) WithManifestParserOption

func (WithManifestParserOption) Apply

func (o WithManifestParserOption) Apply(options *Options)

type WithNamespaceOption

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

func WithNamespace

func WithNamespace(name string, createIfMissing bool) WithNamespaceOption

func (WithNamespaceOption) Apply

func (o WithNamespaceOption) Apply(options *Options)

type WithPeriodicConsistencyCheck

type WithPeriodicConsistencyCheck time.Duration

func (WithPeriodicConsistencyCheck) Apply

func (o WithPeriodicConsistencyCheck) Apply(options *Options)

type WithPermanentConsistencyCheck

type WithPermanentConsistencyCheck bool

func (WithPermanentConsistencyCheck) Apply

func (o WithPermanentConsistencyCheck) Apply(options *Options)

type WithPostRun

type WithPostRun []PostRun

WithPostRun applies PostRun.

func (WithPostRun) Apply

func (o WithPostRun) Apply(options *Options)

type WithPreDelete

type WithPreDelete []PreDelete

WithPreDelete applies PreDelete.

func (WithPreDelete) Apply

func (o WithPreDelete) Apply(options *Options)

type WithRemoteTargetClusterOption

type WithRemoteTargetClusterOption struct {
	ClusterFn
}

func WithRemoteTargetCluster

func WithRemoteTargetCluster(configFn ClusterFn) WithRemoteTargetClusterOption

func (WithRemoteTargetClusterOption) Apply

func (o WithRemoteTargetClusterOption) Apply(options *Options)

type WithSingletonClientCacheOption

type WithSingletonClientCacheOption struct {
	ClientCache
}

func WithSingletonClientCache

func WithSingletonClientCache(cache ClientCache) WithSingletonClientCacheOption

func (WithSingletonClientCacheOption) Apply

func (o WithSingletonClientCacheOption) Apply(options *Options)

type WithSkipReconcileOnOption

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

func WithSkipReconcileOn

func WithSkipReconcileOn(skipReconcile SkipReconcile) WithSkipReconcileOnOption

func (WithSkipReconcileOnOption) Apply

func (o WithSkipReconcileOnOption) Apply(options *Options)

Directories

Path Synopsis
Package mock_v2 is a generated GoMock package.
Package mock_v2 is a generated GoMock package.
test
v1
+kubebuilder:object:generate=true +groupName=test.declarative.kyma-project.io
+kubebuilder:object:generate=true +groupName=test.declarative.kyma-project.io

Jump to

Keyboard shortcuts

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