utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceCPUMem  = "cpumem"
	ResourceStorage = "resource-storage"

	FlagExtraResources = "extra-resources"
)

Variables

This section is empty.

Functions

func EachMessage

func EachMessage[T any](recv recvFunc[T], fn func(*T) error) error

func EncodeResources

func EncodeResources(cmd *cli.Command, resources resourcetypes.Resources) (map[string][]byte, error)

EncodeResources encodes plugin params for the core rpc; --extra-resources fills only the plugins not already present.

func EnvParser

func EnvParser(b []byte) ([]byte, error)

EnvParser expands Go template references to environment variables in b.

func ExitCoder

func ExitCoder(f cli.ActionFunc) cli.ActionFunc

ExitCoder turns an action error into a cli.ExitCoder.

func GetHostname

func GetHostname() string

GetHostname returns the local hostname, empty when it cannot be read.

func GetNetworks

func GetNetworks(network string) map[string]string

GetNetworks returns a networkmode -> ip map.

func GetSpecFromRemote

func GetSpecFromRemote(ctx context.Context, uri string) ([]byte, error)

GetSpecFromRemote fetches a spec over HTTP.

func NewCoreRPCClient

func NewCoreRPCClient(ctx context.Context, cmd *cli.Command) (corepb.CoreRPCClient, error)

NewCoreRPCClient dials the core address in cmd and returns its RPC client.

func ParseDeployStrategy

func ParseDeployStrategy(name string) (corepb.DeployOptions_Strategy, error)

ParseDeployStrategy maps a --deploy-strategy value onto the core enum.

func ParseRAMInHuman

func ParseRAMInHuman(ram string) (int64, error)

ParseRAMInHuman parses a human-readable size ("100KB", "-1T") into bytes; the implementation lives with core's RawParams.

func ReadAllFiles

func ReadAllFiles(files []string) (map[string]*types.LinuxFile, error)

ReadAllFiles reads srcfile:dstfile[:mode[:uid:gid]] pairs into a dstfile keyed map.

func SplitEquality

func SplitEquality(elements []string) map[string]string

SplitEquality turns a list of key=value strings into a map.

func SplitFiles

func SplitFiles(files []string) map[string]string

SplitFiles turns a list of src:dst strings into a map.

func StorageParams added in v0.1.2

func StorageParams(storageRequest, storageLimit int64, volumesRequest, volumesLimit []string) resourcetypes.RawParams

StorageParams builds the storage plugin request; zero values stay out, so an untouched entry defers to --extra-resources.

func StreamToChan

func StreamToChan[T any](recv recvFunc[T]) (<-chan *T, func() error)

StreamToChan returns a wait func that reports the recv error once the channel is drained.

func TarDirectory added in v0.1.1

func TarDirectory(dir string) ([]byte, error)

TarDirectory packs dir into an uncompressed tar whose entry names are relative to dir.

Types

type FileOptions

type FileOptions struct {
	Data   map[string][]byte
	Modes  map[string]*corepb.FileMode
	Owners map[string]*corepb.FileOwner
}

FileOptions carries the --file pairs in the shape the core rpc expects.

func GenerateFileOptions

func GenerateFileOptions(cmd *cli.Command) (*FileOptions, error)

Jump to

Keyboard shortcuts

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