utils

package
v0.1.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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

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 ForceFlag added in v0.1.5

func ForceFlag(usage string) *cli.BoolFlag

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 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 Positional added in v0.1.5

func Positional(name, usage string, max int) []cli.Argument

Positional declares one required positional argument, max -1 for an unlimited list.

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, error)

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