utils

package
v0.9.5-test5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenIsoImage

func GenIsoImage(isoPath string, volumeID string, srcDir string) error

GenIsoImage generates an ISO 9660 filesystem image containing files from srcDir. It uses specified volumeID as the volume id.

func GetBoolFromString

func GetBoolFromString(str string) bool

GetBoolFromString returns false if str is an empty string or is equal to one of: "0", "f" or "false". Case doesnt't matter anythging else is true

func GetK8sClientConfig

func GetK8sClientConfig(host string) (*rest.Config, error)

GetK8sClientConfig returns config that is needed to access k8s

func GetK8sClientset

func GetK8sClientset(config *rest.Config) (*kubernetes.Clientset, error)

GetK8sClientset returns clientset for standard k8s APIs

func GetK8sRestClient

func GetK8sRestClient(cfg *rest.Config, scheme *runtime.Scheme, groupVersion *schema.GroupVersion) (*rest.RESTClient, error)

GetK8sRestClient returns k8s ReST client that for the giver API group-version/subset

func HandleNsFixReexec

func HandleNsFixReexec()

HandleNsFixReexec handles executing the code in another namespace. If reexcution is requested, the function calls os.Exit() after handling it.

func MapToJSON

func MapToJSON(m map[string]interface{}) string

MapToJSON converts the specified map object to indented JSON. It panics in case if the map connot be converted.

func MapToJSONUnindented

func MapToJSONUnindented(m map[string]interface{}) string

MapToJSONUnindented converts the specified map object to unindented JSON. It panics in case if the map connot be converted.

func Merge

func Merge(base, override interface{}) interface{}

Merge will take two data sets and merge them together - returning a new data set

func NewUUID

func NewUUID() string

NewUUID returns a new uuid4 as a string

func NewUUID5

func NewUUID5(nsUUID, s string) string

NewUUID5 returns a new uuid5 as a string

func ReadJSON

func ReadJSON(filename string, v interface{}) error

ReadJSON converts data from file specified by `filename` to provided as `v` interface.

func RegisterNsFixReexec

func RegisterNsFixReexec(name string, handler NsFixReexecHandler, arg interface{})

RegisterNsFixReexec registers the specified function as a reexec handler. arg specifies the argument type to pass. Note that if you pass somestruct{} as arg, the handler will receive *somestruct as its argument (i.e. a level of pointer indirection is added).

func WaitForProcess

func WaitForProcess(procFile string) (int, error)

WaitForProcess waits for the following conditions to be true at the same time:

  • the specified procFile is readable and contains two numeric values separated by space, PID and start time in jiffies (field 22 in /proc/PID/stat, starting from 1)
  • the process with the PID read from procFile exists and has start time equal to the start time read from procFile

This avoids possible problems with stale procFile that could happen if only PID was stored there. The command can be used in shell script to generate the "procfile" for the current shell: /bin/sh -c 'echo "$$ `cut -d" " -f22 /proc/$$/stat`"'

func WaitLoop

func WaitLoop(test func() (bool, error), retryPeriod time.Duration, timeout time.Duration, clock clockwork.Clock) error

WaitLoop executes test func in loop until it returns error, true, or the timeout elapses. clock argument denotes a clock object to use for waiting. When clock is nil, WaitLoop uses clockwork.NewRealClock()

func WriteFiles

func WriteFiles(targetDir string, content map[string][]byte) error

WriteFiles writes the files specified as a map under `targetDir`. The keys of the map are subpaths and values are file contents. WriteFiles automatically creates any non-existing directories mentioned in subpaths.

func WriteJSON

func WriteJSON(filename string, v interface{}, perm os.FileMode) error

WriteJSON saves under specified `filename` data provided in `v` interface setting file mode according to `perm` value.

Types

type NsFixCall

type NsFixCall struct {
	// contains filtered or unexported fields
}

NsFixCall describes a call to be executed in network, mount, UTS and IPC namespaces of another process.

func NewNsFixCall

func NewNsFixCall(handlerName string) *NsFixCall

NewNsFixCall makes a new NsFixCall structure with specified handlerName using PID 1.

func (*NsFixCall) Arg

func (c *NsFixCall) Arg(arg interface{}) *NsFixCall

Arg sets argument for NsFixCall

func (*NsFixCall) DropPrivs

func (c *NsFixCall) DropPrivs() *NsFixCall

DropPrivs instructs NsFixCall to drop privileges in the new process

func (*NsFixCall) RemountSys

func (c *NsFixCall) RemountSys() *NsFixCall

RemountSys instructs NsFixCall to remount /sys in the new process

func (*NsFixCall) SpawnInNamespaces

func (c *NsFixCall) SpawnInNamespaces(ret interface{}) error

SpawnInNamespaces executes the specified handler using network, mount, UTS and IPC namespaces of the specified process. It passes the argument to the handler using JSON serialization. It then returns the value returned by the handler (also via JSON serialization + deserialization). If dropPrivs is true, the new process will execute using non-root uid/gid (using real uid/gid of the process if they're non-zero or 65534 which is nobody/nogroup)

func (*NsFixCall) SwitchToNamespaces

func (c *NsFixCall) SwitchToNamespaces() error

SwitchToNamespaces executes the specified handler using network, mount, UTS and IPC namespaces of the specified process. It passes the argument to the handler using JSON serialization. The current process gets replaced by the new one. If dropPrivs is true, the new process will execute using non-root uid/gid (using real uid/gid of the process if they're non-zero or 65534 which is nobody/nogroup)

func (*NsFixCall) TargetPid

func (c *NsFixCall) TargetPid(targetPid int) *NsFixCall

TargetPid sets target PID value for NsFixCall

type NsFixReexecHandler

type NsFixReexecHandler func(arg interface{}) (interface{}, error)

NsFixReexecHandler is a function that can be passed to RegisterNsFixReexec to be executed my nsfix mechanism after self-reexec. arg can be safely casted to the type of arg passed to RegisterNsFixReexec plus one level of pointer inderection, i.e. if you pass somestruct{} to RegisterNsFixReexec you may cast arg safely to *somestruct.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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