deploy

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateServiceName added in v0.6.0

func GenerateServiceName(image string) (string, error)

Types

type ContainerSpecStatus

type ContainerSpecStatus string
const (
	ContainerUpToDate      ContainerSpecStatus = "up-to-date"
	ContainerNeedsUpdate   ContainerSpecStatus = "needs-update"
	ContainerNeedsRecreate ContainerSpecStatus = "needs-recreate"
)

func EvalContainerSpecChange

func EvalContainerSpecChange(current api.ServiceSpec, new api.ServiceSpec) ContainerSpecStatus

type CreateVolumeOperation added in v0.6.0

type CreateVolumeOperation struct {
	VolumeSpec api.VolumeSpec
	MachineID  string
	// MachineName is used for formatting the operation output only.
	MachineName string
}

CreateVolumeOperation creates a volume on a specific machine.

func (*CreateVolumeOperation) Execute added in v0.6.0

func (o *CreateVolumeOperation) Execute(ctx context.Context, cli Client) error

func (*CreateVolumeOperation) Format added in v0.6.0

func (*CreateVolumeOperation) String added in v0.6.0

func (o *CreateVolumeOperation) String() string

type Deployment

type Deployment struct {
	Service  *api.Service
	Spec     api.ServiceSpec
	Strategy Strategy
	// contains filtered or unexported fields
}

Deployment manages the process of creating or updating a service to match a desired state. It coordinates the validation, planning, and execution of deployment operations.

func NewDeployment

func NewDeployment(cli Client, spec api.ServiceSpec, strategy Strategy) *Deployment

NewDeployment creates a new deployment for the given service specification. If strategy is nil, a default RollingStrategy will be used.

func (*Deployment) Plan

func (d *Deployment) Plan(ctx context.Context) (Plan, error)

Plan returns a plan of operations to reconcile the service to the desired state. If a plan has already been created, the same plan will be returned.

func (*Deployment) Run

func (d *Deployment) Run(ctx context.Context) (Plan, error)

Run executes the deployment plan and returns the ID of the created or updated service. It will create a new plan if one hasn't been created yet. The deployment will either create a new service or update the existing one to match the desired specification. TODO: forbid to run the same deployment more than once.

func (*Deployment) Validate

func (d *Deployment) Validate(ctx context.Context) error

Validate checks if the deployment specification is valid.

type ImageDigestResolver

type ImageDigestResolver struct {
	Ctx    context.Context
	Client ImageResolverClient
}

TODO(lhf): as of April 2025, ImageDigestResolver is not used in the codebase and considered more harmful than helpful. It's safe to remove it.

func (*ImageDigestResolver) Resolve

func (r *ImageDigestResolver) Resolve(image, policy string) (string, error)

Resolve resolves the image to the image with the digest according to the pull policy:

  • always: Fetch the latest digest for the image tag in the registry.
  • missing: Find the latest image matching the tag on any machine and use its digest, if it exists. When there is no matching image on any machine, it behaves like 'always'.
  • never: !Not implemented! Similar to 'missing' but when there is no matching image on any machine, it returns an error.

If the image is already pinned to a digest, it is returned as is.

type ImageResolverClient

type ImageResolverClient interface {
	api.ImageClient
	api.MachineClient
}

type NameResolver

type NameResolver interface {
	MachineName(machineID string) string
	ContainerName(containerID string) string
}

NameResolver resolves machine and container IDs to their names.

type Operation

type Operation interface {
	// Execute performs the operation using the provided client.
	// TODO: Encapsulate the client in the operation as otherwise it gives an impression that different clients
	//  can be provided. But in reality, the operation is tightly coupled with the client that was used to create it.
	Execute(ctx context.Context, cli Client) error
	// Format returns a human-readable representation of the operation.
	// TODO: get rid of the resolver and assign the required names for formatting in the operation itself.
	Format(resolver NameResolver) string
	String() string
}

Operation represents a single atomic operation in a deployment process. Operations can be composed to form complex deployment strategies.

type Plan

type Plan struct {
	ServiceID   string
	ServiceName string
	SequenceOperation
}

type RemoveContainerOperation

type RemoveContainerOperation struct {
	ServiceID   string
	ContainerID string
	MachineID   string
}

RemoveContainerOperation stops and removes a container from a specific machine.

func (*RemoveContainerOperation) Execute

func (o *RemoveContainerOperation) Execute(ctx context.Context, cli Client) error

func (*RemoveContainerOperation) Format

func (o *RemoveContainerOperation) Format(resolver NameResolver) string

func (*RemoveContainerOperation) String

func (o *RemoveContainerOperation) String() string

type RollingStrategy

type RollingStrategy struct {
	State         *scheduler.ClusterState
	ForceRecreate bool
}

RollingStrategy implements a rolling update deployment pattern where containers are updated one at a time to minimize service disruption.

func (*RollingStrategy) Plan

func (s *RollingStrategy) Plan(
	ctx context.Context, cli scheduler.Client, svc *api.Service, spec api.ServiceSpec,
) (Plan, error)

func (*RollingStrategy) Type

func (s *RollingStrategy) Type() string

type RunContainerOperation

type RunContainerOperation struct {
	ServiceID string
	Spec      api.ServiceSpec
	MachineID string
}

RunContainerOperation creates and starts a new container on a specific machine.

func (*RunContainerOperation) Execute

func (o *RunContainerOperation) Execute(ctx context.Context, cli Client) error

func (*RunContainerOperation) Format

func (o *RunContainerOperation) Format(resolver NameResolver) string

func (*RunContainerOperation) String

func (o *RunContainerOperation) String() string

type SequenceOperation

type SequenceOperation struct {
	Operations []Operation
}

SequenceOperation is a composite operation that executes a sequence of operations in order.

func (*SequenceOperation) Execute

func (o *SequenceOperation) Execute(ctx context.Context, cli Client) error

func (*SequenceOperation) Format

func (o *SequenceOperation) Format(resolver NameResolver) string

func (*SequenceOperation) String

func (o *SequenceOperation) String() string

type ServiceSpecResolver

type ServiceSpecResolver struct {
	ClusterDomain string
	ImageResolver *ImageDigestResolver
}

ServiceSpecResolver transforms user-provided service specs into deployment-ready form.

func (*ServiceSpecResolver) Resolve

Resolve transforms a service spec into its fully resolved form ready for deployment.

type StopContainerOperation

type StopContainerOperation struct {
	ServiceID   string
	ContainerID string
	MachineID   string
}

StopContainerOperation stops a container on a specific machine.

func (*StopContainerOperation) Execute

func (o *StopContainerOperation) Execute(ctx context.Context, cli Client) error

func (*StopContainerOperation) Format

func (o *StopContainerOperation) Format(resolver NameResolver) string

func (*StopContainerOperation) String

func (o *StopContainerOperation) String() string

type Strategy

type Strategy interface {
	// Type returns the type of the deployment strategy, e.g. "rolling", "blue-green".
	Type() string
	// Plan returns the operation to reconcile the service to the desired state.
	// If the service does not exist (new deployment), svc will be nil.
	Plan(ctx context.Context, cli scheduler.Client, svc *api.Service, spec api.ServiceSpec) (Plan, error)
}

Strategy defines how a service should be deployed or updated. Different implementations can provide various deployment patterns such as rolling updates, blue/green deployments, etc.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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