utils

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

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

	FlagExtraResources = "extra-resources"
	FlagFile           = "file"
)

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 ExtraResourcesFlag added in v0.1.4

func ExtraResourcesFlag() *cli.StringFlag

ExtraResourcesFlag is the one --extra-resources every resource-taking command shares.

func FileFlag added in v0.1.4

func FileFlag(usage string) *cli.StringSliceFlag

FileFlag is the one --file every file-carrying command shares; usage says what the command does with the files.

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 ReadSpecURI added in v0.1.4

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

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)

type FileSpec added in v0.1.4

type FileSpec struct {
	Src  string
	Dst  string
	File types.LinuxFile
}

FileSpec is one --file value: a local path and where it lands in the workload.

func ParseFileSpec added in v0.1.4

func ParseFileSpec(file string) (*FileSpec, error)

ParseFileSpec parses src:dst[:mode[:uid:gid]] without touching the file.

Jump to

Keyboard shortcuts

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