v2

package
v0.0.0-...-d6154db 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 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperatorName              = "module-manager"
	ManagedByLabelValue       = "declarative-v2"
	DisclaimerAnnotation      = shared.OperatorGroup + shared.Separator + "managed-by-reconciler-disclaimer"
	DisclaimerAnnotationValue = "DO NOT EDIT - This resource is managed by Kyma.\n" +
		"Any modifications are discarded and the resource is reverted to the original state."
	OwnedByFormat = "%s/%s"
)
View Source
const (
	FinalizerDefault        = "declarative.kyma-project.io/finalizer"
	FieldOwnerDefault       = "declarative.kyma-project.io/applier"
	EventRecorderDefault    = "declarative.kyma-project.io/events"
	DefaultInMemoryParseTTL = 24 * time.Hour
)
View Source
const (
	CustomResourceManager  = "resource.kyma-project.io/finalizer"
	SyncedOCIRefAnnotation = "sync-oci-ref"
)
View Source
const (
	ManifestFilePrefix = "manifest"
)

Variables

View Source
var (
	ErrWarningResourceSyncStateDiff   = errors.New("resource syncTarget state diff detected")
	ErrResourceSyncDiffInSameOCILayer = errors.New("resource syncTarget diff detected but in " +
		"same oci layer, prevent sync resource to be deleted")
	ErrInstallationConditionRequiresUpdate = errors.New("installation condition needs an update")
	ErrObjectHasEmptyState                 = errors.New("object has an empty state")
	ErrRequeueRequired                     = errors.New("requeue required")
	ErrAccessSecretNotFound                = errors.New("access secret not found")
)
View Source
var (
	ErrClientObjectConversionFailed = errors.New("client object conversion failed")
	ErrServerSideApplyFailed        = errors.New("ServerSideApply failed")
	ErrClientUnauthorized           = errors.New("ServerSideApply is unauthorized")
)
View Source
var ErrNotValidClientObject = errors.New("object in resource info is not a valid client object")

Functions

func DisclaimerTransform

func DisclaimerTransform(_ context.Context, _ Object, resources []*unstructured.Unstructured) error

func KymaComponentTransform

func KymaComponentTransform(_ context.Context, obj Object, resources []*unstructured.Unstructured) error

func ManagedByDeclarativeV2

func ManagedByDeclarativeV2(_ context.Context, _ Object, resources []*unstructured.Unstructured) error

func NewClientProxy

func NewClientProxy(config *rest.Config, mapper meta.RESTMapper) (client.Client, error)

NewClientProxy returns a new instance of ProxyClient.

func SkipReconcileOnDefaultLabelPresentAndTrue

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

SkipReconcileOnDefaultLabelPresentAndTrue determines SkipReconcile by checking if DefaultSkipReconcileLabel is true.

Types

type ClientCache

type ClientCache interface {
	GetClient(key string) Client
	AddClient(key string, client Client)
	DeleteClient(key string)
}

type ClientCacheKeyFn

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

type ClusterFn

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

type ClusterInfo

type ClusterInfo struct {
	Config *rest.Config
	Client client.Client
}

ClusterInfo describes client and config for a cluster.

func (ClusterInfo) IsEmpty

func (r ClusterInfo) IsEmpty() bool

IsEmpty indicates if ClusterInfo is empty.

type ConcurrentDefaultSSA

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

func ConcurrentSSA

func ConcurrentSSA(clnt client.Client, owner client.FieldOwner) *ConcurrentDefaultSSA

func (*ConcurrentDefaultSSA) Run

func (c *ConcurrentDefaultSSA) Run(ctx context.Context, resources []*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 CustomSpecFns

type CustomSpecFns struct {
	ManifestNameFn func(ctx context.Context, obj Object) string
	PathFn         func(ctx context.Context, obj Object) string
	OCIRefFn       func(ctx context.Context, obj Object) string
	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, ociref string, mode RenderMode) *CustomSpecFns

func (*CustomSpecFns) Spec

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

type DefaultDeletionCheck

type DefaultDeletionCheck struct{}

func NewDefaultDeletionCheck

func NewDefaultDeletionCheck() *DefaultDeletionCheck

NewDefaultDeletionCheck creates a check that verifies that the Resource CR in the remote cluster is deleted.

func (*DefaultDeletionCheck) Run

func (c *DefaultDeletionCheck) Run(ctx context.Context, clnt client.Client, obj Object) (bool, error)

type DefaultInfoToResourceConverter

type DefaultInfoToResourceConverter struct{}

func NewInfoToResourceConverter

func NewInfoToResourceConverter() *DefaultInfoToResourceConverter

func (*DefaultInfoToResourceConverter) InfosToResources

func (c *DefaultInfoToResourceConverter) InfosToResources(infos []*resource.Info) []shared.Resource

type DefaultResourceToInfoConverter

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

func NewResourceToInfoConverter

func NewResourceToInfoConverter(
	converter ResourceInfoConverter, defaultNamespace string,
) *DefaultResourceToInfoConverter

func (*DefaultResourceToInfoConverter) ResourcesToInfos

func (c *DefaultResourceToInfoConverter) ResourcesToInfos(resources []shared.Resource) ([]*resource.Info, error)

func (*DefaultResourceToInfoConverter) UnstructuredToInfos

func (c *DefaultResourceToInfoConverter) UnstructuredToInfos(
	resources []*unstructured.Unstructured,
) ([]*resource.Info, error)

type ExistsReadyCheck

type ExistsReadyCheck struct{}

func NewExistsReadyCheck

func NewExistsReadyCheck() *ExistsReadyCheck

func (*ExistsReadyCheck) Run

func (c *ExistsReadyCheck) Run(
	ctx context.Context,
	clnt Client,
	_ Object,
	resources []*resource.Info,
) (StateInfo, 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, internal.ManifestResources]
}

func NewInMemoryCachedManifestParser

func NewInMemoryCachedManifestParser(ttl time.Duration) *InMemoryManifestCache

func (*InMemoryManifestCache) EvictCache

func (c *InMemoryManifestCache) EvictCache(spec *Spec)

func (*InMemoryManifestCache) Parse

type InfoToResourceConverter

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

type ManifestCache

type ManifestCache string

type ManifestParser

type ManifestParser interface {
	Parse(spec *Spec) (internal.ManifestResources, error)
	EvictCache(spec *Spec)
}

type MemoryClientCache

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

func NewMemoryClientCache

func NewMemoryClientCache() *MemoryClientCache

func (*MemoryClientCache) AddClient

func (m *MemoryClientCache) AddClient(key string, value Client)

func (*MemoryClientCache) DeleteClient

func (m *MemoryClientCache) DeleteClient(key string)

func (*MemoryClientCache) GetClient

func (m *MemoryClientCache) GetClient(key string) Client

func (*MemoryClientCache) Size

func (m *MemoryClientCache) Size() int

type ModuleCRDeletionCheck

type ModuleCRDeletionCheck interface {
	Run(ctx context.Context, clnt client.Client, obj Object) (bool, error)
}

type Object

type Object interface {
	client.Object
	GetStatus() shared.Status
	SetStatus(status shared.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

	DeletionCheck ModuleCRDeletionCheck

	DeletePrerequisites bool

	ShouldSkip SkipReconcile
}

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 ProxyClient

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

ProxyClient holds information required to proxy Client requests to verify RESTMapper integrity. During the proxy, the underlying mapper verifies mapping for the calling resource. If not available and NoMatchesKind error occurs, the mappings are reset (if type meta.ResettableRESTMapper). After reset a follow-up call verifies if mappings are now available.

func (*ProxyClient) Create

func (p *ProxyClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create implements client.Client.

func (*ProxyClient) Delete

func (p *ProxyClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete implements client.Client.

func (*ProxyClient) DeleteAllOf

func (p *ProxyClient) DeleteAllOf(
	ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption,
) error

DeleteAllOf implements client.Client.

func (*ProxyClient) Get

func (p *ProxyClient) Get(ctx context.Context,
	key client.ObjectKey,
	obj client.Object,
	opts ...client.GetOption,
) error

Get implements client.Client.

func (*ProxyClient) GroupVersionKindFor

func (p *ProxyClient) GroupVersionKindFor(obj machineryruntime.Object) (schema.GroupVersionKind, error)

func (*ProxyClient) IsObjectNamespaced

func (p *ProxyClient) IsObjectNamespaced(obj machineryruntime.Object) (bool, error)

func (*ProxyClient) List

func (p *ProxyClient) List(ctx context.Context, obj client.ObjectList, opts ...client.ListOption) error

List implements client.Client.

func (*ProxyClient) Patch

func (p *ProxyClient) Patch(
	ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption,
) error

Patch implements client.Client.

func (*ProxyClient) RESTMapper

func (p *ProxyClient) RESTMapper() meta.RESTMapper

RESTMapper returns the rest mapper this client is using.

func (*ProxyClient) Scheme

func (p *ProxyClient) Scheme() *machineryruntime.Scheme

Scheme returns the scheme this client is using.

func (*ProxyClient) Status

func (p *ProxyClient) Status() client.StatusWriter

Status implements client.StatusClient.

func (*ProxyClient) SubResource

func (p *ProxyClient) SubResource(subResource string) client.SubResourceClient

func (*ProxyClient) Update

func (p *ProxyClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update implements client.Client.

type ReadyCheck

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

type Reconciler

type Reconciler struct {
	queue.RequeueIntervals
	*Options
	ManifestMetrics        *metrics.ManifestMetrics
	MandatoryModuleMetrics *metrics.MandatoryModulesMetrics
	// contains filtered or unexported fields
}

func NewFromManager

func NewFromManager(mgr manager.Manager, prototype Object, requeueIntervals queue.RequeueIntervals,
	metrics *metrics.ManifestMetrics, mandatoryModulesMetrics *metrics.MandatoryModulesMetrics, 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 (
	RenderModeRaw RenderMode = "raw"
)

type ResourceInfoConverter

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

type ResourceList

type ResourceList []*resource.Info

ResourceList provides convenience methods for comparing collections of Infos. Copy from helm.sh/helm/v3/pkg/kube.

func (*ResourceList) Append

func (r *ResourceList) Append(val *resource.Info)

Append adds an Info to the Result.

func (ResourceList) Contains

func (r ResourceList) Contains(info *resource.Info) bool

Contains checks to see if an object exists.

func (ResourceList) Difference

func (r ResourceList) Difference(rs ResourceList) ResourceList

Difference will return a new Result with objects not contained in rs.

func (ResourceList) Filter

func (r ResourceList) Filter(fn func(*resource.Info) bool) ResourceList

Filter returns a new Result with Infos that satisfy the predicate fn.

func (ResourceList) Get

func (r ResourceList) Get(info *resource.Info) *resource.Info

Get returns the Info from the result that matches the name and kind.

func (ResourceList) Intersect

func (r ResourceList) Intersect(rs ResourceList) ResourceList

Intersect will return a new Result with objects contained in both Results.

func (ResourceList) Visit

func (r ResourceList) Visit(fn resource.VisitorFunc) error

Visit implements resource.Visitor.

type ResourceToInfoConverter

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

type SSA

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

type SingletonClients

type SingletonClients struct {

	// controller runtime client
	client.Client
	// contains filtered or unexported fields
}

SingletonClients serves as a single-minded client interface that combines all kubernetes Client APIs (Kubernetes, Client-Go) under the hood. It offers a simple initialization lifecycle during creation, but delegates all heavy-duty work to deferred discovery logic and a single http client as well as a client cache to support GV-based clients.

func NewSingletonClients

func NewSingletonClients(info *ClusterInfo) (*SingletonClients, error)

func (*SingletonClients) ClientForMapping

func (s *SingletonClients) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)

ClientForMapping returns a RESTClient for working with the specified RESTMapping or an error. This is intended for working with arbitrary resources and is not guaranteed to point to a Kubernetes APIServer.

func (*SingletonClients) OpenAPIGetter

func (s *SingletonClients) OpenAPIGetter() *openapi.CachedOpenAPIGetter

OpenAPIGetter returns a getter for the openapi schema document.

func (*SingletonClients) OpenAPISchema

func (s *SingletonClients) OpenAPISchema() (openapi.Resources, error)

OpenAPISchema returns metadata and structural information about Kubernetes object definitions.

func (*SingletonClients) ResourceInfo

func (s *SingletonClients) ResourceInfo(obj *unstructured.Unstructured, retryOnNoMatch bool) (*resource.Info, error)

func (*SingletonClients) ToDiscoveryClient

func (s *SingletonClients) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*SingletonClients) ToRESTConfig

func (s *SingletonClients) ToRESTConfig() (*rest.Config, error)

func (*SingletonClients) ToRESTMapper

func (s *SingletonClients) ToRESTMapper() (meta.RESTMapper, error)

func (*SingletonClients) ToRawKubeConfigLoader

func (s *SingletonClients) ToRawKubeConfigLoader() clientcmd.ClientConfig

func (*SingletonClients) UnstructuredClientForMapping

func (s *SingletonClients) UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)

UnstructuredClientForMapping returns a RESTClient for working with Unstructured objects.

type SkipReconcile

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

type Spec

type Spec struct {
	ManifestName string
	Path         string
	OCIRef       string
	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 StateInfo

type StateInfo struct {
	shared.State
	Info string
}

type WithClientCacheKeyOption

type WithClientCacheKeyOption struct {
	ClientCacheKeyFn
}

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 k8slabels.Set

func (WithCustomResourceLabels) Apply

func (o WithCustomResourceLabels) 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 WithModuleCRDeletionCheckOption

type WithModuleCRDeletionCheckOption struct {
	ModuleCRDeletionCheck
}

func WithModuleCRDeletionCheck

func WithModuleCRDeletionCheck(deletionCheckFn ModuleCRDeletionCheck) WithModuleCRDeletionCheckOption

func (WithModuleCRDeletionCheckOption) Apply

func (o WithModuleCRDeletionCheckOption) 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 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
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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