reconciler

package
v0.0.0-...-3cf8ccf Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Overview

Copyright 2022 Matrix Origin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// ConditionTypeReady Whether the object is ready to act
	ConditionTypeReady = "Ready"
	// ConditionTypeSynced Whether the object is update to date
	ConditionTypeSynced = "Synced"
)
View Source
const (
	Error        = 0
	Warn         = 1
	Info         = 2
	ExtendedInfo = 3
	Debug        = 4
	Trace        = 5
)

Variables

This section is empty.

Functions

func CreateOwnedOrUpdate

func CreateOwnedOrUpdate(kubeCli KubeClient, obj client.Object, mutateFn func() error) error

func GetCondition

func GetCondition(c Conditional, conditionType ConditionType) (*metav1.Condition, bool)

func IsReady

func IsReady(c Conditional) bool

func IsSynced

func IsSynced(c Conditional) bool

func Setup

func Setup[T client.Object](tpl T, name string, mgr ctrl.Manager, actor Actor[T], applyOpts ...ApplyOption) error

Setup register a kubernetes reconciler to the resource kind defined by T. Name is the name of the reconciler, which should be unique across a cluster. Manager represents the kubernetes cluster. Actor implements the logic of the reconciliation.

Types

type Action

type Action[T client.Object] func(*Context[T]) error

func (Action[T]) String

func (s Action[T]) String() string

type Actor

type Actor[T client.Object] interface {
	Observe(*Context[T]) (Action[T], error)
	Finalize(*Context[T]) (done bool, err error)
}

type ApplyOption

type ApplyOption func(*options)

func WithBuildFn

func WithBuildFn(buildFn func(*builder.Builder)) ApplyOption

WithBuildFn allows customizing reconciler.Builder defined the controller-runtime

func WithControllerOptions

func WithControllerOptions(opts controller.Options) ApplyOption

WithEventRecorder set the controller options of the reconciler

func WithEventRecorder

func WithEventRecorder(recorder record.EventRecorder) ApplyOption

WithEventRecorder set the event recorder of the reconciler

func WithLogger

func WithLogger(logger logr.Logger) ApplyOption

WithEventRecorder set the logger of the reconciler

type ConditionType

type ConditionType string

type Conditional

type Conditional interface {
	SetCondition(c metav1.Condition)
	GetConditions() []metav1.Condition
}

type Context

type Context[T client.Object] struct {
	context.Context
	Obj T

	// Dep hold the dependencies of the object T, will only be set when
	// the object implement the `Dependant` interface
	Dep T

	Client client.Client
	// TODO(aylei): add tracing
	Event EventEmitter
	Log   logr.Logger
}

func (*Context[T]) Create

func (c *Context[T]) Create(obj client.Object, opts ...client.CreateOption) error

TODO(aylei): add logging and tracing when operate upon kube-api

func (*Context[T]) CreateOwned

func (c *Context[T]) CreateOwned(obj client.Object, opts ...client.CreateOption) error

CreateOwned create the given object with an OwnerReference to the currently reconciling controller object (ctx.Obj)

func (*Context[T]) Delete

func (c *Context[T]) Delete(obj client.Object, opts ...client.DeleteOption) error

Delete marks the given obj to be deleted

func (*Context[T]) Exist

func (c *Context[T]) Exist(objKey client.ObjectKey, kind client.Object) (bool, error)

func (*Context[T]) Get

func (c *Context[T]) Get(objKey client.ObjectKey, obj client.Object) error

func (*Context[T]) List

func (c *Context[T]) List(objList client.ObjectList, opts ...client.ListOption) error

func (*Context[T]) Patch

func (c *Context[T]) Patch(obj client.Object, mutateFn func() error, opts ...client.PatchOption) error

Patch patches the mutation by mutateFn to the spec of given obj an error would be raised if mutateFn changed anything immutable (e.g. namespace / name)

func (*Context[T]) Update

func (c *Context[T]) Update(obj client.Object, opts ...client.UpdateOption) error

Update update the spec of the given obj

func (*Context[T]) UpdateStatus

func (c *Context[T]) UpdateStatus(obj client.Object, opts ...client.UpdateOption) error

UpdateStatus update the status of the given obj

type Dependant

type Dependant interface {
	GetDependencies() []Dependency
}

type Dependency

type Dependency interface {
	// IsReady checks whether the given object is ready
	IsReady(kubeCli KubeClient) (bool, error)
}

type EmitEventWrapper

type EmitEventWrapper struct {
	record.EventRecorder
	// contains filtered or unexported fields
}

EmitEventWrapper captures the object being reconciled and associated all emitted events with that object

func (*EmitEventWrapper) EmitEventGeneric

func (e *EmitEventWrapper) EmitEventGeneric(eventReason, msg string, err error)

EmitEventGeneric shall emit a generic event

func (*EmitEventWrapper) EmitEventOnCreate

func (e *EmitEventWrapper) EmitEventOnCreate(createObj client.Object, err error)

EmitEventOnCreate shall emit event on CREATE operation

func (*EmitEventWrapper) EmitEventOnDelete

func (e *EmitEventWrapper) EmitEventOnDelete(deleteObj client.Object, err error)

EmitEventOnDelete shall emit event on DELETE operation

func (*EmitEventWrapper) EmitEventOnGetError

func (e *EmitEventWrapper) EmitEventOnGetError(getObj client.Object, err error)

EmitEventOnGetError shall emit event on GET err operation

func (*EmitEventWrapper) EmitEventOnList

func (e *EmitEventWrapper) EmitEventOnList(listObj client.ObjectList, err error)

EmitEventOnList shall emit event on LIST err operation

func (*EmitEventWrapper) EmitEventOnPatch

func (e *EmitEventWrapper) EmitEventOnPatch(patchObj client.Object, err error)

EmitEventOnPatch shall emit event on PATCH operation

func (*EmitEventWrapper) EmitEventOnUpdate

func (e *EmitEventWrapper) EmitEventOnUpdate(updateObj client.Object, err error)

EmitEventOnUpdate shall emit event on UPDATE operation

func (*EmitEventWrapper) EmitEventRollingDeployWait

func (e *EmitEventWrapper) EmitEventRollingDeployWait(k8sObj client.Object)

type EventEmitter

type EventEmitter interface {
	K8sEventEmitter
	GenericEventEmitter
}

EventEmitter Interface is a wrapper interface for all the emitter interface operator shall support.

type EventReason

type EventReason string

TODO(aylei): event.go is modified from pkg/controller/event.go, remove the original one once we migrate to mo-runtime

type GenericEventEmitter

type GenericEventEmitter interface {
	EmitEventGeneric(eventReason, msg string, err error)
}

GenericEventEmitter can be used for any case where the state change isn't handled by reader,writer or any custom event.

type K8sEventEmitter

type K8sEventEmitter interface {
	EmitEventRollingDeployWait(k8sObj client.Object)
	EmitEventOnGetError(getObj client.Object, err error)
	EmitEventOnUpdate(updateObj client.Object, err error)
	EmitEventOnDelete(deleteObj client.Object, err error)
	EmitEventOnCreate(createObj client.Object, err error)
	EmitEventOnPatch(patchObj client.Object, err error)
	EmitEventOnList(listObj client.ObjectList, err error)
}

type KubeClient

type KubeClient interface {
	Create(obj client.Object, opts ...client.CreateOption) error
	CreateOwned(obj client.Object, opts ...client.CreateOption) error
	Get(objKey client.ObjectKey, obj client.Object) error
	Update(obj client.Object, opts ...client.UpdateOption) error
	UpdateStatus(obj client.Object, opts ...client.UpdateOption) error
	Delete(obj client.Object, opts ...client.DeleteOption) error
	List(objList client.ObjectList, opts ...client.ListOption) error
	Patch(obj client.Object, mutateFn func() error, opts ...client.PatchOption) error
	Exist(objKey client.ObjectKey, kind client.Object) (bool, error)
}

type ObjectDependency

type ObjectDependency[T client.Object] struct {
	ObjectRef T
	ReadyFunc func(T) bool
}

func (*ObjectDependency[T]) IsReady

func (od *ObjectDependency[T]) IsReady(kubeCli KubeClient) (bool, error)

type ReSync

type ReSync struct {
	Message      string
	RequeueAfter time.Duration
}

func ErrReSync

func ErrReSync(msg string, requeueAfter ...time.Duration) *ReSync

func (*ReSync) Error

func (e *ReSync) Error() string

type Reconciler

type Reconciler[T client.Object] struct {
	client.Client
	// contains filtered or unexported fields
}

func (*Reconciler[T]) Reconcile

func (r *Reconciler[T]) Reconcile(goCtx context.Context, req recon.Request) (recon.Result, error)

Jump to

Keyboard shortcuts

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