util

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamespaceSeparator = '_'
)

Variables

View Source
var (
	// VERSION is set during the build from the file at itzo/version
	VERSION string = ""
	// GIT_REVISION and GIT_DIRTY are set during build.
	GIT_REVISION string = ""
	GIT_DIRTY    string = ""
)
View Source
var (
	MaxBufferSize int64 = 1024 * 1024 * 10 // 10MB
)

Functions

func APIEnvVarsToMap

func APIEnvVarsToMap(envs []api.EnvVar) map[string]string

V1EnvVarsToMap constructs a map of environment name to value from a slice of env vars.

func AddToEnvList

func AddToEnvList(env []string, key string, value string, overwrite bool) []string

Add an entry to the list of environment variables. Also removes duplicate entries, only keeping the last one.

func CopyFile added in v1.2.0

func CopyFile(src, dst string) error

func EnsureFileExists added in v1.2.0

func EnsureFileExists(name string) error

func EnsureProg

func EnsureProg(prog, downloadURL, minVersion, versionArg string) (string, error)

func EnvironToAPIEnvVar

func EnvironToAPIEnvVar(envs []string) []api.EnvVar

func ExpandContainerCommandOnlyStatic

func ExpandContainerCommandOnlyStatic(containerCommand []string, envs []api.EnvVar) (command []string)

ExpandContainerCommandOnlyStatic substitutes only static environment variable values from the container environment definitions. This does *not* include valueFrom substitutions. TODO: callers should use ExpandContainerCommandAndArgs with a fully resolved list of environment.

func FindPortByName added in v1.2.0

func FindPortByName(unit *api.Unit, portName string) (int, error)

findPortByName is a helper function to look up a port in a container by name.

func GetNameFromString

func GetNameFromString(n string) string

func GetNamespaceFromString

func GetNamespaceFromString(n string) string

func GetNumberOfFreeAndAvailableBlocks

func GetNumberOfFreeAndAvailableBlocks(path string) (uint64, uint64, error)

func GetRepoCreds added in v1.2.0

func GetRepoCreds(server string, allCreds map[string]api.RegistryCredentials) (string, string)

Dockerhub can go by several names that the user can specify in their image spec. .docker/config.json uses index.docker.io but an empty server should also map to that. We have used registry-1.docker.io internally and users might also just say "docker.io". Try to find the server that shows up in the credentials sent over from kip.

func InstallProg

func InstallProg(url, path string) error

func IsEmptyDir added in v1.2.0

func IsEmptyDir(name string) (bool, error)

func LookupUser

func LookupUser(userspec string, lookup UserLookup) (uint32, uint32, string, error)

func MapDiff

func MapDiff(spec, status map[string]interface{}) ([]string, []string, []string)

func Minint64

func Minint64(a, b int64) int64

func ParseImageSpec

func ParseImageSpec(image string) (string, string)

Parse the image spec and extract the registry server and the repo name. Example image specs:

ECS: ACCOUNT.dkr.ecr.REGION.amazonaws.com/imagename:tag
Docker Hub: imagename:tag or owner/imagename:tag

func RandStr added in v1.2.0

func RandStr(t *testing.T, n int) string

func RunProg

func RunProg(prog string, outputLimit, maxRetries int, args ...string) error

func SetOOMScore

func SetOOMScore(pid, score int) error

We disable the OOM Killer for Itzo in the itzo startup script but we want to reenable it for user processes that itzo spawns

func SplitNamespaceAndName

func SplitNamespaceAndName(n string) (string, string)

func TailFile added in v1.2.0

func TailFile(path string, lines int, maxBytes int64) (string, error)

func TranslateProbePorts added in v1.2.0

func TranslateProbePorts(unit *api.Unit, probe *api.Probe) *api.Probe

Our probes can reference unit ports by the name given to them in the unit. However, where the probes are actually used (inside unit.go) we don't have access to the full unit structure. Here we make a copy of an httpget probe and update it to use only port numbers. If we can't look up a probe's name, we don't fail the unit, instead we pass along the unmodified port and it'll fail in the probe. That matches the behavior of the kubelet. Note that we can't change a probe in-place since that messes up the diffs we do on pods during UpdatePod and would cause us to delete and recreate pods.

func Version

func Version() string

func WithNamespace

func WithNamespace(ns, name string) string

Types

type FakeUserLookup

type FakeUserLookup struct {
	Uid     uint32
	UidGid  uint32
	UidErr  error
	Gid     uint32
	GidErr  error
	Homedir string
}

func (*FakeUserLookup) Lookup

func (ful *FakeUserLookup) Lookup(username string) (*user.User, error)

func (*FakeUserLookup) LookupGroup

func (ful *FakeUserLookup) LookupGroup(name string) (*user.Group, error)

func (*FakeUserLookup) LookupGroupId

func (ful *FakeUserLookup) LookupGroupId(name string) (*user.Group, error)

func (*FakeUserLookup) LookupId

func (ful *FakeUserLookup) LookupId(username string) (*user.User, error)

type OsUserLookup

type OsUserLookup struct{}

func (*OsUserLookup) Lookup

func (oul *OsUserLookup) Lookup(username string) (*user.User, error)

func (*OsUserLookup) LookupGroup

func (oul *OsUserLookup) LookupGroup(name string) (*user.Group, error)

func (*OsUserLookup) LookupGroupId

func (oul *OsUserLookup) LookupGroupId(name string) (*user.Group, error)

func (*OsUserLookup) LookupId

func (oul *OsUserLookup) LookupId(username string) (*user.User, error)

type PasswdUserLookup

type PasswdUserLookup struct {
	RootFs string
	// contains filtered or unexported fields
}

func NewPasswdUserLookup

func NewPasswdUserLookup(path string) (*PasswdUserLookup, error)

func (*PasswdUserLookup) Lookup

func (l *PasswdUserLookup) Lookup(username string) (*user.User, error)

func (*PasswdUserLookup) LookupGroup

func (l *PasswdUserLookup) LookupGroup(name string) (*user.Group, error)

func (*PasswdUserLookup) LookupGroupId

func (l *PasswdUserLookup) LookupGroupId(name string) (*user.Group, error)

func (*PasswdUserLookup) LookupId

func (l *PasswdUserLookup) LookupId(username string) (*user.User, error)

type UserLookup

type UserLookup interface {
	Lookup(username string) (*user.User, error)
	LookupId(username string) (*user.User, error)
	LookupGroup(name string) (*user.Group, error)
	LookupGroupId(name string) (*user.Group, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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