kubernetes

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: Apache-2.0, MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const KubeConfig = "kubeconfig"

KubeConfig is the key to the kubeconfig

Variables

View Source
var DefaultApplierOptions = ApplierOptions{
	MergeFuncs: map[schema.GroupKind]MergeFunc{
		corev1.SchemeGroupVersion.WithKind("Service").GroupKind(): func(newObj, oldObj *unstructured.Unstructured) {

			oldPorts := oldObj.Object["spec"].(map[string]interface{})["ports"].([]interface{})
			newPorts := newObj.Object["spec"].(map[string]interface{})["ports"].([]interface{})
			ports := []map[string]interface{}{}

			for _, newPort := range newPorts {
				np := newPort.(map[string]interface{})

				for _, oldPort := range oldPorts {
					op := oldPort.(map[string]interface{})

					if fmt.Sprintf("%v", np["port"]) == fmt.Sprintf("%v", op["port"]) {
						if nodePort, ok := op["nodePort"]; ok {
							np["nodePort"] = nodePort
						}
					}
				}
				ports = append(ports, np)
			}

			newObj.Object["spec"].(map[string]interface{})["clusterIP"] = oldObj.Object["spec"].(map[string]interface{})["clusterIP"]
			newObj.Object["spec"].(map[string]interface{})["ports"] = ports
		},
		corev1.SchemeGroupVersion.WithKind("ServiceAccount").GroupKind(): func(newObj, oldObj *unstructured.Unstructured) {

			newObj.Object["secrets"] = oldObj.Object["secrets"]
			newObj.Object["imagePullSecrets"] = oldObj.Object["imagePullSecrets"]
		},
	},
}

DefaultApplierOptions contains options for common k8s objects, e.g. Service, ServiceAccount.

View Source
var NewControllerClient = newControllerClient

NewControllerClient instantiates a new client.Client.

Functions

func NewRuntimeClientForConfig

func NewRuntimeClientForConfig(config *rest.Config, opts client.Options) (client.Client, error)

NewRuntimeClientForConfig returns a new controller runtime client from a config.

func NewRuntimeClientFromBytes

func NewRuntimeClientFromBytes(kubeconfig []byte, opts client.Options) (client.Client, error)

NewRuntimeClientFromBytes creates a new controller runtime Client struct for a given kubeconfig byte slice.

func NewRuntimeClientFromSecret

func NewRuntimeClientFromSecret(secret *corev1.Secret, opts client.Options) (client.Client, error)

NewRuntimeClientFromSecret creates a new controller runtime Client struct for a given secret.

Types

type Applier

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

Applier is a default implementation of the ApplyInterface. It applies objects with by first checking whether they exist and then either creating / updating them (update happens with a predefined merge logic).

func NewApplierForConfig

func NewApplierForConfig(config *rest.Config) (*Applier, error)

NewApplierForConfig creates and returns a new Applier for the given rest.Config.

func NewApplierInternal

func NewApplierInternal(config *rest.Config, discoveryClient discovery.CachedDiscoveryInterface) (*Applier, error)

NewApplierInternal constructs a new Applier from the given config and DiscoveryInterface. This method should only be used for testing. TODO(AC): Once https://github.com/kubernetes/kubernetes/issues/68865 is resolved, this should be adapted to use the updated RESTMapper (https://github.com/kubernetes/kubernetes/issues/75383) and not do the invalidation / checks on its own (depending on whether the controller-runtime/client might even automatically use this updated mapper then).

func (*Applier) ApplyManifest

func (c *Applier) ApplyManifest(ctx context.Context, r UnstructuredReader, options ApplierOptions) error

ApplyManifest is a function which does the same like `kubectl apply -f <file>`. It takes a bunch of manifests <m>, all concatenated in a byte slice, and sends them one after the other to the API server. If a resource already exists at the API server, it will update it. It returns an error as soon as the first error occurs.

func (*Applier) DeleteManifest

func (c *Applier) DeleteManifest(ctx context.Context, r UnstructuredReader) error

DeleteManifest is a function which does the same like `kubectl delete -f <file>`. It takes a bunch of manifests <m>, all concatenated in a byte slice, and sends them one after the other to the API server for deletion. It returns an error as soon as the first error occurs.

type ApplierInterface

type ApplierInterface interface {
	ApplyManifest(ctx context.Context, unstructured UnstructuredReader, options ApplierOptions) error
	DeleteManifest(ctx context.Context, unstructured UnstructuredReader) error
}

ApplierInterface is an interface which describes declarative operations to apply multiple Kubernetes objects.

type ApplierOptions

type ApplierOptions struct {
	MergeFuncs map[schema.GroupKind]MergeFunc
}

ApplierOptions contains options used by the Applier.

func CopyApplierOptions

func CopyApplierOptions(in ApplierOptions) ApplierOptions

CopyApplierOptions returns a copies of the provided applier options.

type ChartApplier

type ChartApplier interface {
	chartrenderer.Interface
	ApplierInterface

	ApplyChartWithOptions(ctx context.Context, chartPath, namespace, name string, defaultValues, additionalValues map[string]interface{}, options ApplierOptions) error
	ApplyChart(ctx context.Context, chartPath, namespace, name string, defaultValues, additionalValues map[string]interface{}) error
	ApplyChartInNamespaceWithOptions(ctx context.Context, chartPath, namespace, name string, defaultValues, additionalValues map[string]interface{}, options ApplierOptions) error
	ApplyChartInNamespace(ctx context.Context, chartPath, namespace, name string, defaultValues, additionalValues map[string]interface{}) error

	DeleteChart(ctx context.Context, chartPath, namespace, name string, defaultValues, additionalValues map[string]interface{}) error
}

ChartApplier is an interface that describes needed methods that render and apply Helm charts in Kubernetes clusters.

func NewChartApplier

func NewChartApplier(renderer chartrenderer.Interface, applier ApplierInterface) ChartApplier

NewChartApplier returns a new chart applier.

func NewChartApplierForConfig

func NewChartApplierForConfig(config *rest.Config) (ChartApplier, error)

NewChartApplierForConfig returns a new chart applier based on the given REST config.

type Clientset

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

Clientset is a struct containing the configuration for the respective Kubernetes cluster, the collection of Kubernetes clients <Clientset> containing all REST clients for the built-in Kubernetes API groups. The RESTClient itself is a normal HTTP client for the respective Kubernetes cluster, allowing requests to arbitrary URLs. The version string contains only the major/minor part in the form <major>.<minor>.

func (*Clientset) Applier

func (c *Clientset) Applier() ApplierInterface

Applier returns the applier of this Clientset.

func (*Clientset) Client

func (c *Clientset) Client() client.Client

Client returns the client of this Clientset.

func (*Clientset) Kubernetes

func (c *Clientset) Kubernetes() kubernetes.Interface

Kubernetes will return the kubernetes attribute of the Client object.

func (*Clientset) RESTClient

func (c *Clientset) RESTClient() rest.Interface

RESTClient will return the restClient attribute of the Client object.

func (*Clientset) RESTConfig

func (c *Clientset) RESTConfig() *rest.Config

RESTConfig will return the config attribute of the Client object.

func (*Clientset) RESTMapper

func (c *Clientset) RESTMapper() meta.RESTMapper

RESTMapper returns the restMapper of this Clientset.

func (*Clientset) Version

func (c *Clientset) Version() string

Version returns the GitVersion of the Kubernetes client stored on the object.

type Interface

type Interface interface {
	RESTConfig() *rest.Config
	RESTMapper() meta.RESTMapper
	RESTClient() rest.Interface

	Client() client.Client
	Applier() ApplierInterface

	Kubernetes() kubernetesclientset.Interface
	Version() string
}

Interface is used to wrap the interactions with a Kubernetes cluster (which are performed with the help of kubernetes/client-go) in order to allow the implementation of several Kubernetes versions.

func NewClientFromBytes

func NewClientFromBytes(kubeconfig []byte, opts client.Options) (Interface, error)

NewClientFromBytes creates a new Client struct for a given kubeconfig byte slice.

func NewClientFromFile

func NewClientFromFile(masterURL, kubeconfigPath string, opts client.Options) (Interface, error)

NewClientFromFile creates a new Client struct for a given kubeconfig. The kubeconfig will be read from the filesystem at location <kubeconfigPath>. If given, <masterURL> overrides the master URL in the kubeconfig. If no filepath is given, the in-cluster configuration will be taken into account.

func NewClientFromSecret

func NewClientFromSecret(k8sClient Interface, namespace, secretName string, opts client.Options) (Interface, error)

NewClientFromSecret creates a new Client struct for a given kubeconfig stored as a Secret in an existing Kubernetes cluster. This cluster will be accessed by the <k8sClient>. It will read the Secret <secretName> in <namespace>. The Secret must contain a field "kubeconfig" which will be used.

func NewClientFromSecretObject

func NewClientFromSecretObject(secret *corev1.Secret, opts client.Options) (Interface, error)

NewClientFromSecretObject creates a new Client struct for a given Kubernetes Secret object. The Secret must contain a field "kubeconfig" which will be used.

func NewForConfig

func NewForConfig(config *rest.Config, options client.Options) (Interface, error)

NewForConfig returns a new Kubernetes base client.

type MergeFunc

type MergeFunc func(newObj, oldObj *unstructured.Unstructured)

MergeFunc determines how oldOj is merged into new oldObj.

type UnstructuredReader

type UnstructuredReader interface {
	Read() (*unstructured.Unstructured, error)
}

UnstructuredReader an interface that all manifest readers should implement

func NewManifestReader

func NewManifestReader(manifest []byte) UnstructuredReader

NewManifestReader initializes a reader for yaml manifests

func NewNamespaceSettingReader

func NewNamespaceSettingReader(mReader UnstructuredReader, namespace string) UnstructuredReader

NewNamespaceSettingReader initializes a reader for yaml manifests with support for setting the namespace

func NewObjectReferenceReader

func NewObjectReferenceReader(objectReference *corev1.ObjectReference) UnstructuredReader

NewObjectReferenceReader initializes a reader from ObjectReference

Jump to

Keyboard shortcuts

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