kubernetes

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BooleanType = iota
	StringType
	IntType
)
View Source
const (
	// APISGroupName is the api name used for epinio
	APISGroupName = "epinio.suse.org"
)

Variables

View Source
var (
	EpinioDeploymentLabelKey   = fmt.Sprintf("%s/%s", APISGroupName, "deployment")
	EpinioDeploymentLabelValue = "true"
	EpinioNamespaceLabelKey    = "app.kubernetes.io/component"
	EpinioNamespaceLabelValue  = "epinio-namespace"
	EpinioAPISecretLabelKey    = fmt.Sprintf("%s/%s", APISGroupName, "api-user-credentials")
	EpinioAPISecretLabelValue  = "true"
)

Functions

This section is empty.

Types

type CLIOptionsReader

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

func NewCLIOptionsReader

func NewCLIOptionsReader(flags *pflag.FlagSet) CLIOptionsReader

NewCLIOptionsReader is a reader used by the Installer to fill configuration variables from cli options.

func (CLIOptionsReader) Read

func (reader CLIOptionsReader) Read(option *InstallationOption) error

Queries the cobra command for a flag associated with the given InstallationOption and returns its value converted to the appropriate (Go) type as defined by the Type field of the InstallationOption. Does nothing if no cobra flag is found.

type Cluster

type Cluster struct {
	//	InternalIPs []string
	//	Ingress     bool
	Kubectl    *kubernetes.Clientset
	RestConfig *restclient.Config
	// contains filtered or unexported fields
}

func GetCluster

func GetCluster(ctx context.Context) (*Cluster, error)

GetCluster returns the Cluster needed to talk to it. On first call it creates it from a Kubernetes rest client config and cli arguments / environment variables.

func (*Cluster) ClientApp added in v0.0.18

ClientApp returns a dynamic namespaced client for the app resource

func (*Cluster) ClientCertManager added in v0.0.18

func (c *Cluster) ClientCertManager() (dynamic.NamespaceableResourceInterface, error)

ClientCertManager returns a dynamic namespaced client for the cert manager resource

func (*Cluster) ClientCertificate added in v0.0.18

func (c *Cluster) ClientCertificate() (dynamic.NamespaceableResourceInterface, error)

ClientCertificate returns a dynamic namespaced client for the cert manager certificate resource

func (*Cluster) ClusterIssuerExists added in v0.0.21

func (c *Cluster) ClusterIssuerExists(ctx context.Context, name string) (bool, error)

ClusterIssuerExists checks if the resource exists

func (*Cluster) CreateJob added in v0.3.6

func (c *Cluster) CreateJob(ctx context.Context, namespace string, job *apibatchv1.Job) error

func (*Cluster) CreateLabeledSecret

func (c *Cluster) CreateLabeledSecret(ctx context.Context, namespace, name string,
	data map[string][]byte,
	label map[string]string) error

CreateLabeledSecret posts a new secret to the cluster. The secret is constructed from name and a key/value dictionary for labels.

func (*Cluster) CreateNamespace added in v0.0.15

func (c *Cluster) CreateNamespace(ctx context.Context, name string, labels map[string]string, annotations map[string]string) error

func (*Cluster) CreateSecret

func (c *Cluster) CreateSecret(ctx context.Context, namespace string, secret v1.Secret) error

CreateSecret posts the specified secret to the cluster. All configuration of the secret is done by the caller.

func (*Cluster) DeleteJob added in v0.3.6

func (c *Cluster) DeleteJob(ctx context.Context, namespace string, name string) error

DeleteJob deletes the namepace

func (*Cluster) DeleteNamespace

func (c *Cluster) DeleteNamespace(ctx context.Context, namespace string) error

DeleteNamespace deletes the namepace

func (*Cluster) DeleteSecret

func (c *Cluster) DeleteSecret(ctx context.Context, namespace, name string) error

DeleteSecret removes a secret

func (*Cluster) DeploymentExists added in v0.0.17

func (c *Cluster) DeploymentExists(ctx context.Context, namespace, deploymentName string) wait.ConditionFunc

func (*Cluster) Exec

func (c *Cluster) Exec(namespace, podName, containerName string, command, stdin string) (string, string, error)

func (*Cluster) GetPlatform

func (c *Cluster) GetPlatform() Platform

func (*Cluster) GetPodEvents

func (c *Cluster) GetPodEvents(ctx context.Context, namespace, podName string) (string, error)

func (*Cluster) GetPodEventsWithSelector

func (c *Cluster) GetPodEventsWithSelector(ctx context.Context, namespace, selector string) (string, error)

GetPodEventsWithSelector tries to find a pod using the provided selector and namespace. If found it returns the events on that Pod. If not found it returns an error. An equivalent kubectl command would look like this (label selector being "app.kubernetes.io/name=container-registry"):

kubectl get event --namespace my-namespace \
--field-selector involvedObject.name=$( \
  kubectl get pods -o=jsonpath='{.items[0].metadata.name}' --selector=app.kubernetes.io/name=container-registry -n my-namespace)

func (*Cluster) GetSecret

func (c *Cluster) GetSecret(ctx context.Context, namespace, name string) (*v1.Secret, error)

GetSecret gets a secret's values

func (*Cluster) GetVersion

func (c *Cluster) GetVersion() (string, error)

GetVersion get the kube server version

func (*Cluster) IsDeploymentCompleted added in v0.0.14

func (c *Cluster) IsDeploymentCompleted(ctx context.Context, deploymentName, namespace string) wait.ConditionFunc

IsDeploymentCompleted returns a condition function that indicates whether the given Deployment is in Completed state or not.

func (*Cluster) IsJobDone added in v0.3.6

func (c *Cluster) IsJobDone(ctx context.Context, client *typedbatchv1.BatchV1Client, jobName, namespace string) wait.ConditionFunc

IsJobDone returns a condition function that indicates whether the given Job is done (Completed or Failed), or not

func (*Cluster) IsJobFailed added in v0.3.6

func (c *Cluster) IsJobFailed(ctx context.Context, jobName, namespace string) (bool, error)

IsJobFailed is a condition function that indicates whether the given Job is in Failed state or not.

func (*Cluster) IsPodRunning

func (c *Cluster) IsPodRunning(ctx context.Context, podName, namespace string) wait.ConditionFunc

IsPodRunning returns a condition function that indicates whether the given pod is currently running

func (*Cluster) ListIngress

func (c *Cluster) ListIngress(ctx context.Context, namespace, selector string) (*networkingv1.IngressList, error)

ListIngress returns the list of available ingresses in `namespace` with the given selector

func (*Cluster) ListIngressRoutes

func (c *Cluster) ListIngressRoutes(ctx context.Context, namespace, name string) ([]string, error)

ListIngressRoutes returns a list of all routes for ingresses in `namespace` with the given selector

func (*Cluster) ListJobs added in v0.3.6

func (c *Cluster) ListJobs(ctx context.Context, namespace, selector string) (*apibatchv1.JobList, error)

ListJobs returns the list of currently scheduled or running Jobs in `namespace` with the given selector

func (*Cluster) ListPods

func (c *Cluster) ListPods(ctx context.Context, namespace, selector string) (*v1.PodList, error)

ListPods returns the list of currently scheduled or running pods in `namespace` with the given selector

func (*Cluster) NamespaceDoesNotExist

func (c *Cluster) NamespaceDoesNotExist(ctx context.Context, namespaceName string) wait.ConditionFunc

func (*Cluster) NamespaceExists

func (c *Cluster) NamespaceExists(ctx context.Context, namespaceName string) (bool, error)

NamespaceExists checks if a namespace exists or not

func (*Cluster) NamespaceExistsAndOwned

func (c *Cluster) NamespaceExistsAndOwned(ctx context.Context, namespaceName string) (bool, error)

NamespaceExistsAndOwned checks if the namespace exists and is created by epinio or not.

func (*Cluster) NamespaceLabelExists

func (c *Cluster) NamespaceLabelExists(ctx context.Context, namespaceName, labelKey string) (bool, error)

NamespaceLabelExists checks if a specific label exits on the namespace

func (*Cluster) PodDoesNotExist

func (c *Cluster) PodDoesNotExist(ctx context.Context, namespace, selector string) wait.ConditionFunc

func (*Cluster) PodExists

func (c *Cluster) PodExists(ctx context.Context, namespace, selector string) wait.ConditionFunc

func (*Cluster) WaitForCRD

func (c *Cluster) WaitForCRD(ctx context.Context, ui *termui.UI, CRDName string, timeout time.Duration) error

WaitForCRD wait for a custom resource definition to exist in the cluster. It will wait until the CRD reaches the condition "established". This method should be used when installing a Deployment that is supposed to provide that CRD and want to make sure the CRD is ready for consumption before continuing deploying things that will consume it.

func (*Cluster) WaitForClusterIssuer added in v0.0.21

func (c *Cluster) WaitForClusterIssuer(ctx context.Context, ui *termui.UI, name string, timeout time.Duration) error

WaitForClusterIssuer waits up to timeout for ClusterIssuer to exist

func (*Cluster) WaitForDeploymentCompleted added in v0.0.14

func (c *Cluster) WaitForDeploymentCompleted(ctx context.Context, ui *termui.UI, namespace, deploymentName string, timeout time.Duration) error

func (*Cluster) WaitForJobDone added in v0.3.6

func (c *Cluster) WaitForJobDone(ctx context.Context, namespace, jobName string, timeout time.Duration) error

func (*Cluster) WaitForNamespace added in v0.0.13

func (c *Cluster) WaitForNamespace(ctx context.Context, ui *termui.UI, namespace string, timeout time.Duration) error

WaitForNamespace waits up to timeout for namespace to appear Returns an error if the Namespace is not found within the allotted time.

func (*Cluster) WaitForNamespaceMissing

func (c *Cluster) WaitForNamespaceMissing(ctx context.Context, ui *termui.UI, namespace string, timeout time.Duration) error

Wait up to timeout for Namespace to be removed. Returns an error if the Namespace is not removed within the allotted time.

func (*Cluster) WaitForPodBySelector added in v0.1.5

func (c *Cluster) WaitForPodBySelector(ctx context.Context, ui *termui.UI, namespace, selector string, timeout time.Duration) error

WaitForPodBySelector combines WaitUntilPodBySelectorExist and WaitForPodBySelectorRunning, as one doesn't check if the pod is ready and the other would fail immediately if the pod does not exist.

func (*Cluster) WaitForPodBySelectorMissing

func (c *Cluster) WaitForPodBySelectorMissing(ctx context.Context, ui *termui.UI, namespace, selector string, timeout time.Duration) error

Wait up to timeout for pod to be removed. Returns an error if the pod is not removed within the allotted time.

func (*Cluster) WaitForPodBySelectorRunning

func (c *Cluster) WaitForPodBySelectorRunning(ctx context.Context, ui *termui.UI, namespace, selector string, timeout time.Duration) error

WaitForPodBySelectorRunning waits timeout for all pods in 'namespace' with given 'selector' to enter running state. Returns an error if no pods are found or not all discovered pods enter running state.

func (*Cluster) WaitForPodRunning

func (c *Cluster) WaitForPodRunning(ctx context.Context, namespace, podName string, timeout time.Duration) error

Poll up to timeout for pod to enter running state. Returns an error if the pod never enters the running state.

func (*Cluster) WaitForSecret

func (c *Cluster) WaitForSecret(ctx context.Context, namespace, secretName string, timeout time.Duration) (*v1.Secret, error)

WaitForSecret waits until the specified secret exists. If timeout is reached, an error is returned. It should be used when something is expected to create a Secret and the code needs to wait until that happens.

func (*Cluster) WaitUntilDeploymentExists added in v0.0.17

func (c *Cluster) WaitUntilDeploymentExists(ctx context.Context, ui *termui.UI, namespace, deploymentName string, timeout time.Duration) error

WaitUntilDeploymentExist waits up to timeout for the specified deployment to exist. The Deployment is specified by its name.

func (*Cluster) WaitUntilPodBySelectorExist

func (c *Cluster) WaitUntilPodBySelectorExist(ctx context.Context, ui *termui.UI, namespace, selector string, timeout time.Duration) error

Wait up to timeout for all pods in 'namespace' with given 'selector' to enter running state. Returns an error if no pods are found or not all discovered pods enter running state.

func (*Cluster) WaitUntilServiceHasLoadBalancer added in v0.0.18

func (c *Cluster) WaitUntilServiceHasLoadBalancer(ctx context.Context, ui *termui.UI, namespace, serviceName string, timeout time.Duration) error

type DefaultOptionsReader

type DefaultOptionsReader struct{}

func NewDefaultOptionsReader

func NewDefaultOptionsReader() DefaultOptionsReader

NewDefaultOptionsReader is a reader used by the Installer to fill InstallationOptions with a default value, either static, or dynamic per function vector.

func (DefaultOptionsReader) Read

func (reader DefaultOptionsReader) Read(option *InstallationOption) error

Read attempts to fill the option with a default, dynamic or static.

type Deployment

type Deployment interface {
	PreDeployCheck(context.Context, *Cluster, *termui.UI, InstallationOptions) error
	PostDeleteCheck(context.Context, *Cluster, *termui.UI) error
	Deploy(context.Context, *Cluster, *termui.UI, InstallationOptions) error
	Upgrade(context.Context, *Cluster, *termui.UI, InstallationOptions) error
	Delete(context.Context, *Cluster, *termui.UI) error
	Describe() string
	GetVersion() string
	ID() string
}

type InstallationOption

type InstallationOption struct {
	Name           string                           // Identifying name of the configuration variable
	Value          interface{}                      // Value to use (may not be valid, see `Valid` field).
	Default        interface{}                      // Static default value for the value.
	DynDefaultFunc InstallationOptionDynamicDefault // Function to provide a default. Has priority over `Default`.
	UserSpecified  bool                             // Flag, true if `Value` came from the user.
	Description    string                           // Short description of the variable
	Type           InstallationOptionType           // Type information for `Value` and `Default`.
	DeploymentID   string                           // If set, this option will be passed only to this deployment (private)
}

func (*InstallationOption) DynDefault

func (opt *InstallationOption) DynDefault() error

func (*InstallationOption) SetDefault

func (opt *InstallationOption) SetDefault() error

type InstallationOptionDynamicDefault

type InstallationOptionDynamicDefault func(o *InstallationOption) error

A InstallationOptionDynamicDefault function may provide a dynamic default value for an option. When present it has precedence over any static default value in the structure.

ATTENTION: The function is responsible for setting both Value and Valid flag of the specified option. This is necessary for cases where the dynamic default could not be determined, yet is not an error.

type InstallationOptionType

type InstallationOptionType int

type InstallationOptions

type InstallationOptions []InstallationOption

func (InstallationOptions) AsCobraFlagsFor

func (opts InstallationOptions) AsCobraFlagsFor(flags *pflag.FlagSet)

func (InstallationOptions) ForDeployment

func (opts InstallationOptions) ForDeployment(deploymentID string) InstallationOptions

func (InstallationOptions) GetBool

func (opts InstallationOptions) GetBool(optionName string, deploymentID string) (bool, error)

func (InstallationOptions) GetBoolNG added in v0.0.19

func (opts InstallationOptions) GetBoolNG(optionName string) bool

GetBoolNG returns the bool value for a needed, global option

func (InstallationOptions) GetInt

func (opts InstallationOptions) GetInt(optionName string, deploymentID string) (int, error)

func (InstallationOptions) GetOpt

func (opts InstallationOptions) GetOpt(optionName string, deploymentID string) (*InstallationOption, error)

GetOpt finds the given option in opts.

When the deploymentID is the empty string the function searches for and returns only global options (not associated to any deployment). Otherwise it searches for private options associated with the specified deployment as well.

ATTENTION: In the second case private options have precedence. In other words if we have private and global options of the same name, then the private option is returned.

ATTENTION: This function returns a reference, enabling the caller to modify the structure.

func (InstallationOptions) GetString

func (opts InstallationOptions) GetString(optionName string, deploymentID string) (string, error)

func (InstallationOptions) GetStringNG added in v0.0.19

func (opts InstallationOptions) GetStringNG(optionName string) string

GetStringNG returns the string value for a needed, global option

func (*InstallationOptions) Populate

func (opts *InstallationOptions) Populate(reader OptionsReader) (*InstallationOptions, error)

Populate will try to give values to the needed options using the given OptionsReader. If none is given, the default is the InteractiveOptionsReader which will ask in the terminal. This method only populates what is possible and leaves the rest empty. TODO: Implement another method to validate that all options have been set.

type InteractiveOptionsReader

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

func NewInteractiveOptionsReader

func NewInteractiveOptionsReader(stdout io.Writer, stdin io.Reader) InteractiveOptionsReader

NewInteractiveOptionsReader is the default reader used by the Installer when one is not defined. It asks the user questions on stdout and gets answers on stdin.

func (InteractiveOptionsReader) Read

func (reader InteractiveOptionsReader) Read(option *InstallationOption) error

Read asks the user what value should the given InstallationOption have and returns that value validated and converted to the appropriate type as defined by the Type field of the InstallationOption.

type OptionsReader

type OptionsReader interface {
	Read(*InstallationOption) error
}

OptionsReader is the interface to the structures and objects used to fill InstallationOption instances with a valid value.

Note, each reader has the discretion to not modify the provided option instance based on its state. The option's Valid flag is, for example, how the defaults, cli, and interactive readers communicate and decide which options to handle.

type Platform

type Platform interface {
	Detect(context.Context, *kubernetes.Clientset) bool
	Describe() string
	String() string
	Load(context.Context, *kubernetes.Clientset) error
	ExternalIPs() []string
}

Directories

Path Synopsis
platform
ibm
k3s
tailer manages objects which tail the logs of a collection of pods specified by a label selector.
tailer manages objects which tail the logs of a collection of pods specified by a label selector.

Jump to

Keyboard shortcuts

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