controller

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 33 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToMgr

func AddToMgr(mgr manager.Manager, adapter ReconcileAdapter) error

AddToMgr creates a new Controller of specified reconcileAdapter and adds it to the Manager with default RBAC. The Manager will set fields on the Controller and Start it when the Manager is Started.

func GetEmployerByEmployee

func GetEmployerByEmployee(ctx context.Context, client client.Client, employee client.Object) ([]string, error)

Types

type CUDEmployeeResults added in v0.0.2

type CUDEmployeeResults struct {
	SuccCreated []IEmployee
	FailCreated []IEmployee
	SuccUpdated []IEmployee
	FailUpdated []IEmployee
	SuccDeleted []IEmployee
	FailDeleted []IEmployee
	Unchanged   []IEmployee
}

type CUDEmployerResults added in v0.0.2

type CUDEmployerResults struct {
	SuccCreated []IEmployer
	FailCreated []IEmployer
	SuccUpdated []IEmployer
	FailUpdated []IEmployer
	SuccDeleted []IEmployer
	FailDeleted []IEmployer
	Unchanged   []IEmployer
}

type Consist

type Consist struct {
	client.Client
	// contains filtered or unexported fields
}

func NewReconcile

func NewReconcile(mgr manager.Manager, reconcileAdapter ReconcileAdapter) *Consist

func (*Consist) Reconcile

func (r *Consist) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error)

type EnqueueServiceByPod

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

func (*EnqueueServiceByPod) Create

func (*EnqueueServiceByPod) Delete

func (*EnqueueServiceByPod) Generic

func (*EnqueueServiceByPod) Update

type EnqueueServiceWithRateLimit

type EnqueueServiceWithRateLimit struct{}

func (*EnqueueServiceWithRateLimit) Create

func (*EnqueueServiceWithRateLimit) Delete

func (*EnqueueServiceWithRateLimit) Generic

func (*EnqueueServiceWithRateLimit) Update

type ExpectedFinalizerRecordOptions added in v0.0.2

type ExpectedFinalizerRecordOptions interface {
	// NeedRecordExpectedFinalizerCondition only needed for those adapters that follow PodOpsLifecycle,
	// in the case of employment relationship might change(like label/selector changes) and the compensation logic
	// of kusionstack.io/operating can't handle the changes.
	// in most cases, this option is not needed.
	NeedRecordExpectedFinalizerCondition() bool
}

type IEmployee

type IEmployee interface {
	GetEmployeeId() string
	// GetEmployeeName returns employee's name
	// note: in multi cluster case, if adapters deployed in fed and employees are under local, the format of employeeName
	// should be "employeeName" + "#" + "clusterName"
	GetEmployeeName() string
	GetEmployeeStatuses() interface{}
	EmployeeEqual(employee IEmployee) (bool, error)
}

type IEmployer

type IEmployer interface {
	GetEmployerId() string
	GetEmployerStatuses() interface{}
	EmployerEqual(employer IEmployer) (bool, error)
}

type MultiClusterOptions added in v0.0.2

type MultiClusterOptions interface {
	EmployeeFed() bool
}

MultiClusterOptions defines whether employee is under fed cluster "kusionstack.io/kube-utils/multicluster" is the solution for multi cluster if MultiClusterOptions implemented, the cache and client of manager should be generated via "kusionstack.io/kube-utils/multicluster"

type PodEmployeeStatuses

type PodEmployeeStatuses struct {
	// can be set by calling SetCommonPodEmployeeStatus
	Ip             string `json:"ip,omitempty"`
	Ipv6           string `json:"ipv6,omitempty"`
	LifecycleReady bool   `json:"lifecycleReady,omitempty"`
	// extra info related to backend provider
	ExtraStatus interface{} `json:"extraStatus,omitempty"`
}

func GetCommonPodEmployeeStatus

func GetCommonPodEmployeeStatus(pod *corev1.Pod) (PodEmployeeStatuses, error)

GetCommonPodEmployeeStatus called by ReconcileAdapter's GetExpectedEmployee/GetCurrentEmployee

type PodExpectedFinalizerOps

type PodExpectedFinalizerOps struct {
	Name    string
	Succeed bool
}

type ReconcileAdapter

type ReconcileAdapter interface {
	GetControllerName() string

	// GetSelectedEmployeeNames returns employees' names selected by employer
	// note: in multi cluster case, if adapters deployed in fed and employees are under local, the format of employeeName
	// should be "employeeName" + "#" + "clusterName"
	GetSelectedEmployeeNames(ctx context.Context, employer client.Object) ([]string, error)

	// GetExpectedEmployer and GetCurrentEmployer return expect/current status of employer from related backend provider
	GetExpectedEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error)
	GetCurrentEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error)

	// CreateEmployer/UpdateEmployer/DeleteEmployer handles creation/update/deletion of resources related to employer on related backend provider
	CreateEmployer(ctx context.Context, employer client.Object, toCreates []IEmployer) ([]IEmployer, []IEmployer, error)
	UpdateEmployer(ctx context.Context, employer client.Object, toUpdates []IEmployer) ([]IEmployer, []IEmployer, error)
	DeleteEmployer(ctx context.Context, employer client.Object, toDeletes []IEmployer) ([]IEmployer, []IEmployer, error)

	// GetExpectedEmployee and GetCurrentEmployee return expect/current status of employees from related backend provider
	GetExpectedEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error)
	GetCurrentEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error)

	// CreateEmployees/UpdateEmployees/DeleteEmployees handles creation/update/deletion of resources related to employee on related backend provider
	CreateEmployees(ctx context.Context, employer client.Object, toCreates []IEmployee) ([]IEmployee, []IEmployee, error)
	UpdateEmployees(ctx context.Context, employer client.Object, toUpdates []IEmployee) ([]IEmployee, []IEmployee, error)
	DeleteEmployees(ctx context.Context, employer client.Object, toDeletes []IEmployee) ([]IEmployee, []IEmployee, error)
}

ReconcileAdapter is the interface that customized controllers should implement.

type ReconcileLifecycleOptions

type ReconcileLifecycleOptions interface {
	FollowPodOpsLifeCycle() bool

	// NeedRecordLifecycleFinalizerCondition only needed for those adapters that follow PodOpsLifecycle,
	// in the case of employment relationship might change and resources in backend provider might be changed by others.
	NeedRecordLifecycleFinalizerCondition() bool
}

ReconcileLifecycleOptions defines whether PodOpsLifecycle followed and whether employees' LifecycleFinalizer conditions need to be Recorded/Erased to employer's anno. If not implemented, the default options would be: FollowPodOpsLifeCycle: true and NeedRecordLifecycleFinalizerCondition: false

type ReconcileOptions

type ReconcileOptions interface {
	GetRateLimiter() ratelimiter.RateLimiter
	GetMaxConcurrent() int
}

ReconcileOptions includes max concurrent reconciles and rate limiter, max concurrent reconcile: 5 and DefaultControllerRateLimiter() will be used if ReconcileOptions not implemented.

type ReconcileRequeueOptions

type ReconcileRequeueOptions interface {
	// EmployeeSyncRequeueInterval returns requeue time interval if employee synced failed but no err
	EmployeeSyncRequeueInterval() time.Duration
}

type ReconcileWatchOptions

type ReconcileWatchOptions interface {
	NewEmployer() client.Object
	NewEmployee() client.Object
	EmployerEventHandler() handler.EventHandler
	EmployeeEventHandler() handler.EventHandler
	EmployerPredicates() predicate.Funcs
	EmployeePredicates() predicate.Funcs
}

ReconcileWatchOptions defines what employer and employee is and how controller watch default employer: Service, default employee: Pod Recommend: implement ReconcileWatchOptions if Employer resource might be reconciled by other controller, different Predicates make an employer won't be reconciled by more than one controller so that LifecycleFinalizer won't be solved incorrectly.

type StatusRecordOptions added in v0.0.2

type StatusRecordOptions interface {
	RecordStatuses(ctx context.Context, employer client.Object,
		cudEmployerResults CUDEmployerResults, cudEmployeeResults CUDEmployeeResults) error
}

StatusRecordOptions defines methods of record something for adapters

type ToCUDEmployees

type ToCUDEmployees struct {
	ToCreate  []IEmployee
	ToUpdate  []IEmployee
	ToDelete  []IEmployee
	Unchanged []IEmployee
}

type ToCUDEmployer

type ToCUDEmployer struct {
	ToCreate  []IEmployer
	ToUpdate  []IEmployer
	ToDelete  []IEmployer
	Unchanged []IEmployer
}

Jump to

Keyboard shortcuts

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