util

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: Apache-2.0 Imports: 47 Imported by: 365

Documentation

Index

Constants

View Source
const (
	APIServerPort            = 8443
	DefaultMinikubeDirectory = "/var/lib/minikube"
	DefaultCertPath          = DefaultMinikubeDirectory + "/certs/"
	DefaultKubeConfigPath    = DefaultMinikubeDirectory + "/kubeconfig"
	DefaultDNSDomain         = "cluster.local"
	DefaultServiceCIDR       = "10.96.0.0/12"
)

These constants are used by both minikube

View Source
const ErrPrefix = "! "

ErrPrefix notes an error

View Source
const OutPrefix = "> "

OutPrefix notes output

Variables

View Source
var (
	// ReasonableMutateTime is how long to wait for basic object mutations, such as deletions, to show up
	ReasonableMutateTime = time.Minute * 1
	// ReasonableStartTime is how long to wait for pods to start, considering dependency chains & slow networks.
	ReasonableStartTime = time.Minute * 10
)
View Source
var DefaultLegacyAdmissionControllers = append([]string{"Initializers"}, DefaultV114AdmissionControllers...)

DefaultLegacyAdmissionControllers are admission controllers we include with Kubernetes <1.14.0

View Source
var DefaultV114AdmissionControllers = []string{
	"NamespaceLifecycle",
	"LimitRanger",
	"ServiceAccount",
	"DefaultStorageClass",
	"DefaultTolerationSeconds",
	"NodeRestriction",
	"MutatingAdmissionWebhook",
	"ValidatingAdmissionWebhook",
	"ResourceQuota",
}

DefaultV114AdmissionControllers are admission controllers we default to in v1.14.x

Functions

func CalculateDiskSizeInMB added in v0.22.0

func CalculateDiskSizeInMB(humanReadableDiskSize string) int

CalculateDiskSizeInMB returns the number of MB in the human readable string

func CanReadFile

func CanReadFile(path string) bool

CanReadFile returns true if the file represented by path exists and is readable, otherwise false.

func ChownR added in v0.21.0

func ChownR(path string, uid, gid int) error

ChownR does a recursive os.Chown

func ConcatStrings added in v1.0.1

func ConcatStrings(src []string, prefix string, postfix string) []string

ConcatStrings concatenates each string in the src slice with prefix and postfix and returns a new slice

func ContainsString added in v1.1.0

func ContainsString(slice []string, s string) bool

ContainsString checks if a given slice of strings contains the provided string. If a modifier func is provided, it is called with the slice item before the comparation.

func FindAndSet added in v0.11.0

func FindAndSet(path string, c interface{}, value string) error

FindAndSet sets the nested value.

func GenerateCACert added in v0.6.0

func GenerateCACert(certPath, keyPath string, name string) error

GenerateCACert generates a CA certificate and RSA key for a common name

func GenerateSignedCert added in v0.6.0

func GenerateSignedCert(certPath, keyPath, cn string, ips []net.IP, alternateDNS []string, signerCertPath, signerKeyPath string) error

GenerateSignedCert generates a signed certificate and key

func GetAlternateDNS

func GetAlternateDNS(domain string) []string

GetAlternateDNS returns a list of alternate names for a domain

func GetBinaryDownloadURL added in v0.26.0

func GetBinaryDownloadURL(version, platform string) string

GetBinaryDownloadURL returns a suitable URL for the platform

func GetClient added in v0.22.2

func GetClient() (kubernetes.Interface, error)

GetClient gets the client from config

func GetDNSIP added in v0.24.0

func GetDNSIP(serviceCIDR string) (net.IP, error)

GetDNSIP returns x.x.x.10 of the service CIDR

func GetKubeConfigStatus added in v1.0.0

func GetKubeConfigStatus(ip net.IP, filename string, machineName string) (bool, error)

GetKubeConfigStatus verifies the ip stored in kubeconfig.

func GetPortFromKubeConfig added in v1.0.1

func GetPortFromKubeConfig(filename, machineName string) (int, error)

GetPortFromKubeConfig returns the Port number stored for minikube in the kubeconfig specified

func GetServiceClusterIP added in v0.24.0

func GetServiceClusterIP(serviceCIDR string) (net.IP, error)

GetServiceClusterIP returns the first IP of the ServiceCIDR

func IsDirectory added in v0.9.0

func IsDirectory(path string) (bool, error)

IsDirectory checks if path is a directory

func IsRetryableAPIError added in v0.22.2

func IsRetryableAPIError(err error) bool

IsRetryableAPIError returns if this error is retryable or not

func MaybeChownDirRecursiveToMinikubeUser added in v0.21.0

func MaybeChownDirRecursiveToMinikubeUser(dir string) error

MaybeChownDirRecursiveToMinikubeUser changes ownership of a dir, if requested

func Pad

func Pad(str string) string

Pad pads the string with newlines

func ParseSHAFromURL added in v0.11.0

func ParseSHAFromURL(url string) (string, error)

ParseSHAFromURL downloads and reads a SHA checksum from an URL

func PopulateKubeConfig added in v1.0.0

func PopulateKubeConfig(cfg *KubeConfigSetup, kubecfg *api.Config) error

PopulateKubeConfig populates an api.Config object.

func ReadConfigOrNew added in v1.0.0

func ReadConfigOrNew(filename string) (*api.Config, error)

ReadConfigOrNew retrieves Kubernetes client configuration from a file. If no files exists, an empty configuration is returned.

func ReplaceChars added in v1.0.1

func ReplaceChars(src []string, replacer *strings.Replacer) []string

ReplaceChars returns a copy of the src slice with each string modified by the replacer

func Retry added in v0.2.0

func Retry(attempts int, callback func() error) (err error)

Retry retries a number of attempts

func RetryAfter added in v0.2.0

func RetryAfter(attempts int, callback func() error, d time.Duration) (err error)

RetryAfter retries a number of attempts, after a delay

func SetupKubeConfig added in v1.0.0

func SetupKubeConfig(cfg *KubeConfigSetup) error

SetupKubeConfig reads config from disk, adds the minikube settings, and writes it back. activeContext is true when minikube is the CurrentContext If no CurrentContext is set, the given name will be used.

func StartPods added in v0.22.2

func StartPods(c kubernetes.Interface, namespace string, pod core.Pod, waitForRunning bool) error

StartPods starts all pods

func TeePrefix added in v0.32.0

func TeePrefix(prefix string, r io.Reader, w io.Writer, logger func(format string, args ...interface{})) error

TeePrefix copies bytes from a reader to writer, logging each new line.

func UnsetCurrentContext added in v1.1.0

func UnsetCurrentContext(filename, machineName string) error

UnsetCurrentContext unsets the current-context from minikube to "" on minikube stop

func Until

func Until(fn func() error, w io.Writer, name string, sleep time.Duration, done <-chan struct{})

Until endlessly loops the provided function until a message is received on the done channel. The function will wait the duration provided in sleep between function calls. Errors will be sent on provider Writer.

func UpdateKubeconfigIP added in v1.0.0

func UpdateKubeconfigIP(ip net.IP, filename string, machineName string) (bool, error)

UpdateKubeconfigIP overwrites the IP stored in kubeconfig with the provided IP.

func WaitForDeploymentToStabilize added in v0.25.0

func WaitForDeploymentToStabilize(c kubernetes.Interface, ns, name string, timeout time.Duration) error

WaitForDeploymentToStabilize waits till the Deployment has a matching generation/replica count between spec and status.

func WaitForEvent added in v0.31.0

func WaitForEvent(c kubernetes.Interface, ns string, reason string) error

WaitForEvent waits for the given event to appear

func WaitForPodDelete added in v0.31.0

func WaitForPodDelete(c kubernetes.Interface, ns string, label fmt.Stringer) error

WaitForPodDelete waits for a pod to be deleted

func WaitForPodsWithLabelRunning added in v0.22.2

func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels.Selector) error

WaitForPodsWithLabelRunning waits for all matching pods to become Running and at least one matching pod exists.

func WaitForRCToStabilize added in v0.22.2

func WaitForRCToStabilize(c kubernetes.Interface, ns, name string, timeout time.Duration) error

WaitForRCToStabilize waits till the RC has a matching generation/replica count between spec and status.

func WaitForService added in v0.22.2

func WaitForService(c kubernetes.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error

WaitForService waits until the service appears (exist == true), or disappears (exist == false)

func WaitForServiceEndpointsNum added in v0.22.2

func WaitForServiceEndpointsNum(c kubernetes.Interface, namespace, serviceName string, expectNum int, interval, timeout time.Duration) error

WaitForServiceEndpointsNum waits until the amount of endpoints that implement service to expectNum.

func WriteConfig added in v1.0.0

func WriteConfig(config *api.Config, filename string) error

WriteConfig encodes the configuration and writes it to the given file. If the file exists, it's contents will be overwritten.

Types

type ComponentExtraOptionMap added in v1.1.0

type ComponentExtraOptionMap map[string]map[string]string

ComponentExtraOptionMap maps components to their extra opts, which is a map of keys to values

func (ComponentExtraOptionMap) Get added in v1.1.0

func (cm ComponentExtraOptionMap) Get(component string) map[string]string

Get returns the extra option map of keys to values for the specified component

type DefaultDownloader added in v0.16.0

type DefaultDownloader struct{}

DefaultDownloader is the default ISODownloader

func (DefaultDownloader) CacheMinikubeISOFromURL added in v0.16.0

func (f DefaultDownloader) CacheMinikubeISOFromURL(isoURL string) error

CacheMinikubeISOFromURL downloads the ISO, if it doesn't exist in cache

func (DefaultDownloader) GetISOCacheFilepath added in v0.17.0

func (f DefaultDownloader) GetISOCacheFilepath(isoURL string) string

GetISOCacheFilepath returns the path of an ISO in the local cache

func (DefaultDownloader) GetISOFileURI added in v0.16.0

func (f DefaultDownloader) GetISOFileURI(isoURL string) string

GetISOFileURI gets the local destination for a remote source

func (DefaultDownloader) IsMinikubeISOCached added in v0.17.0

func (f DefaultDownloader) IsMinikubeISOCached(isoURL string) bool

IsMinikubeISOCached returns if an ISO exists in the local cache

func (DefaultDownloader) ShouldCacheMinikubeISO added in v0.17.0

func (f DefaultDownloader) ShouldCacheMinikubeISO(isoURL string) bool

ShouldCacheMinikubeISO returns if we need to download the ISO

type ExtraOption added in v0.11.0

type ExtraOption struct {
	Component string
	Key       string
	Value     string
}

ExtraOption is an extra option

func (*ExtraOption) String added in v0.11.0

func (e *ExtraOption) String() string

type ExtraOptionSlice added in v0.11.0

type ExtraOptionSlice []ExtraOption

ExtraOptionSlice is a slice of ExtraOption

func (*ExtraOptionSlice) AsMap added in v1.1.0

AsMap converts the slice to a map of components to a map of keys and values.

func (*ExtraOptionSlice) Get added in v1.1.0

func (es *ExtraOptionSlice) Get(key string, component ...string) string

Get finds and returns the value of an argument with the specified key and component (optional) or an empty string if not found. If component contains more than one value, the value for the first component found is returned. If component is not specified, all of the components are used.

func (*ExtraOptionSlice) Set added in v0.11.0

func (es *ExtraOptionSlice) Set(value string) error

Set parses the string value into a slice

func (*ExtraOptionSlice) String added in v0.11.0

func (es *ExtraOptionSlice) String() string

String converts the slice to a string value

func (*ExtraOptionSlice) Type added in v0.11.0

func (es *ExtraOptionSlice) Type() string

Type returns the type

type ISODownloader added in v0.16.0

type ISODownloader interface {
	GetISOFileURI(isoURL string) string
	CacheMinikubeISOFromURL(isoURL string) error
}

ISODownloader downloads an ISO

type KubeConfigSetup added in v1.0.0

type KubeConfigSetup struct {
	// The name of the cluster for this context
	ClusterName string

	// ClusterServerAddress is the address of the kubernetes cluster
	ClusterServerAddress string

	// ClientCertificate is the path to a client cert file for TLS.
	ClientCertificate string

	// CertificateAuthority is the path to a cert file for the certificate authority.
	CertificateAuthority string

	// ClientKey is the path to a client key file for TLS.
	ClientKey string

	// Should the current context be kept when setting up this one
	KeepContext bool

	// Should the certificate files be embedded instead of referenced by path
	EmbedCerts bool
	// contains filtered or unexported fields
}

KubeConfigSetup is the kubeconfig setup

func (*KubeConfigSetup) GetKubeConfigFile added in v1.0.0

func (k *KubeConfigSetup) GetKubeConfigFile() string

GetKubeConfigFile gets the kubeconfig file

func (*KubeConfigSetup) SetKubeConfigFile added in v1.0.0

func (k *KubeConfigSetup) SetKubeConfigFile(kubeConfigFile string)

SetKubeConfigFile sets the kubeconfig file

type MultiError added in v0.8.0

type MultiError struct {
	Errors []error
}

MultiError holds multiple errors

func (*MultiError) Collect added in v0.8.0

func (m *MultiError) Collect(err error)

Collect adds the error

func (MultiError) ToError added in v0.8.0

func (m MultiError) ToError() error

ToError converts all errors into one

type PodStore added in v0.22.2

type PodStore struct {
	cache.Store

	Reflector *cache.Reflector
	// contains filtered or unexported fields
}

PodStore stores pods

func NewPodStore added in v0.22.2

func NewPodStore(c kubernetes.Interface, namespace string, label fmt.Stringer, field fmt.Stringer) *PodStore

NewPodStore creates a new PodStore

func (*PodStore) List added in v0.22.2

func (s *PodStore) List() []*core.Pod

List lists the pods

func (*PodStore) Stop added in v0.22.2

func (s *PodStore) Stop()

Stop stops the pods

type RetriableError added in v0.12.0

type RetriableError struct {
	Err error
}

RetriableError is an error that can be tried again

func (RetriableError) Error added in v0.12.0

func (r RetriableError) Error() string

Jump to

Keyboard shortcuts

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