templateupgrade

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package templateupgrade plans a guarded upgrade of a deployed catalog template. It is pure: callers parse the stored and catalog compose bodies, the planner returns a JSON-serializable Plan and never touches a runtime, a store or a secret value.

Index

Constants

View Source
const (
	EnvAdd      = "add"
	EnvRemove   = "remove"
	EnvUpdate   = "update"
	EnvKeepUser = "keep_user"
)

Env actions. Values are never reported, only names.

View Source
const (
	KindPatch     = "patch"
	KindMinor     = "minor"
	KindMajor     = "major"
	KindDowngrade = "downgrade"
	KindChanged   = "changed"
	KindNew       = "new"
	KindRemoved   = "removed"
)

Image change kinds.

View Source
const (
	ServiceUnchanged = "unchanged"
	ServiceChanged   = "changed"
	ServiceAdded     = "added"
	ServiceRemoved   = "removed"
)

Service statuses in a Plan.

View Source
const (
	BlockerVolumeRemoved    = "volume_removed"
	BlockerVolumeRetargeted = "volume_retargeted"
	BlockerServiceRemoved   = "service_removed_with_data"
)

Blocker codes: any blocker stops an automatic upgrade.

View Source
const (
	VolumeAdd       = "add"
	VolumeRemove    = "remove"
	VolumeRetarget  = "retarget"
	PortAdd         = "add"
	PortRemove      = "remove"
	ReasonRemoved   = "named volume no longer in the template"
	ReasonRetargets = "named volume mounted at a different path"
)

Volume and port actions.

Variables

View Source
var ErrUserServices = errors.New("the app has services that are not part of the template")

ErrUserServices means the installed file has services the template never had; applying the catalog body would delete them.

Functions

func Merge

func Merge(installedBody, templateBody string, plan Plan) (string, error)

Merge returns the template body with the user's choices carried over: a pinned image tag, env values the plan marks keep_user, and env variables the user added. Everything else is the new template, so the result goes through the normal compose deploy path unchanged.

func Version

func Version(f *compose.File) string

Version is the template's version stamp: its image tags, since catalog templates carry no version field of their own.

Types

type Blocker

type Blocker struct {
	Code    string `json:"code"`
	Service string `json:"service"`
	Detail  string `json:"detail"`
}

Blocker is one reason an upgrade must not run unattended.

type EnvChange

type EnvChange struct {
	Name      string `json:"name"`
	Action    string `json:"action"`
	Generated bool   `json:"generated,omitempty"`
	Required  bool   `json:"required,omitempty"`
}

EnvChange is one variable's planned fate. Generated marks a value the platform creates (a magic variable), Required one the template leaves empty for the operator.

type HealthcheckChange

type HealthcheckChange struct {
	From      string `json:"from,omitempty"`
	To        string `json:"to,omitempty"`
	Preserved bool   `json:"preserved,omitempty"`
}

HealthcheckChange summarizes a probe change; Preserved means the user already edited it away from the baseline.

type ImageChange

type ImageChange struct {
	From      string `json:"from,omitempty"`
	To        string `json:"to,omitempty"`
	Kind      string `json:"kind"`
	Preserved bool   `json:"preserved,omitempty"`
}

ImageChange is one service's image move. Preserved means the installed tag differs from the baseline, so the user pinned it and the executor leaves it alone.

type Input

type Input struct {
	AppID      string
	TemplateID string
	Installed  *compose.File
	Baseline   *compose.File
	Template   *compose.File
}

Input is everything the planner reads. Baseline is optional: the compose body of the first template revision of the app. With it, a value that differs from the baseline is a user edit; without it every value that differs from the catalog is treated as one.

type Plan

type Plan struct {
	AppID       string        `json:"app_id"`
	TemplateID  string        `json:"template_id"`
	FromVersion string        `json:"from_version"`
	ToVersion   string        `json:"to_version"`
	Risk        Risk          `json:"risk"`
	HasChanges  bool          `json:"has_changes"`
	Automatic   bool          `json:"automatic"`
	Blockers    []Blocker     `json:"blockers"`
	Services    []ServicePlan `json:"services"`
}

Plan is the upgrade a later executor may apply: back up first, apply Services in order, roll back on failure. It carries names and tags only, never environment values.

func Build

func Build(in Input) Plan

Build computes the plan. Nil Installed or Template yields an empty plan.

type PortChange

type PortChange struct {
	Port     int    `json:"port"`
	Protocol string `json:"protocol,omitempty"`
	Action   string `json:"action"`
}

PortChange is a published or container port the template adds or drops.

type Risk

type Risk string

Risk grades how much attention an upgrade needs.

const (
	RiskNone   Risk = "none"
	RiskLow    Risk = "low"
	RiskMedium Risk = "medium"
	RiskHigh   Risk = "high"
)

Risk levels, from "nothing to do" to "needs a human".

type ServicePlan

type ServicePlan struct {
	Name        string             `json:"name"`
	Status      string             `json:"status"`
	Image       *ImageChange       `json:"image,omitempty"`
	Env         []EnvChange        `json:"env,omitempty"`
	Volumes     []VolumeChange     `json:"volumes,omitempty"`
	Ports       []PortChange       `json:"ports,omitempty"`
	Healthcheck *HealthcheckChange `json:"healthcheck,omitempty"`
}

ServicePlan is the change set for one service key.

type VolumeChange

type VolumeChange struct {
	Name   string `json:"name"`
	Action string `json:"action"`
	From   string `json:"from,omitempty"`
	To     string `json:"to,omitempty"`
}

VolumeChange covers named volumes only; bind mounts are user-owned. Remove and retarget are blockers.

Jump to

Keyboard shortcuts

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