Documentation ¶
Overview ¶
Package util provides utility functions for the cmd packages.
Index ¶
- Constants
- Variables
- func AllLocalIP4() ([]net.IP, error)
- func CertPoolFromFile(filename string) (*x509.CertPool, error)
- func CertificatesFromFile(file string) ([]*x509.Certificate, error)
- func CertificatesFromPEM(pemCerts []byte) ([]*x509.Certificate, error)
- func DefaultLocalIP4() (net.IP, error)
- func Env(key string, defaultValue string) string
- func EnvInt(key string, defaultValue int32, minValue int32) int32
- func GetCertificateFunc(certs map[string]*tls.Certificate) func(*tls.ClientHelloInfo) (*tls.Certificate, error)
- func GetDisplayFilename(filename string) string
- func GetDistributionName(binaryName string) string
- func GetEnv(key string) (string, bool)
- func GetLogLevel() (level int)
- func GetPlatformName(binaryName string) string
- func GetProductName(binaryName string) string
- func HostnameMatchSpecCandidates(hostname string) []string
- func HostnameMatches(hostname string, matchSpec string) bool
- func IsEnvironmentArgument(s string) bool
- func IsValidEnvironmentArgument(s string) bool
- func ListenAndServe(srv *http.Server, network string) error
- func ListenAndServeTLS(srv *http.Server, network string, certFile, keyFile string) error
- func MakeAbs(path, base string) (string, error)
- func MakeRelative(path, base string) (string, error)
- func NewGLogWriterV(level int) io.Writer
- func ParseEnv(spec []string, defaultReader io.Reader) ([]kapi.EnvVar, []string, error)
- func PrivateKeysFromPEM(pemCerts []byte) ([]byte, error)
- func RelativizePathWithNoBacksteps(refs []*string, base string) error
- func RelativizePaths(refs []*string, base string) error
- func ReplaceCommandName(from, to string, c *cobra.Command) *cobra.Command
- func ResolvePaths(refs []*string, base string) error
- func ResolveResource(defaultResource unversioned.GroupResource, resourceString string, ...) (unversioned.GroupResource, string, error)
- func SiblingCommand(cmd *cobra.Command, name string) string
- func SplitEnvironmentFromResources(args []string) (resources, envArgs []string, ok bool)
- func TransportFor(ca string, certFile string, keyFile string) (http.RoundTripper, error)
- func TryListen(network, hostPort string) (bool, error)
- func UnsecuredRoute(kc *kclient.Client, namespace, routeName, serviceName, portString string) (*api.Route, error)
- func VersionedPrintObject(fn func(*cobra.Command, meta.RESTMapper, runtime.Object, io.Writer) error, ...) func(runtime.Object) error
- func WaitForSuccessfulDial(https bool, network, address string, timeout, interval time.Duration, ...) error
- func WarnAboutCommaSeparation(errout io.Writer, values []string, flag string)
- type Environment
- type Mux
Constants ¶
const ( ProductOrigin = `Origin` ProductOpenShift = `OpenShift` ProductAtomicEnterprise = `Atomic Enterprise` )
Variables ¶
var ErrExit = fmt.Errorf("exit directly")
ErrExit is a marker interface for cli commands indicating that the response has been processed
var ErrorNoDefaultIP = errors.New("no suitable IP address")
ErrorNoDefaultIP is returned when no suitable non-loopback address can be found.
Functions ¶
func AllLocalIP4 ¶
AllLocalIP4 returns all the IPv4 addresses that this host can be reached on.
func CertificatesFromFile ¶
func CertificatesFromFile(file string) ([]*x509.Certificate, error)
func CertificatesFromPEM ¶
func CertificatesFromPEM(pemCerts []byte) ([]*x509.Certificate, error)
func DefaultLocalIP4 ¶
DefaultLocalIP4 returns an IPv4 address that this host can be reached on. Will return NoDefaultIP if no suitable address can be found.
func GetCertificateFunc ¶
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 ¶
GetDisplayFilename returns the absolute path of the filename as long as there was no error, otherwise it returns the filename as-is
func GetDistributionName ¶
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 GetPlatformName ¶
GetPlatformName returns an appropriate platform name for given binary name. Platform name can be used as a headline in command's usage.
func GetProductName ¶
GetProductName chooses appropriate product for a binary name.
func HostnameMatchSpecCandidates ¶
HostnameMatchSpecCandidates returns a list of match specs that would match the provided hostname Returns nil if len(hostname) == 0
func HostnameMatches ¶
HostnameMatches returns true if the given hostname is matched by the given matchSpec
func IsEnvironmentArgument ¶
func ListenAndServe ¶
ListenAndServe starts a server that listens on the provided TCP mode (as supported by net.Listen)
func ListenAndServeTLS ¶
ListenAndServeTLS starts a server that listens on the provided TCP mode (as supported by net.Listen).
func MakeRelative ¶
func NewGLogWriterV ¶
NewGLogWriterV returns a new Writer that delegates to `glog.Info` at the desired level of verbosity
func PrivateKeysFromPEM ¶
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 ¶
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 ¶
RelativizePaths updates the given refs to be relative paths, relative to the given base directory
func ReplaceCommandName ¶
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 ¶
ResolvePaths updates the given refs to be absolute paths, relative to the given base directory
func ResolveResource ¶
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 ¶
SiblingCommand returns a sibling command to the given command
func TransportFor ¶
TransportFor returns an http.Transport for the given ca and client cert (which may be empty strings)
func TryListen ¶
TryListen tries to open a connection on the given port and returns true if it succeeded.
func UnsecuredRoute ¶
func UnsecuredRoute(kc *kclient.Client, 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 ¶
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
Types ¶
type Environment ¶
func ParseEnvironmentArguments ¶
func ParseEnvironmentArguments(s []string) (Environment, []string, []error)