Documentation
¶
Overview ¶
Package unit provides quadlet unit generation and management functionality
Index ¶
- Variables
- func ApplyDependencyRelationships(unit *QuadletUnit, serviceName string, dependencyGraph *ServiceDependencyGraph, ...) error
- func GenerateQuadletUnit(unit QuadletUnit) string
- func GetUnitStatus(unitName string, unitType string) (string, error)deprecated
- func ProcessComposeProjects(projects []*types.Project, force bool, existingProcessedUnits map[string]bool, ...) (map[string]bool, error)
- func ReloadSystemd() error
- func ResetFailedUnit(unitName string, unitType string) errordeprecated
- func RestartChangedUnits(changedUnits []QuadletUnit, ...) error
- func RestartUnit(unitName string, unitType string) errordeprecated
- func ShowUnit(unitName string, unitType string) errordeprecated
- func StartUnit(unitName string, unitType string) errordeprecated
- func StartUnitDependencyAware(unitName string, unitType string, dependencyGraph *ServiceDependencyGraph) error
- func StopUnit(unitName string, unitType string) errordeprecated
- type BaseSystemdUnit
- func (u *BaseSystemdUnit) GetServiceName() string
- func (u *BaseSystemdUnit) GetStatus() (string, error)
- func (u *BaseSystemdUnit) GetUnitName() string
- func (u *BaseSystemdUnit) GetUnitType() string
- func (u *BaseSystemdUnit) ResetFailed() error
- func (u *BaseSystemdUnit) Restart() error
- func (u *BaseSystemdUnit) Show() error
- func (u *BaseSystemdUnit) Start() error
- func (u *BaseSystemdUnit) Stop() error
- type BaseUnit
- func (u *BaseUnit) GetServiceName() string
- func (u *BaseUnit) GetStatus() (string, error)
- func (u *BaseUnit) GetUnitName() string
- func (u *BaseUnit) GetUnitType() string
- func (u *BaseUnit) ResetFailed() error
- func (u *BaseUnit) Restart() error
- func (u *BaseUnit) Show() error
- func (u *BaseUnit) Start() error
- func (u *BaseUnit) Stop() error
- type Build
- type Change
- type CleanupOrphanedUnitsFunc
- type Container
- type Network
- type ProcessUnitFunc
- type QuadletUnit
- type Repository
- type SQLRepository
- type Secret
- type ServiceDependencyGraph
- func (sdg *ServiceDependencyGraph) AddDependency(dependent, dependency string) error
- func (sdg *ServiceDependencyGraph) AddService(serviceName string) error
- func (sdg *ServiceDependencyGraph) GetDependencies(serviceName string) ([]string, error)
- func (sdg *ServiceDependencyGraph) GetDependents(serviceName string) ([]string, error)
- func (sdg *ServiceDependencyGraph) GetTopologicalOrder() ([]string, error)
- func (sdg *ServiceDependencyGraph) HasCycles() bool
- type SystemdConfig
- type SystemdUnit
- type Unit
- type UpdateUnitDatabaseFunc
- type Volume
- type WriteUnitFileFunc
Constants ¶
This section is empty.
Variables ¶
var ( ProcessUnit ProcessUnitFunc = processUnit CleanupOrphanedUnits CleanupOrphanedUnitsFunc = cleanupOrphanedUnits WriteUnitFile WriteUnitFileFunc = writeUnitFile UpdateUnitDatabase UpdateUnitDatabaseFunc = updateUnitDatabase )
Package variables for testing.
Functions ¶
func ApplyDependencyRelationships ¶ added in v0.4.0
func ApplyDependencyRelationships(unit *QuadletUnit, serviceName string, dependencyGraph *ServiceDependencyGraph, projectName string) error
ApplyDependencyRelationships applies dependencies to a quadlet unit based on the dependency graph.
func GenerateQuadletUnit ¶
func GenerateQuadletUnit(unit QuadletUnit) string
GenerateQuadletUnit generates a quadlet unit file content from a unit configuration.
func GetUnitStatus
deprecated
func ProcessComposeProjects ¶ added in v0.4.0
func ProcessComposeProjects(projects []*types.Project, force bool, existingProcessedUnits map[string]bool, doCleanup bool) (map[string]bool, error)
ProcessComposeProjects processes Docker Compose projects and converts them to Podman systemd units. It accepts an existing processedUnits map to track units across multiple repository calls and a cleanup flag to control when orphaned unit cleanup should occur.
func ResetFailedUnit
deprecated
added in
v0.9.0
func RestartChangedUnits ¶ added in v0.4.0
func RestartChangedUnits(changedUnits []QuadletUnit, projectDependencyGraphs map[string]*ServiceDependencyGraph) error
RestartChangedUnits restarts all changed units in dependency-aware order.
func RestartUnit
deprecated
func StartUnitDependencyAware ¶ added in v0.4.0
func StartUnitDependencyAware(unitName string, unitType string, dependencyGraph *ServiceDependencyGraph) error
StartUnitDependencyAware starts or restarts a unit while being dependency-aware.
Types ¶
type BaseSystemdUnit ¶ added in v0.3.0
BaseSystemdUnit provides common implementation for all systemd units.
func (*BaseSystemdUnit) GetServiceName ¶ added in v0.3.0
func (u *BaseSystemdUnit) GetServiceName() string
GetServiceName returns the full systemd service name based on unit type.
func (*BaseSystemdUnit) GetStatus ¶ added in v0.3.0
func (u *BaseSystemdUnit) GetStatus() (string, error)
GetStatus returns the current status of the unit.
func (*BaseSystemdUnit) GetUnitName ¶ added in v0.3.0
func (u *BaseSystemdUnit) GetUnitName() string
GetUnitName returns the name of the unit.
func (*BaseSystemdUnit) GetUnitType ¶ added in v0.3.0
func (u *BaseSystemdUnit) GetUnitType() string
GetUnitType returns the type of the unit.
func (*BaseSystemdUnit) ResetFailed ¶ added in v0.9.0
func (u *BaseSystemdUnit) ResetFailed() error
ResetFailed resets the failed state of the unit.
func (*BaseSystemdUnit) Restart ¶ added in v0.3.0
func (u *BaseSystemdUnit) Restart() error
Restart restarts the unit.
func (*BaseSystemdUnit) Show ¶ added in v0.3.0
func (u *BaseSystemdUnit) Show() error
Show displays the unit configuration and status.
func (*BaseSystemdUnit) Start ¶ added in v0.3.0
func (u *BaseSystemdUnit) Start() error
Start starts the unit.
func (*BaseSystemdUnit) Stop ¶ added in v0.3.0
func (u *BaseSystemdUnit) Stop() error
Stop stops the unit.
type BaseUnit ¶ added in v0.9.0
BaseUnit provides common fields and methods for all unit types.
func (*BaseUnit) GetServiceName ¶ added in v0.9.0
GetServiceName returns the full systemd service name based on unit type.
func (*BaseUnit) GetUnitName ¶ added in v0.9.0
GetUnitName returns the name of the unit.
func (*BaseUnit) GetUnitType ¶ added in v0.9.0
GetUnitType returns the type of the unit.
func (*BaseUnit) ResetFailed ¶ added in v0.9.0
ResetFailed resets the failed state of the unit.
type Build ¶ added in v0.9.0
type Build struct {
BaseUnit // Embed the base struct
ImageTag []string // Specifies the name which is assigned to the resulting image
File string // Path to Containerfile/Dockerfile
SetWorkingDirectory string // Sets the working directory for the build context
Label []string // Add metadata to the resulting image
Annotation []string // Add OCI annotations to the resulting image
Env map[string]string // Environment variables for the build process
Secret []string // Pass secret information for build
Network []string // Set network mode for RUN instructions
Pull string // Pull policy for base images (always, missing, never, newer)
Volume []string // Mount volumes for build process
Target string // Set the target build stage to build
PodmanArgs []string // Additional arguments to pass to podman build
}
Build represents the configuration for a build unit.
func (*Build) FromComposeBuild ¶ added in v0.9.0
func (b *Build) FromComposeBuild(buildConfig types.BuildConfig, service types.ServiceConfig, projectName string) *Build
FromComposeBuild converts a Docker Compose build configuration to a Podman Quadlet build configuration.
type CleanupOrphanedUnitsFunc ¶ added in v0.5.0
type CleanupOrphanedUnitsFunc func(unitRepo Repository, processedUnits map[string]bool) error
CleanupOrphanedUnitsFunc is the function signature for cleaning up orphaned units.
type Container ¶ added in v0.3.0
type Container struct {
BaseUnit // Embed the base struct
Image string
Label []string
PublishPort []string
Environment map[string]string
// Environment file paths (will be sorted for deterministic output)
EnvironmentFile []string
Volume []string
Network []string
NetworkAlias []string
Exec []string
Entrypoint []string
User string
Group string
WorkingDir string
RunInit *bool
// Privileged removed - not supported by podman-systemd
ReadOnly bool
// SecurityLabel removed - not supported by podman-systemd
// Use SecurityLabelType, SecurityLabelLevel, etc. instead
HostName string
ContainerName string
Secrets []Secret
// PodmanArgs contains direct podman run arguments for features not supported by Quadlet
PodmanArgs []string
// Health check settings
HealthCmd []string
HealthInterval string
HealthTimeout string
HealthRetries int
HealthStartPeriod string
HealthStartInterval string
// Resource constraints
Memory string
MemoryReservation string
MemorySwap string
CPUQuota int64
CPUPeriod int64
PidsLimit int64
// Advanced container configuration
Ulimit []string
Sysctl map[string]string
Tmpfs []string
UserNS string
// Logging and monitoring configuration
LogDriver string
LogOpt map[string]string
RestartPolicy string
// contains filtered or unexported fields
}
Container represents the configuration for a container unit.
func NewContainer ¶ added in v0.3.0
NewContainer creates a new Container with the given name.
func (*Container) FromComposeService ¶ added in v0.4.0
func (c *Container) FromComposeService(service types.ServiceConfig, projectName string) *Container
FromComposeService converts a Docker Compose service to a Podman Quadlet container configuration.
type Network ¶ added in v0.3.0
type Network struct {
BaseUnit // Embed the base struct
Label []string `yaml:"label"`
Driver string `yaml:"driver"`
Gateway string `yaml:"gateway"`
IPRange string `yaml:"ip_range"`
Subnet string `yaml:"subnet"`
IPv6 bool `yaml:"ipv6"`
Internal bool `yaml:"internal"`
// DNSEnabled removed - not supported by podman-systemd
Options []string `yaml:"options"`
NetworkName string `yaml:"network_name"`
}
Network represents the configuration for a network in a Quadlet unit.
func NewNetwork ¶ added in v0.3.0
NewNetwork creates a new Network with the given name.
func (*Network) FromComposeNetwork ¶ added in v0.4.0
func (n *Network) FromComposeNetwork(name string, network types.NetworkConfig) *Network
FromComposeNetwork creates a Network from a Docker Compose network configuration.
type ProcessUnitFunc ¶ added in v0.5.0
type ProcessUnitFunc func(unitRepo Repository, unit *QuadletUnit, force bool, processedUnits map[string]bool, changedUnits *[]QuadletUnit) error
ProcessUnitFunc is the function signature for processing a single quadlet unit.
type QuadletUnit ¶
type QuadletUnit struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Systemd SystemdConfig `yaml:"systemd"`
Container Container `yaml:"container,omitempty"`
Volume Volume `yaml:"volume,omitempty"`
Network Network `yaml:"network,omitempty"`
Build Build `yaml:"build,omitempty"`
}
QuadletUnit represents the configuration for a Quadlet unit, which can include systemd, container, volume, network, pod, Kubernetes, image, and build settings.
func (*QuadletUnit) GetSystemdUnit ¶ added in v0.3.0
func (u *QuadletUnit) GetSystemdUnit() SystemdUnit
GetSystemdUnit returns the appropriate SystemdUnit implementation for this QuadletUnit.
type Repository ¶
type Repository interface {
FindAll() ([]Unit, error)
FindByUnitType(unitType string) ([]Unit, error)
FindByID(id int64) (Unit, error)
Create(unit *Unit) (int64, error)
Delete(id int64) error
}
Repository defines the interface for unit data access operations.
func NewUnitRepository ¶
func NewUnitRepository(db *sql.DB) Repository
NewUnitRepository creates a new SQL-based unit repository.
type SQLRepository ¶ added in v0.3.0
type SQLRepository struct {
// contains filtered or unexported fields
}
SQLRepository implements UnitRepository interface with SQL database.
func (*SQLRepository) Create ¶ added in v0.3.0
func (r *SQLRepository) Create(unit *Unit) (int64, error)
Create inserts or updates a unit in the database.
func (*SQLRepository) Delete ¶ added in v0.3.0
func (r *SQLRepository) Delete(id int64) error
Delete removes a unit from the database.
func (*SQLRepository) FindAll ¶ added in v0.3.0
func (r *SQLRepository) FindAll() ([]Unit, error)
FindAll retrieves all units from the database.
func (*SQLRepository) FindByID ¶ added in v0.3.0
func (r *SQLRepository) FindByID(id int64) (Unit, error)
FindByID retrieves a single unit by ID.
func (*SQLRepository) FindByUnitType ¶ added in v0.3.0
func (r *SQLRepository) FindByUnitType(unitType string) ([]Unit, error)
FindByUnitType retrieves units filtered by type.
type ServiceDependencyGraph ¶ added in v0.10.0
type ServiceDependencyGraph struct {
// contains filtered or unexported fields
}
ServiceDependencyGraph represents the dependency relationships between services using a directed graph.
func BuildServiceDependencyGraph ¶ added in v0.10.0
func BuildServiceDependencyGraph(project *types.Project) (*ServiceDependencyGraph, error)
BuildServiceDependencyGraph builds a dependency graph for all services in a project.
func NewServiceDependencyGraph ¶ added in v0.10.0
func NewServiceDependencyGraph() *ServiceDependencyGraph
NewServiceDependencyGraph creates a new service dependency graph.
func (*ServiceDependencyGraph) AddDependency ¶ added in v0.10.0
func (sdg *ServiceDependencyGraph) AddDependency(dependent, dependency string) error
AddDependency adds a dependency relationship where dependent depends on dependency.
func (*ServiceDependencyGraph) AddService ¶ added in v0.10.0
func (sdg *ServiceDependencyGraph) AddService(serviceName string) error
AddService adds a service to the dependency graph.
func (*ServiceDependencyGraph) GetDependencies ¶ added in v0.10.0
func (sdg *ServiceDependencyGraph) GetDependencies(serviceName string) ([]string, error)
GetDependencies returns the services that the given service depends on.
func (*ServiceDependencyGraph) GetDependents ¶ added in v0.10.0
func (sdg *ServiceDependencyGraph) GetDependents(serviceName string) ([]string, error)
GetDependents returns the services that depend on the given service.
func (*ServiceDependencyGraph) GetTopologicalOrder ¶ added in v0.10.0
func (sdg *ServiceDependencyGraph) GetTopologicalOrder() ([]string, error)
GetTopologicalOrder returns services in topological order (dependencies first).
func (*ServiceDependencyGraph) HasCycles ¶ added in v0.10.0
func (sdg *ServiceDependencyGraph) HasCycles() bool
HasCycles checks if the dependency graph contains cycles.
type SystemdConfig ¶
type SystemdConfig struct {
Description string `yaml:"description"`
After []string `yaml:"after"`
Before []string `yaml:"before"`
Requires []string `yaml:"requires"`
Wants []string `yaml:"wants"`
Conflicts []string `yaml:"conflicts"`
PartOf []string `yaml:"part_of"` // Services that this unit is part of
PropagatesReloadTo []string `yaml:"propagates_reload_to"` // Services that should be reloaded when this unit is reloaded
RestartPolicy string `yaml:"restart_policy"`
TimeoutStartSec int `yaml:"timeout_start_sec"`
Type string `yaml:"type"`
RemainAfterExit bool `yaml:"remain_after_exit"`
WantedBy []string `yaml:"wanted_by"`
}
SystemdConfig represents the configuration for a systemd unit. It includes settings such as the unit description, dependencies, restart policy, and other systemd-specific options.
type SystemdUnit ¶ added in v0.3.0
type SystemdUnit interface {
// GetServiceName returns the full systemd service name
GetServiceName() string
// GetUnitType returns the type of the unit (container, volume, network, etc.)
GetUnitType() string
// GetUnitName returns the name of the unit
GetUnitName() string
// GetStatus returns the current status of the unit
GetStatus() (string, error)
// Start starts the unit
Start() error
// Stop stops the unit
Stop() error
// Restart restarts the unit
Restart() error
// Show displays the unit configuration and status
Show() error
// ResetFailed resets the failed state of the unit
ResetFailed() error
}
SystemdUnit defines the interface for managing systemd units.
type Unit ¶
type Unit struct {
ID int64 `db:"id"`
Name string `db:"name"`
Type string `db:"type"`
CleanupPolicy string `db:"cleanup_policy"`
SHA1Hash []byte `db:"sha1_hash"`
UserMode bool `db:"user_mode"`
CreatedAt time.Time `db:"created_at"` // Set by database, but not updated on every change
}
Unit represents a record in the units table.
type UpdateUnitDatabaseFunc ¶ added in v0.5.0
type UpdateUnitDatabaseFunc func(unitRepo Repository, unit *QuadletUnit, content string) error
UpdateUnitDatabaseFunc is the function signature for updating the unit database.
type Volume ¶ added in v0.3.0
type Volume struct {
BaseUnit // Embed the base struct
ContainersConfModule []string `yaml:"containers_conf_module"`
Copy bool `yaml:"copy"`
Device string `yaml:"device"`
Driver string `yaml:"driver"`
GlobalArgs []string `yaml:"global_args"`
Group string `yaml:"group"`
Image string `yaml:"image"`
Label []string `yaml:"label"`
Options []string `yaml:"options"`
PodmanArgs []string `yaml:"podman_args"`
Type string `yaml:"type"`
User string `yaml:"user"`
VolumeName string `yaml:"volume_name"`
}
Volume represents the configuration for a volume in a Quadlet unit.
func (*Volume) FromComposeVolume ¶ added in v0.4.0
func (v *Volume) FromComposeVolume(name string, volume types.VolumeConfig) *Volume
FromComposeVolume creates a Volume from a Docker Compose volume configuration.
type WriteUnitFileFunc ¶ added in v0.5.0
WriteUnitFileFunc is the function signature for writing a unit file.