util

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package util provides generic utility routines used within FSM CNI Plugin.

Index

Constants

View Source
const (
	// PrivateFileMode grants owner to read/write a file.
	PrivateFileMode = 0o600
)

Variables

This section is empty.

Functions

func AtomicCopy

func AtomicCopy(srcFilepath, targetDir, targetFilename string) error

AtomicCopy copies file by reading the file then writing atomically into the target directory

func AtomicWrite

func AtomicWrite(path string, data []byte, mode os.FileMode) (err error)

AtomicWrite atomically by writing to a temporary file in the same directory then renaming

func CreateFileWatcher

func CreateFileWatcher(dirs ...string) (watcher *fsnotify.Watcher, fileModified chan bool, errChan chan error, err error)

CreateFileWatcher creates a file watcher that watches for any changes to the directory

func DirEquals

func DirEquals(a, b string) (bool, error)

DirEquals check if two directories are referring to the same directory

func Exists

func Exists(name string) bool

Exists checks whether the file exists

func GetPlugin

func GetPlugin(rawPlugin any) (plugin map[string]any, err error)

GetPlugin given the raw plugin interface, return the plugin asserted as a map[string]interface{}

func GetPlugins

func GetPlugins(cniConfigMap map[string]any) (plugins []any, err error)

GetPlugins given an unmarshalled CNI config JSON map, return the plugin list asserted as a []interface{}

func IP2Pointer

func IP2Pointer(ipstr string) (unsafe.Pointer, error)

IP2Pointer returns the pointer of a ip string

func Inode

func Inode(path string) (uint64, error)

Inode returns the inode of file

func IsDirWriteable

func IsDirWriteable(dir string) error

IsDirWriteable checks if dir is writable by writing and removing a file to dir. It returns nil if dir is writable. Inspired by etcd fileutil.

func MarshalCNIConfig

func MarshalCNIConfig(cniConfigMap map[string]any) ([]byte, error)

MarshalCNIConfig marshal the CNI config map and append a new line

func WaitForFileMod

func WaitForFileMod(ctx context.Context, fileModified chan bool, errChan chan error) error

WaitForFileMod waits until a file is modified (returns nil), the context is cancelled (returns context error), or returns error

Types

This section is empty.

Jump to

Keyboard shortcuts

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