Documentation
¶
Index ¶
- Constants
- Variables
- func BuildHTTPTransport(r *types.RegistryConfig) (*http.Transport, error)
- func BytesString(s string) (string, error)
- func CPUString(s string, targetIsDocker bool) (string, error)
- func ClusterRollbackClean(err error) bool
- func CommandOptionArgs(options CommandOptions, allowedContainerArgs map[string]string) ([]string, error)
- func ContextWithDeployTxn(ctx context.Context, d *DeployTxn) context.Context
- func CreateOrUpdateSecret(ctx context.Context, cs kubernetes.Interface, ns, name string, ...) error
- func DelegateHandler(r *http.Request, config *types.ServerConfig, logger *types.Logger) (any, error)
- func DigestPinned(image, digest string) string
- func GenerateDockerConfigJSON(r *types.RegistryConfig) ([]byte, error)
- func GetDockerConfig(ctx context.Context, imageRef string, registryConfig *types.RegistryConfig) (name.Reference, []remote.Option, error)
- func GetImageReferenceConfig(ctx context.Context, imageRef string, registryConfig *types.RegistryConfig) (name.Reference, []remote.Option, error)
- func GetWorkloadPodLogs(ctx context.Context, config *types.ServerConfig, name string, tail int) (string, error)
- func GetWorkloadPodLogsStream(ctx context.Context, config *types.ServerConfig, name string, tail int, ...) (io.ReadCloser, error)
- func HasPersistentVolume(volumes []*VolumeInfo) bool
- func ImageExists(ctx context.Context, logger *types.Logger, imageRef string, ...) (bool, error)
- func KanikoJob(ctx context.Context, logger *types.Logger, cs kubernetes.Interface, ...) error
- func LocalhostBindingHostname(containerCommand string) string
- func LocalhostHostGatewayArgs(containerCommand string) []string
- func LookupContainerCommand(checkKubernetes bool) string
- func RedactEnvArgs(args []string) []string
- func RewriteLocalhostEndpoint(endpoint, containerCommand string) string
- func TrimLabelValue(input string) string
- type AppContainerStopper
- type ClusterStats
- type CommandCM
- func (c *CommandCM) BuildImage(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, ...) error
- func (c *CommandCM) BuildImageTarget(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, ...) error
- func (c *CommandCM) ContainerExited(ctx context.Context, name ContainerName) (bool, string, error)
- func (c *CommandCM) DeployContainer(ctx context.Context, req DeployRequest) (DeployResult, error)
- func (c *CommandCM) EnsureLitestreamSidecar(ctx context.Context, appEntry *types.AppEntry, spec *LitestreamAppSpec) error
- func (c *CommandCM) ExecTailN(ctx context.Context, command string, args []string, n int) ([]string, error)
- func (c *CommandCM) GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)
- func (c *CommandCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)
- func (c *CommandCM) GetDevContainerInfo(ctx context.Context, name ContainerName, runHash string) (bool, bool, string, bool, error)
- func (c *CommandCM) ImageExists(ctx context.Context, name ImageName) (bool, error)
- func (c *CommandCM) InitVolumePermissions(ctx context.Context, image ImageName, volumeName VolumeName, targetDir string) error
- func (c *CommandCM) ListOpenRunContainers(ctx context.Context) ([]Container, error)
- func (c *CommandCM) RefreshImage(ctx context.Context, name ImageName) (string, error)
- func (c *CommandCM) RemoveContainer(ctx context.Context, name ContainerName) error
- func (c *CommandCM) RemoveImage(ctx context.Context, name ImageName) error
- func (c *CommandCM) RemoveSupersededImages(ctx context.Context, keep ImageName) error
- func (c *CommandCM) RestartDevContainer(ctx context.Context, name ContainerName) error
- func (c *CommandCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, ...) error
- func (c *CommandCM) RunDevContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, ...) error
- func (c *CommandCM) RunLitestreamRestores(ctx context.Context, appId types.AppId, spec *LitestreamAppSpec) error
- func (c *CommandCM) StartContainer(ctx context.Context, name ContainerName) error
- func (c *CommandCM) StopAppContainersExcept(ctx context.Context, appId types.AppId, keep ContainerName) error
- func (c *CommandCM) StopContainer(ctx context.Context, name ContainerName) error
- func (c *CommandCM) StopLitestreamSidecar(ctx context.Context, appId types.AppId) error
- func (k *CommandCM) SupportsInPlaceUpdate() bool
- func (c CommandCM) VolumeCreate(ctx context.Context, name VolumeName, size string) error
- func (c CommandCM) VolumeExists(ctx context.Context, name VolumeName) bool
- type CommandOptions
- type Container
- type ContainerExitChecker
- type ContainerManager
- type ContainerName
- type DelegateRequest
- type DeployRequest
- type DeployResult
- type DeployRollbackError
- type DeployTxn
- type DevContainerManager
- type DevRunOptions
- type ExistsResult
- type HealthProbe
- type ImageName
- type KanikoBuild
- type KubernetesCM
- func (k *KubernetesCM) BuildImage(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, ...) error
- func (k *KubernetesCM) CurrentVersionHash(ctx context.Context, name ContainerName) (string, error)
- func (k *KubernetesCM) DeployContainer(ctx context.Context, req DeployRequest) (DeployResult, error)
- func (k *KubernetesCM) GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)
- func (k *KubernetesCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)
- func (k *KubernetesCM) ImageExists(ctx context.Context, name ImageName) (bool, error)
- func (k *KubernetesCM) PromoteVersion(ctx context.Context, serviceName ContainerName, versionHash string) (string, map[string]string, error)
- func (k *KubernetesCM) RefreshImage(ctx context.Context, name ImageName) (string, error)
- func (k *KubernetesCM) RemoveVersion(ctx context.Context, serviceName ContainerName, versionHash string) error
- func (k *KubernetesCM) Restore(ctx context.Context, snapshot any) error
- func (k *KubernetesCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, ...) error
- func (k *KubernetesCM) Snapshot(ctx context.Context, name ContainerName) (any, error)
- func (k *KubernetesCM) StartContainer(ctx context.Context, name ContainerName) error
- func (k *KubernetesCM) StopContainer(ctx context.Context, name ContainerName) error
- func (k *KubernetesCM) SupportsInPlaceUpdate() bool
- func (k *KubernetesCM) VolumeCreate(ctx context.Context, name VolumeName, requestedSize string) error
- func (k *KubernetesCM) VolumeExists(ctx context.Context, name VolumeName) bool
- type KubernetesOptions
- type LitestreamAppSpec
- type LitestreamMount
- type LitestreamRestore
- type LitestreamRunner
- type NamespaceStats
- type PodCondition
- type PodContainerStatus
- type PodEvent
- type VersionReporter
- type VolumeInfo
- type VolumeInitializer
- type VolumeName
- type WorkloadMount
- type WorkloadPod
- func GetWorkloadPod(ctx context.Context, config *types.ServerConfig, name string) (*WorkloadPod, error)
- func ListWorkloadPods(ctx context.Context, config *types.ServerConfig) ([]WorkloadPod, error)
- func ListWorkloadPodsSelector(ctx context.Context, config *types.ServerConfig, selector string) ([]WorkloadPod, error)
- type WorkloadPodStatus
Constants ¶
const ( DOCKER_COMMAND = "docker" PODMAN_COMMAND = "podman" )
const ( DockerLocalhostBindingHostname = "host.docker.internal" OtherLocalhostBindingHostname = "host.containers.internal" )
const ( OPENRUN_FIELD_MANAGER = "openrun" KUBERNETES_NAME_MAX = 63 // Ownership labels used to identify objects (Secrets/ConfigMaps) generated // by OpenRun for a specific container, so snapshot/restore only ever lists, // overwrites, or deletes OpenRun-managed objects and never an unrelated // object that merely shares the common "app" label. MANAGED_BY_LABEL = "app.kubernetes.io/managed-by" INSTANCE_LABEL = "app.kubernetes.io/instance" MANAGED_BY_VALUE = "openrun" )
const DEV_HASH_LABEL = "dev.hash"
DEV_HASH_LABEL is the label key (under LABEL_PREFIX) stamped on dev mode containers with the run hash of their full runtime config
const DefaultLitestreamImage = "litestream/litestream:0.5"
DefaultLitestreamImage is the litestream image used for app restore and replicate containers when the named config does not pin one. Pinned to the 0.5 series: the LTX replica format ties restore compatibility to the bucket contents.
const IMAGE_NAME_PREFIX = "cli-"
const LABEL_PREFIX = "dev.openrun."
const LitestreamConfigFileName = "litestream.yml"
LitestreamConfigFileName is the rendered config file mounted into the litestream sidecar.
const UNNAMED_VOLUME = "<UNNAMED>"
const VERSION_HASH_LABEL = LABEL_PREFIX + "version.hash"
Variables ¶
var (
KNOWN_OPTIONS = []string{"cpus", "memory", "min_replicas", "max_replicas"}
)
Functions ¶
func BuildHTTPTransport ¶
func BuildHTTPTransport(r *types.RegistryConfig) (*http.Transport, error)
func BytesString ¶ added in v0.16.0
BytesString parses s and returns bytes as a base-10 integer string.
Rules: 1) If already an integer string (bytes), return as-is. 2) If docker-like (e.g., 512m, 1g), parse via Docker and return bytes. 3) Otherwise parse as k8s Quantity (e.g., 512Mi, 1Gi, 500M) and return bytes.
func CPUString ¶ added in v0.16.0
CPUString converts CPU from either docker-like ("0.5", "2") or k8s-like ("500m", "1") into a string that "makes sense" for the target.
- targetIsDocker=true => return cores as decimal string (e.g. "0.5", "2")
- targetIsDocker=false => return millicores as integer string (e.g. "500", "2000")
Notes:
- Bare "1" is treated as 1 core (not 1 millicore).
- For millicores input, use "m" suffix: "500m".
func ClusterRollbackClean ¶ added in v0.18.3
func CommandOptionArgs ¶ added in v0.17.0
func CommandOptionArgs(options CommandOptions, allowedContainerArgs map[string]string) ([]string, error)
CommandOptionArgs converts parsed container options into CLI args. Built-in OpenRun options are parsed explicitly. Any remaining Docker/Podman flags must be listed in allowedContainerArgs before they are emitted.
func ContextWithDeployTxn ¶ added in v0.18.3
func CreateOrUpdateSecret ¶
func CreateOrUpdateSecret(ctx context.Context, cs kubernetes.Interface, ns, name string, data map[string][]byte, typ corev1.SecretType) error
func DelegateHandler ¶
func DelegateHandler(r *http.Request, config *types.ServerConfig, logger *types.Logger) (any, error)
DelegateHandler is the handler for the delegated build API
func DigestPinned ¶ added in v0.17.3
DigestPinned returns image with the given digest appended, replacing any existing @digest suffix. For example:
("mycompany/jp-app:latest", "sha256:abc") -> "mycompany/jp-app:latest@sha256:abc"
("mycompany/jp-app@sha256:old", "sha256:new") -> "mycompany/jp-app@sha256:new"
("mycompany/jp-app:v1@sha256:old", "sha256:new") -> "mycompany/jp-app:v1@sha256:new"
("mycompany/jp-app", "sha256:abc") -> "mycompany/jp-app@sha256:abc"
Both Docker and Kubernetes accept "repo:tag@digest" references; when both are present the digest is authoritative. Returns image unchanged if either argument is empty.
func GenerateDockerConfigJSON ¶
func GenerateDockerConfigJSON(r *types.RegistryConfig) ([]byte, error)
func GetDockerConfig ¶
func GetImageReferenceConfig ¶ added in v0.18.3
func GetWorkloadPodLogs ¶ added in v0.18.4
func GetWorkloadPodLogs(ctx context.Context, config *types.ServerConfig, name string, tail int) (string, error)
GetWorkloadPodLogs returns the last tail lines of an OpenRun managed pod's logs
func GetWorkloadPodLogsStream ¶ added in v0.18.6
func GetWorkloadPodLogsStream(ctx context.Context, config *types.ServerConfig, name string, tail int, follow bool) (io.ReadCloser, error)
GetWorkloadPodLogsStream returns the logs of an OpenRun managed pod as a stream, optionally following new output. The caller closes the stream; canceling ctx also terminates it
func HasPersistentVolume ¶ added in v0.18.3
func HasPersistentVolume(volumes []*VolumeInfo) bool
HasPersistentVolume reports whether any mount is PVC-backed (a named volume or UNNAMED_VOLUME). Secrets (IsSecret) and config-maps (VolumeName == "") are per-pod and impose no single-writer constraint, so they are excluded. Under the default ReadWriteOnce access mode such a volume cannot be multi-attached, so its presence forces a downtime (Recreate) deploy rather than a surge-based rolling update.
TODO: exempt volumes once per-app ReadOnlyMany/ReadWriteMany access modes are supported.
func ImageExists ¶
func KanikoJob ¶
func KanikoJob(ctx context.Context, logger *types.Logger, cs kubernetes.Interface, cfg *rest.Config, r *types.RegistryConfig, dockerCfgJSON []byte, kb KanikoBuild) error
func LocalhostBindingHostname ¶ added in v0.18.0
LocalhostBindingHostname returns the hostname app containers should use to reach services bound to localhost on the OpenRun host.
func LocalhostHostGatewayArgs ¶ added in v0.18.0
LocalhostHostGatewayArgs returns runtime args needed for host.docker.internal to resolve inside Docker app containers.
func LookupContainerCommand ¶
func RedactEnvArgs ¶ added in v0.17.5
func RewriteLocalhostEndpoint ¶ added in v0.18.15
RewriteLocalhostEndpoint rewrites a localhost URL to the hostname containers use to reach the OpenRun host (e.g. host.docker.internal), for endpoints that must be reachable from inside app companion containers. Non-localhost endpoints are returned unchanged.
func TrimLabelValue ¶ added in v0.16.0
TrimLabelValue trims the input string to 63 characters so that it can be used as a Kubernetes label value
Types ¶
type AppContainerStopper ¶ added in v0.18.4
type AppContainerStopper interface {
StopAppContainersExcept(ctx context.Context, appId types.AppId, keep ContainerName) error
}
AppContainerStopper is an optional manager capability: stopping all of an app's version containers except the active one. Implemented by the command-based (Docker/Podman) manager, where superseded versions linger as separately named containers; Kubernetes cleans up through its own workload-cleanup path instead.
func AsAppContainerStopper ¶ added in v0.18.4
func AsAppContainerStopper(cm ContainerManager) (AppContainerStopper, bool)
AsAppContainerStopper unwraps any decorating container managers and returns the underlying AppContainerStopper if one is present.
type ClusterStats ¶ added in v0.18.6
type ClusterStats struct {
Version string `json:"version"`
Platform string `json:"platform"`
Nodes int `json:"nodes"`
ReadyNodes int `json:"ready_nodes"`
CPU string `json:"cpu"` // total allocatable cpu cores
Memory string `json:"memory"` // total allocatable memory
NodesError string `json:"nodes_error"` // set when node access is denied
}
ClusterStats summarizes the cluster as visible to a regular in-cluster service account: the server version (open to any authenticated principal) and node counts/capacity (cluster scoped, best-effort since RBAC may deny)
func GetClusterStats ¶ added in v0.18.6
func GetClusterStats(ctx context.Context, config *types.ServerConfig) (*ClusterStats, error)
GetClusterStats returns the cluster version and node summary
type CommandCM ¶ added in v0.16.0
func NewCommandCM ¶ added in v0.16.0
func (*CommandCM) BuildImage ¶ added in v0.16.0
func (*CommandCM) BuildImageTarget ¶ added in v0.18.15
func (c *CommandCM) BuildImageTarget(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, containerArgs map[string]string, buildTarget string) error
BuildImageTarget builds the image up to the named Containerfile stage (docker build --target). Used by dev mode to build the toolchain stage of a multi stage Containerfile instead of the runtime stage.
func (*CommandCM) ContainerExited ¶ added in v0.18.4
ContainerExited reports whether the named container is in a terminal state. Containers are run without a restart policy, so an exited container never recovers on its own and callers waiting on health can fail fast.
func (*CommandCM) DeployContainer ¶ added in v0.18.3
func (c *CommandCM) DeployContainer(ctx context.Context, req DeployRequest) (DeployResult, error)
func (*CommandCM) EnsureLitestreamSidecar ¶ added in v0.18.15
func (*CommandCM) ExecTailN ¶ added in v0.16.0
func (c *CommandCM) ExecTailN(ctx context.Context, command string, args []string, n int) ([]string, error)
ExecTailN executes a command and returns the last n lines of output
func (*CommandCM) GetContainerLogs ¶ added in v0.16.0
func (*CommandCM) GetContainerState ¶ added in v0.16.0
func (c *CommandCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)
GetContainerState returns the host:port of the running container, "" if not running. running is true if the container is running.
func (*CommandCM) GetDevContainerInfo ¶ added in v0.18.15
func (c *CommandCM) GetDevContainerInfo(ctx context.Context, name ContainerName, runHash string) (bool, bool, string, bool, error)
GetDevContainerInfo reports whether a container with the given name exists, whether it carries the given run hash label, its published host port and whether it is currently running, using a single listing call.
func (*CommandCM) ImageExists ¶ added in v0.16.0
func (*CommandCM) InitVolumePermissions ¶ added in v0.18.15
func (*CommandCM) ListOpenRunContainers ¶ added in v0.17.3
ListOpenRunContainers returns running containers started by THIS server installation, matched by the server.home ownership label. Scoping matters on a shared container daemon: the stale-container sweeper must never stop containers owned by another server (another OPENRUN_HOME, a test server, or a kubernetes-managed install whose pod containers carry the app.id label too). Containers started before the label existed are not returned
func (*CommandCM) RefreshImage ¶ added in v0.17.3
RefreshImage pulls the named image and returns its content-addressable digest. It first attempts to extract the manifest digest from RepoDigests (which is stable across container managers and matches the digest the registry advertises); it falls back to the image config digest (.Id) when the local image has no associated RepoDigests entry (e.g. it was built locally rather than pulled).
func (*CommandCM) RemoveContainer ¶ added in v0.16.0
func (c *CommandCM) RemoveContainer(ctx context.Context, name ContainerName) error
func (*CommandCM) RemoveImage ¶ added in v0.16.0
func (*CommandCM) RemoveSupersededImages ¶ added in v0.18.15
RemoveSupersededImages removes the app's generated images other than keep, cleaning up dev images left behind by image hash changes.
func (*CommandCM) RestartDevContainer ¶ added in v0.18.15
func (c *CommandCM) RestartDevContainer(ctx context.Context, name ContainerName) error
RestartDevContainer restarts (or starts, if stopped) a dev mode container with no stop grace period, prioritizing the dev feedback loop.
func (*CommandCM) RunContainer ¶ added in v0.16.0
func (c *CommandCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName, imageName ImageName, port int32, envMap map[string]string, volumes []*VolumeInfo, containerOptions map[string]string, paramMap map[string]string, versionHash string, isImageSpec bool, _ *HealthProbe) error
func (*CommandCM) RunDevContainer ¶ added in v0.18.15
func (c *CommandCM) RunDevContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName, imageName ImageName, port int32, envMap map[string]string, volumes []*VolumeInfo, containerOptions map[string]string, paramMap map[string]string, devOpts DevRunOptions) error
RunDevContainer runs a dev mode container with the fast reload options applied: run hash label, working dir override and app command override.
func (*CommandCM) RunLitestreamRestores ¶ added in v0.18.15
func (*CommandCM) StartContainer ¶ added in v0.16.0
func (c *CommandCM) StartContainer(ctx context.Context, name ContainerName) error
func (*CommandCM) StopAppContainersExcept ¶ added in v0.18.4
func (c *CommandCM) StopAppContainersExcept(ctx context.Context, appId types.AppId, keep ContainerName) error
StopAppContainersExcept stops all running containers of the given app other than keep. Containers are content-hash named, so after a committed update the previous version keeps running under its own name; this stops those superseded versions at operation commit instead of leaving them for the periodic stale container sweeper.
func (*CommandCM) StopContainer ¶ added in v0.16.0
func (c *CommandCM) StopContainer(ctx context.Context, name ContainerName) error
func (*CommandCM) StopLitestreamSidecar ¶ added in v0.18.15
func (*CommandCM) SupportsInPlaceUpdate ¶ added in v0.16.0
func (CommandCM) VolumeCreate ¶ added in v0.16.0
func (CommandCM) VolumeExists ¶ added in v0.16.0
func (c CommandCM) VolumeExists(ctx context.Context, name VolumeName) bool
type CommandOptions ¶ added in v0.16.0
type CommandOptions struct {
Cpus string `mapstructure:"cpus"`
Memory string `mapstructure:"memory"`
Other map[string]any `mapstructure:",remain"`
}
func ParseCommandOptions ¶ added in v0.17.0
func ParseCommandOptions(containerCommand string, options map[string]string) (CommandOptions, error)
type Container ¶
type Container struct {
ID string `json:"ID"`
Names string `json:"Names"`
Image string `json:"Image"`
State string `json:"State"`
Status string `json:"Status"`
PortString string `json:"Ports"`
LabelString string `json:"Labels"` // Docker format: "key=value,key=value"
Port int
Labels map[string]string `json:"-"` // Podman format, parsed from the JSON map
}
type ContainerExitChecker ¶ added in v0.18.4
type ContainerExitChecker interface {
// ContainerExited returns whether the named container has terminally
// exited, along with its status text (e.g. "Exited (1) 5 seconds ago")
// for error reporting. A missing container is not treated as exited.
ContainerExited(ctx context.Context, name ContainerName) (exited bool, status string, err error)
}
ContainerExitChecker is an optional manager capability: reporting whether a container is in a terminal state and cannot become healthy without outside intervention. Implemented by the command-based (Docker/Podman) manager, which runs containers without a restart policy, so an exited container never comes back on its own and health waits can fail fast. Kubernetes restarts crashed pods, so it does not implement this.
func AsContainerExitChecker ¶ added in v0.18.4
func AsContainerExitChecker(cm ContainerManager) (ContainerExitChecker, bool)
AsContainerExitChecker unwraps any decorating container managers and returns the underlying ContainerExitChecker if one is present.
type ContainerManager ¶
type ContainerManager interface {
BuildImage(ctx context.Context, name ImageName, sourceUrl, containerFile string, containerArgs map[string]string) error
ImageExists(ctx context.Context, name ImageName) (bool, error)
// RefreshImage pulls (or HEADs) the named image from its registry and returns a
// stable content-addressable digest (e.g. "sha256:..."). Only used for
// image-spec apps so the container handler can detect when the upstream
// reference has moved and recreate the container with the new content.
RefreshImage(ctx context.Context, name ImageName) (digest string, err error)
GetContainerState(ctx context.Context, name ContainerName, expectHash string) (hostPort string, running bool, err error)
StartContainer(ctx context.Context, name ContainerName) error
StopContainer(ctx context.Context, name ContainerName) error
RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName,
imageName ImageName, port int32, envMap map[string]string, volumes []*VolumeInfo,
containerOptions map[string]string, paramMap map[string]string, versionHash string, isImageSpec bool,
healthProbe *HealthProbe) error
DeployContainer(ctx context.Context, req DeployRequest) (DeployResult, error)
GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)
VolumeExists(ctx context.Context, name VolumeName) bool
// VolumeCreate creates the named volume. size is a requested capacity
// (kubernetes PVC size); empty means the manager default, and managers
// without sized volumes (docker/podman) ignore it.
VolumeCreate(ctx context.Context, name VolumeName, size string) error
SupportsInPlaceUpdate() bool
}
ContainerManager is the interface for managing containers
func WrapContainerManager ¶ added in v0.17.1
func WrapContainerManager(cm ContainerManager, kind string) ContainerManager
type ContainerName ¶
type ContainerName string
func GenContainerName ¶
func GenContainerName(appId types.AppId, contentHash string, supportsInPlaceUpdate bool) ContainerName
func LitestreamSidecarName ¶ added in v0.18.15
func LitestreamSidecarName(appId types.AppId) ContainerName
LitestreamSidecarName returns the app's replication companion container name. One stable sidecar per app (not per version): the brief old/new app container overlap during a reload must not run two litestream processes against one replica path.
type DelegateRequest ¶
type DeployRequest ¶ added in v0.18.3
type DeployRequest struct {
AppEntry *types.AppEntry
SourceDir string
ContainerName ContainerName
ImageName ImageName
Port int32
EnvMap map[string]string
Volumes []*VolumeInfo
ContainerOptions map[string]string
ParamMap map[string]string
VersionHash string
IsImageSpec bool
HealthProbe *HealthProbe
Verify bool
DeployAttempts int
LogLinesToShow int
ShowLogsForFailure bool
// Litestream, when set, adds the app's replication companion to the pod:
// per-database restore init containers and the replicate native sidecar.
Litestream *LitestreamAppSpec
}
type DeployResult ¶ added in v0.18.3
type DeployResult struct {
ContainerName ContainerName
VersionHash string
HostNamePort string
}
type DeployRollbackError ¶ added in v0.18.3
DeployRollbackError wraps a verification failure with the status of the cluster-side rollback, so callers can report accurately instead of always claiming "all changes have been reverted".
func (*DeployRollbackError) Error ¶ added in v0.18.3
func (e *DeployRollbackError) Error() string
func (*DeployRollbackError) Unwrap ¶ added in v0.18.3
func (e *DeployRollbackError) Unwrap() error
type DeployTxn ¶ added in v0.18.3
type DeployTxn struct {
// contains filtered or unexported fields
}
DeployTxn is an operation-level deploy stack for container deployments. A single reload/apply command may deploy several apps before a later app fails. Because the control-plane DB transaction commits or rolls back as a whole, the cluster must follow: each app that successfully deploys registers an onRollback and an onCommit closure here, and the server invokes RollbackAll on failure or CommitAll on success.
func DeployTxnFromContext ¶ added in v0.18.3
func NewDeployTxn ¶ added in v0.18.3
func NewDeployTxn() *DeployTxn
func (*DeployTxn) ContainerNames ¶ added in v0.18.4
func (d *DeployTxn) ContainerNames() []ContainerName
ContainerNames returns the containers touched by this operation. Unlike the entries, names are not drained by CommitAll/RollbackAll: they must keep protecting the operation's containers (e.g. from the stale container sweeper) until the owning scope unregisters the whole transaction.
func (*DeployTxn) Len ¶ added in v0.18.4
Len returns the number of registered deploy entries. Callers use it to scale commit/rollback time budgets with the operation size; it must be read before CommitAll/RollbackAll drain the entries.
type DevContainerManager ¶
type DevContainerManager interface {
ContainerManager
RemoveImage(ctx context.Context, name ImageName) error
// RemoveSupersededImages removes the app's generated images other than
// keep. A dev image hash change builds a new dev-<hash> tagged image; the
// previous images are never used again and would otherwise accumulate on
// the dev machine. Callers must remove containers using the old images
// first. Failure to remove an image is not fatal to a reload.
RemoveSupersededImages(ctx context.Context, keep ImageName) error
// RemoveContainer force-removes a dev container. Dev reloads prioritize a
// short feedback loop and must not wait for the runtime's graceful-stop
// timeout when replacing a container.
RemoveContainer(ctx context.Context, name ContainerName) error
// BuildImageTarget builds like BuildImage but stops at the named
// Containerfile stage (docker build --target). Empty target builds the
// full image.
BuildImageTarget(ctx context.Context, name ImageName, sourceUrl, containerFile string,
containerArgs map[string]string, buildTarget string) error
// RunDevContainer runs a dev mode container with the fast reload options
// applied (source mount workdir, command override, run hash label).
RunDevContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName,
imageName ImageName, port int32, envMap map[string]string, volumes []*VolumeInfo,
containerOptions map[string]string, paramMap map[string]string, devOpts DevRunOptions) error
// GetDevContainerInfo reports whether a container with the given name
// exists, whether it carries the given run hash label, its published host
// port and whether it is currently running, in one container listing call.
GetDevContainerInfo(ctx context.Context, name ContainerName, runHash string) (exists, matches bool, hostPort string, running bool, err error)
// RestartDevContainer restarts (or starts, if stopped) a dev mode
// container with no stop grace period, prioritizing the dev feedback loop.
RestartDevContainer(ctx context.Context, name ContainerName) error
}
DevContainerManager is the interface for managing containers in dev mode
type DevRunOptions ¶ added in v0.18.15
type DevRunOptions struct {
// RunHash identifies the full runtime config of the dev container. It is
// stamped as a label on the container so a reload can detect that the
// running container is already up to date and skip the recreate.
RunHash string
// WorkDir overrides the working directory (where the app source is mounted)
WorkDir string
// Command is the app start command, run via `sh -c`, overriding the image
// entrypoint and cmd. Empty means use the image entrypoint/cmd as is.
Command string
}
DevRunOptions carries the dev-mode fast reload options for RunDevContainer.
type ExistsResult ¶
func CheckImageReferenceExists ¶ added in v0.18.3
func CheckImageReferenceExists(ctx context.Context, logger *types.Logger, imageRef string, registryConfig *types.RegistryConfig) (ExistsResult, error)
func CheckImagesExists ¶
func CheckImagesExists(ctx context.Context, logger *types.Logger, imageRef string, registryConfig *types.RegistryConfig) (ExistsResult, error)
type HealthProbe ¶ added in v0.18.3
type HealthProbe struct {
Path string
Port int32
Scheme string // "HTTP" or "HTTPS"
PeriodSecs int32
TimeoutSecs int32
FailureThreshold int32 // steady-state readiness tolerance
StartupFailures int32 // startup probe tolerance for slow boots
}
HealthProbe describes an HTTP health check that a container manager can translate into a native readiness/startup probe. A nil *HealthProbe means no probe should be configured (e.g. command-lifetime apps or apps without a health URL).
type KanikoBuild ¶
type KubernetesCM ¶ added in v0.16.0
func NewKubernetesCM ¶ added in v0.16.0
func (*KubernetesCM) BuildImage ¶ added in v0.16.0
func (*KubernetesCM) CurrentVersionHash ¶ added in v0.18.3
func (k *KubernetesCM) CurrentVersionHash(ctx context.Context, name ContainerName) (string, error)
CurrentVersionHash returns the version hash the stable Service currently routes to. It is used by stale app handlers to avoid acting on a newer deployment. For stateless apps it is the Service selector's version hash; for PVC apps (version-agnostic selector) it is the active Deployment's pod hash.
func (*KubernetesCM) DeployContainer ¶ added in v0.18.3
func (k *KubernetesCM) DeployContainer(ctx context.Context, req DeployRequest) (DeployResult, error)
func (*KubernetesCM) GetContainerLogs ¶ added in v0.16.0
func (k *KubernetesCM) GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)
func (*KubernetesCM) GetContainerState ¶ added in v0.16.0
func (k *KubernetesCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)
func (*KubernetesCM) ImageExists ¶ added in v0.16.0
func (*KubernetesCM) PromoteVersion ¶ added in v0.18.3
func (k *KubernetesCM) PromoteVersion(ctx context.Context, serviceName ContainerName, versionHash string) (string, map[string]string, error)
PromoteVersion points the stable Service at versionHash and returns the version hash and selector that were previously active.
func (*KubernetesCM) RefreshImage ¶ added in v0.17.3
func (*KubernetesCM) RemoveVersion ¶ added in v0.18.3
func (k *KubernetesCM) RemoveVersion(ctx context.Context, serviceName ContainerName, versionHash string) error
RemoveVersion deletes the workload (Deployment plus owned HPA, Secrets and ConfigMaps) for one stateless version. A NotFound is treated as success.
func (*KubernetesCM) Restore ¶ added in v0.18.3
func (k *KubernetesCM) Restore(ctx context.Context, snapshot any) error
Restore reverts the Deployment, HPA, Secrets and ConfigMaps to the captured snapshot and deletes any of those objects that were created after it. It is best-effort: all steps run and the joined error (if any) is returned. PVC contents are not reverted.
func (*KubernetesCM) RunContainer ¶ added in v0.16.0
func (k *KubernetesCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName, imageName ImageName, port int32, envMap map[string]string, volumes []*VolumeInfo, containerOptions map[string]string, paramMap map[string]string, versionHash string, isImageSpec bool, healthProbe *HealthProbe) error
func (*KubernetesCM) Snapshot ¶ added in v0.18.3
func (k *KubernetesCM) Snapshot(ctx context.Context, name ContainerName) (any, error)
Snapshot captures the current Deployment plus the HPA, Secrets and ConfigMaps owned by the named container. Secrets/ConfigMaps are selected by the OpenRun ownership labels (see ownershipSelector) so only OpenRun-managed objects are captured, never an unrelated object sharing the "app" label.
func (*KubernetesCM) StartContainer ¶ added in v0.16.0
func (k *KubernetesCM) StartContainer(ctx context.Context, name ContainerName) error
func (*KubernetesCM) StopContainer ¶ added in v0.16.0
func (k *KubernetesCM) StopContainer(ctx context.Context, name ContainerName) error
func (*KubernetesCM) SupportsInPlaceUpdate ¶ added in v0.16.0
func (k *KubernetesCM) SupportsInPlaceUpdate() bool
func (*KubernetesCM) VolumeCreate ¶ added in v0.16.0
func (k *KubernetesCM) VolumeCreate(ctx context.Context, name VolumeName, requestedSize string) error
func (*KubernetesCM) VolumeExists ¶ added in v0.16.0
func (k *KubernetesCM) VolumeExists(ctx context.Context, name VolumeName) bool
type KubernetesOptions ¶ added in v0.16.0
type KubernetesOptions struct {
Cpus string `mapstructure:"cpus"`
Memory string `mapstructure:"memory"`
MinReplicas int32 `mapstructure:"min_replicas"` // min number of replicas to run the app on
MaxReplicas int32 `mapstructure:"max_replicas"` // max number of replicas to run the app on
Other map[string]any `mapstructure:",remain"`
}
type LitestreamAppSpec ¶ added in v0.18.15
type LitestreamAppSpec struct {
Image string
ConfigYAML string
// ConfigHash identifies the full replication config (rendered yaml,
// credentials, image); a change recreates the sidecar / rolls the pod.
ConfigHash string
Env map[string]string // LITESTREAM_ACCESS_KEY_ID / LITESTREAM_SECRET_ACCESS_KEY
Mounts []LitestreamMount
Restores []LitestreamRestore
}
LitestreamAppSpec describes the litestream replication companion for one app: the rendered config (credentials excluded, passed via Env), the volume shared with the app container, and the databases to restore before the app starts. An app has at most one sqlite binding, so a single litestream config (endpoint, credentials, image) applies.
type LitestreamMount ¶ added in v0.18.15
type LitestreamMount struct {
VolumeName VolumeName
TargetDir string // mount path, same as in the app container
}
LitestreamMount is one app volume the litestream companion shares.
type LitestreamRestore ¶ added in v0.18.15
type LitestreamRestore struct {
ReplicaURL string // s3://bucket/path?endpoint=... (no credentials)
OutputPath string // path inside the shared volume mount
}
LitestreamRestore is one database to restore before the app starts: litestream restore is per-file, the caller enumerates the replica.
type LitestreamRunner ¶ added in v0.18.15
type LitestreamRunner interface {
// RunLitestreamRestores runs the pre-start restore step: one one-shot
// container per database, restoring files missing from the volume.
RunLitestreamRestores(ctx context.Context, appId types.AppId, spec *LitestreamAppSpec) error
// EnsureLitestreamSidecar starts (or recreates, on config change) the
// app's replication sidecar container.
EnsureLitestreamSidecar(ctx context.Context, appEntry *types.AppEntry, spec *LitestreamAppSpec) error
// StopLitestreamSidecar gently stops the app's replication sidecar:
// SIGTERM with a grace period covering litestream's final shutdown sync.
// A missing or already stopped sidecar is not an error.
StopLitestreamSidecar(ctx context.Context, appId types.AppId) error
}
LitestreamRunner is the optional manager capability for running the litestream restore step and replication sidecar. Implemented by the command-based (docker/podman) manager; kubernetes handles litestream declaratively inside the pod spec via DeployRequest.Litestream.
func AsLitestreamRunner ¶ added in v0.18.15
func AsLitestreamRunner(cm ContainerManager) (LitestreamRunner, bool)
AsLitestreamRunner unwraps any decorating container managers and returns the underlying LitestreamRunner if one is present.
type NamespaceStats ¶ added in v0.18.6
type NamespaceStats struct {
Namespace string `json:"namespace"`
Kind string `json:"kind"` // system / apps
Pods int `json:"pods"`
Running int `json:"running"`
Pending int `json:"pending"`
Failed int `json:"failed"`
Succeeded int `json:"succeeded"`
Ready int `json:"ready"`
}
NamespaceStats summarizes the pods of one OpenRun kubernetes namespace
func GetNamespaceStats ¶ added in v0.18.6
func GetNamespaceStats(ctx context.Context, config *types.ServerConfig) ([]NamespaceStats, error)
GetNamespaceStats returns pod stats for the OpenRun system namespace and the apps namespace
type PodCondition ¶ added in v0.18.6
type PodCondition struct {
Type string `json:"type"`
Status string `json:"status"`
Reason string `json:"reason"`
Message string `json:"message"`
}
PodCondition is one kubernetes pod condition
type PodContainerStatus ¶ added in v0.18.6
type PodContainerStatus struct {
Name string `json:"name"`
State string `json:"state"` // running / waiting / terminated
Reason string `json:"reason"`
Message string `json:"message"`
Restarts int `json:"restarts"`
Ready bool `json:"ready"`
}
PodContainerStatus is the state of one container of a pod
type PodEvent ¶ added in v0.18.6
type PodEvent struct {
Type string `json:"type"` // Normal / Warning
Reason string `json:"reason"`
Message string `json:"message"`
Count int `json:"count"`
LastSeen string `json:"last_seen"`
}
PodEvent is one kubernetes event of a pod, newest first
type VersionReporter ¶ added in v0.18.3
type VersionReporter interface {
CurrentVersionHash(ctx context.Context, name ContainerName) (string, error)
}
VersionReporter is implemented by managers that can report the version hash currently configured on a live workload.
func AsVersionReporter ¶ added in v0.18.3
func AsVersionReporter(cm ContainerManager) (VersionReporter, bool)
AsVersionReporter unwraps any decorating container managers and returns the underlying VersionReporter if one is present.
type VolumeInfo ¶
type VolumeInfo struct {
IsSecret bool
VolumeName string
SourcePath string
TargetPath string
ReadOnly bool
// Size requests a capacity for the backing volume where the manager
// supports it (kubernetes PVC size). Empty means the manager default;
// ignored for docker/podman named volumes, which are not sized.
Size string
// InitPerms marks a volume whose mount directory must be made writable
// for the app image's (possibly non-root) user after creation (sqlite
// binding volumes): a fresh named volume / PVC mount is root-owned.
InitPerms bool
}
type VolumeInitializer ¶ added in v0.18.15
type VolumeInitializer interface {
InitVolumePermissions(ctx context.Context, image ImageName, volumeName VolumeName, targetDir string) error
}
VolumeInitializer is the optional manager capability for preparing a freshly created named volume for the app user: a new docker volume mount directory is root-owned, which a non-root app image (USER directives are common) cannot write to. The chmod runs with the app's own image, which is guaranteed present, as root.
func AsVolumeInitializer ¶ added in v0.18.15
func AsVolumeInitializer(cm ContainerManager) (VolumeInitializer, bool)
AsVolumeInitializer unwraps any decorating container managers and returns the underlying VolumeInitializer if one is present.
type VolumeName ¶
type VolumeName string
func GenVolumeName ¶
func GenVolumeName(appId types.AppId, dirName string) VolumeName
type WorkloadMount ¶ added in v0.18.4
WorkloadMount is a volume mount of a workload pod
type WorkloadPod ¶ added in v0.18.4
type WorkloadPod struct {
Name string
AppId string
AppPath string
AppVersion string
Image string
Phase string // Running / Pending / Succeeded / Failed
Ready bool
Restarts int
StartedAt string
CreatedAt string
Node string
PodIP string
Mounts []WorkloadMount
}
WorkloadPod is the status of one pod in the OpenRun apps namespace
func GetWorkloadPod ¶ added in v0.18.4
func GetWorkloadPod(ctx context.Context, config *types.ServerConfig, name string) (*WorkloadPod, error)
GetWorkloadPod returns the status of one OpenRun managed pod
func ListWorkloadPods ¶ added in v0.18.4
func ListWorkloadPods(ctx context.Context, config *types.ServerConfig) ([]WorkloadPod, error)
ListWorkloadPods lists the OpenRun managed pods in the apps namespace
func ListWorkloadPodsSelector ¶ added in v0.18.6
func ListWorkloadPodsSelector(ctx context.Context, config *types.ServerConfig, selector string) ([]WorkloadPod, error)
ListWorkloadPodsSelector lists namespace pods matching a label selector (e.g. app=kaniko for the image build pods)
type WorkloadPodStatus ¶ added in v0.18.6
type WorkloadPodStatus struct {
Phase string `json:"phase"`
Reason string `json:"reason"`
Message string `json:"message"`
Node string `json:"node"`
Conditions []PodCondition `json:"conditions"`
Containers []PodContainerStatus `json:"containers"`
Events []PodEvent `json:"events"`
EventsError string `json:"events_error"` // events are best-effort, RBAC may deny them
}
WorkloadPodStatus is the kubernetes specific status of one managed pod: pod conditions, per-container states and recent events (the information kubectl describe surfaces)
func GetWorkloadPodStatus ¶ added in v0.18.6
func GetWorkloadPodStatus(ctx context.Context, config *types.ServerConfig, name string) (*WorkloadPodStatus, error)
GetWorkloadPodStatus returns the kubernetes specific status of one OpenRun managed pod