Documentation
¶
Index ¶
- func GenerateServiceName(image string) (string, error)
- type Client
- type ContainerSpecStatus
- type CreateVolumeOperation
- type Deployment
- type ImageDigestResolver
- type ImageResolverClient
- type NameResolver
- type Operation
- type Plan
- type RemoveContainerOperation
- type RollingStrategy
- type RunContainerOperation
- type SequenceOperation
- type ServiceSpecResolver
- type StopContainerOperation
- type Strategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateServiceName ¶ added in v0.6.0
Types ¶
type Client ¶
type Client interface { api.ContainerClient api.DNSClient api.ImageClient api.MachineClient api.ServiceClient api.VolumeClient }
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 (o *CreateVolumeOperation) Format(_ NameResolver) string
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.
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 ¶
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) 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 ¶
func (r *ServiceSpecResolver) Resolve(spec api.ServiceSpec) (api.ServiceSpec, error)
Resolve transforms a service spec into its fully resolved form ready for deployment.
type StopContainerOperation ¶
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.