util

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2017 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package util provides utility functions for the cmd packages.

Index

Constants

View Source
const (
	ProductOpenShift = `OpenShift`
)

Variables

View Source
var ErrExit = fmt.Errorf("exit directly")

ErrExit is a marker interface for cli commands indicating that the response has been processed

View Source
var ErrorNoDefaultIP = errors.New("no suitable IP address")

ErrorNoDefaultIP is returned when no suitable non-loopback address can be found.

Functions

func AllLocalIP4 added in v0.5.1

func AllLocalIP4() ([]net.IP, error)

AllLocalIP4 returns all the IPv4 addresses that this host can be reached on.

func CertPoolFromFile added in v0.4.3

func CertPoolFromFile(filename string) (*x509.CertPool, error)

func CertificatesFromFile added in v0.4.3

func CertificatesFromFile(file string) ([]*x509.Certificate, error)

func CertificatesFromPEM added in v0.4.3

func CertificatesFromPEM(pemCerts []byte) ([]*x509.Certificate, error)

func DefaultLocalIP4

func DefaultLocalIP4() (net.IP, error)

DefaultLocalIP4 returns an IPv4 address that this host can be reached on. Will return NoDefaultIP if no suitable address can be found.

func Env added in v0.2.1

func Env(key string, defaultValue string) string

Env returns an environment variable or a default value if not specified.

func EnvInt added in v0.4.2

func EnvInt(key string, defaultValue int32, minValue int32) int32

func GetCertificateFunc added in v1.0.7

func GetCertificateFunc(certs map[string]*tls.Certificate) func(*tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificateFunc returns a function that can be used in tls.Config#GetCertificate Returns nil if len(certs) == 0

func GetDisplayFilename added in v1.0.6

func GetDisplayFilename(filename string) string

GetDisplayFilename returns the absolute path of the filename as long as there was no error, otherwise it returns the filename as-is

func GetDistributionName added in v1.0.7

func GetDistributionName(binaryName string) string

GetDistributionName returns an appropriate Kubernetes distribution name. Distribution name can be used in relation to some feature set in command's usage string (e.g. <distribution name> allows you to build, run, etc.).

func GetEnv added in v0.2.1

func GetEnv(key string) (string, bool)

GetEnv returns an environment value if specified

func GetLogLevel added in v0.4.2

func GetLogLevel() (level int)

GetLogLevel returns the current glog log level

func GetPlatformName added in v1.0.7

func GetPlatformName(binaryName string) string

GetPlatformName returns an appropriate platform name for given binary name. Platform name can be used as a headline in command's usage.

func GetProductName added in v1.0.7

func GetProductName(binaryName string) string

GetProductName chooses appropriate product for a binary name.

func HostnameMatchSpecCandidates added in v1.0.7

func HostnameMatchSpecCandidates(hostname string) []string

HostnameMatchSpecCandidates returns a list of match specs that would match the provided hostname Returns nil if len(hostname) == 0

func HostnameMatches added in v1.0.7

func HostnameMatches(hostname string, matchSpec string) bool

HostnameMatches returns true if the given hostname is matched by the given matchSpec

func IsEnvironmentArgument added in v0.3.1

func IsEnvironmentArgument(s string) bool

func IsValidEnvironmentArgument added in v1.3.0

func IsValidEnvironmentArgument(s string) bool

func ListenAndServe added in v1.0.5

func ListenAndServe(srv *http.Server, network string) error

ListenAndServe starts a server that listens on the provided TCP mode (as supported by net.Listen)

func ListenAndServeTLS added in v1.0.5

func ListenAndServeTLS(srv *http.Server, network string, certFile, keyFile string) error

ListenAndServeTLS starts a server that listens on the provided TCP mode (as supported by net.Listen).

func MakeAbs added in v0.4.2

func MakeAbs(path, base string) (string, error)

func MakeRelative added in v0.4.4

func MakeRelative(path, base string) (string, error)

func NewGLogWriterV added in v1.3.0

func NewGLogWriterV(level int) io.Writer

NewGLogWriterV returns a new Writer that delegates to `glog.Info` at the desired level of verbosity

func ParseEnv added in v1.1.2

func ParseEnv(spec []string, defaultReader io.Reader) ([]kapi.EnvVar, []string, error)

ParseEnv parses the list of environment variables into kubernetes EnvVar

func PrivateKeysFromPEM added in v1.1.4

func PrivateKeysFromPEM(pemCerts []byte) ([]byte, error)

PrivateKeysFromPEM extracts all blocks recognized as private keys into an output PEM encoded byte array, or returns an error. If there are no private keys it will return an empty byte buffer.

func RelativizePathWithNoBacksteps added in v0.4.2

func RelativizePathWithNoBacksteps(refs []*string, base string) error

RelativizePathWithNoBacksteps updates the given refs to be relative paths, relative to the given base directory as long as they do not require backsteps. Any path requiring a backstep is left as-is as long it is absolute. Any non-absolute path that can't be relativized produces an error

func RelativizePaths added in v0.4.2

func RelativizePaths(refs []*string, base string) error

RelativizePaths updates the given refs to be relative paths, relative to the given base directory

func ReplaceCommandName added in v1.3.0

func ReplaceCommandName(from, to string, c *cobra.Command) *cobra.Command

ReplaceCommandName recursively processes the examples in a given command to change a hardcoded command name (like 'kubectl' to the appropriate target name). It returns c.

func ResolvePaths added in v0.4.2

func ResolvePaths(refs []*string, base string) error

ResolvePaths updates the given refs to be absolute paths, relative to the given base directory

func ResolveResource added in v1.0.8

func ResolveResource(defaultResource unversioned.GroupResource, resourceString string, mapper meta.RESTMapper) (unversioned.GroupResource, string, error)

ResolveResource returns the resource type and name of the resourceString. If the resource string has no specified type, defaultResource will be returned.

func SiblingCommand added in v1.3.0

func SiblingCommand(cmd *cobra.Command, name string) string

SiblingCommand returns a sibling command to the given command

func SplitEnvironmentFromResources added in v1.1.4

func SplitEnvironmentFromResources(args []string) (resources, envArgs []string, ok bool)

func TransportFor added in v0.4.3

func TransportFor(ca string, certFile string, keyFile string) (http.RoundTripper, error)

TransportFor returns an http.Transport for the given ca and client cert (which may be empty strings)

func TryListen added in v0.4.2

func TryListen(network, hostPort string) (bool, error)

TryListen tries to open a connection on the given port and returns true if it succeeded.

func UnsecuredRoute added in v1.3.0

func UnsecuredRoute(kc kclientset.Interface, namespace, routeName, serviceName, portString string) (*api.Route, error)

UnsecuredRoute will return a route with enough info so that it can direct traffic to the service provided by --service. Callers of this helper are responsible for providing tls configuration, path, and the hostname of the route.

func VersionedPrintObject added in v1.1.6

func VersionedPrintObject(fn func(*cobra.Command, meta.RESTMapper, runtime.Object, io.Writer) error, c *cobra.Command, mapper meta.RESTMapper, out io.Writer) func(runtime.Object) error

VersionedPrintObject handles printing an object in the appropriate version by looking at 'output-version' on the command

func WaitForSuccessfulDial added in v0.2.1

func WaitForSuccessfulDial(https bool, network, address string, timeout, interval time.Duration, retries int) error

WaitForSuccessfulDial attempts to connect to the given address, closing and returning nil on the first successful connection.

func WarnAboutCommaSeparation added in v1.4.0

func WarnAboutCommaSeparation(errout io.Writer, values []string, flag string)

Types

type Mux

type Mux interface {
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}

Mux is a standard mux interface for HTTP

Jump to

Keyboard shortcuts

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