deployer

package
v0.1.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LastAppliedResourceSpec = "controller.greptime.io/last-applied-resource-spec"
)

Variables

View Source
var (
	ErrSyncNotReady = fmt.Errorf("the sync process is not ready")
)

Functions

func CreateObjectIfNotExist

func CreateObjectIfNotExist(ctx context.Context, c client.Client, source, newObject client.Object) (client.Object, error)

CreateObjectIfNotExist creates Kubernetes object if it does not exist, otherwise returns the existing object.

func GeneratePodTemplateSpec

func GeneratePodTemplateSpec(template *v1alpha1.PodTemplateSpec, mainContainerName string) *corev1.PodTemplateSpec

func IsDeploymentReady

func IsDeploymentReady(deployment *appsv1.Deployment) bool

IsDeploymentReady checks if the deployment is ready. TODO(zyy17): Maybe it's not a accurate way to detect the statefulset is ready.

func IsObjectSpecEqual

func IsObjectSpecEqual(objectA, objectB client.Object) (bool, error)

IsObjectSpecEqual checks if the spec of the object is equal to other one.

func IsStatefulSetReady

func IsStatefulSetReady(sts *appsv1.StatefulSet) bool

IsStatefulSetReady checks if the statefulset is ready. TODO(zyy17): Maybe it's not a accurate way to detect the deployment is ready.

func MergeStringMap

func MergeStringMap(origin, new map[string]string) map[string]string

func SetControllerAndAnnotation

func SetControllerAndAnnotation(owner, controlled client.Object, scheme *runtime.Scheme, spec interface{}) error

SetControllerAndAnnotation sets the controller reference and annotation for the object.

Types

type ComponentOperator

type ComponentOperator interface {
	// Render generates the multiple Kubernetes objects base on the CRD object.
	Render(crdObject client.Object) ([]client.Object, error)

	// Apply creates or update the Kubernetes objects that generated by Render().
	// If the object is not existed, it will be created.
	// If the object is existed, it will be updated if the object is different.
	Apply(ctx context.Context, objects []client.Object) error

	// CleanUp cleans up the resources that created by the deployer.
	CleanUp(ctx context.Context, crdObject client.Object) error

	// CheckAndUpdateStatus checks if the status of Kubernetes objects are ready and update the status.
	CheckAndUpdateStatus(ctx context.Context, crdObject client.Object) (bool, error)

	// PreSyncHooks returns the hooks that will be executed before the core login of Sync().
	PreSyncHooks() []Hook

	// PostSyncHooks returns the hooks that will be executed after the core login of Sync().
	PostSyncHooks() []Hook
}

ComponentOperator is the interface that define the behaviors of a deployer.

type DefaultDeployer

type DefaultDeployer struct {
	client.Client
}

DefaultDeployer implement some common behaviors of the ComponentOperator interface.

func (*DefaultDeployer) Apply

func (d *DefaultDeployer) Apply(ctx context.Context, objects []client.Object) error

func (*DefaultDeployer) CheckAndUpdateStatus

func (d *DefaultDeployer) CheckAndUpdateStatus(_ context.Context, _ client.Object) (bool, error)

func (*DefaultDeployer) CleanUp

func (d *DefaultDeployer) CleanUp(_ context.Context, _ client.Object) error

func (*DefaultDeployer) PostSyncHooks

func (d *DefaultDeployer) PostSyncHooks() []Hook

func (*DefaultDeployer) PreSyncHooks

func (d *DefaultDeployer) PreSyncHooks() []Hook

func (*DefaultDeployer) Render

func (d *DefaultDeployer) Render(_ client.Object) ([]client.Object, error)

func (*DefaultDeployer) Sync

func (d *DefaultDeployer) Sync(ctx context.Context, crdObject client.Object, operator ComponentOperator) error

type Deployer

type Deployer interface {
	Syncer
	ComponentOperator
}

Deployer is the interface that abstracts the deployment of a component.

type Hook

type Hook func(ctx context.Context, crdObject client.Object) error

Hook is a function that will be executed before or after the Sync().

type Syncer

type Syncer interface {
	Sync(ctx context.Context, crdObject client.Object, operator ComponentOperator) error
}

Syncer use the deployer to sync the CRD object.

Jump to

Keyboard shortcuts

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