kubernetes

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package kubernetes provides some higher level Kubernetes abstractions to orchestrate Ingress resources.

Operations

The exported Adapter provides a limited set of operations that can be used to:

  • List Ingress resources
  • Update the Hostname attribute of Ingress load balancer objects

Usage

The Adapter can be created with the typical in-cluster configuration. This configuration depends on some specific Kubernetes environment variables and files, required to communicate with the API server:

  • Environment variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT
  • OAuth2 Bearer token contained in the file /var/run/secrets/kubernetes.io/serviceaccount/token
  • The Root CA certificate contained in the file /var/run/secrets/kubernetes.io/serviceaccount/ca.crt

This is the preferred way and should be as simples as:

config, err := InClusterConfig()
if err != nil {
    log.Fatal(err)
}
kubeAdapter, err := kubernetes.NewAdapter(config)
if err != nil {
    log.Fatal(err)
}
ingresses, err := kubeAdapter.ListIngress() // for ex.

For local development it is possible to create an Adapter using an insecure configuration.

For example:

config := kubernetes.InsecureConfig("http://localhost:8001")
kubeAdapter, err := kubernetes.NewAdapter(config)
if err != nil {
    log.Fatal(err)
}
ingresses, err := kubeAdapter.ListIngress() // for ex.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingKubernetesEnv is returned when the Kubernetes API server environment variables are not defined
	ErrMissingKubernetesEnv = errors.New("unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and " +
		"KUBERNETES_SERVICE_PORT are not defined")
	// ErrInvalidIngressUpdateParams is returned when a request to update ingress resources has an empty DNS name
	// or doesn't specify any ingress resources
	ErrInvalidIngressUpdateParams = errors.New("invalid ingress update parameters")
	// ErrInvalidIngressUpdateARNParams is returned when a request to update ingress resources has an empty ARN
	// or doesn't specify any ingress resources
	ErrInvalidIngressUpdateARNParams = errors.New("invalid ingress updateARN parameters")
	// ErrUpdateNotNeeded is returned when an ingress update call doesn't require an update due to already having
	// the desired hostname
	ErrUpdateNotNeeded = errors.New("update to ingress resource not needed")
	// ErrInvalidConfiguration is returned when the Kubernetes configuration is missing required attributes
	ErrInvalidConfiguration = errors.New("invalid Kubernetes Adapter configuration")
	// ErrInvalidCertificates is returned when the CA certificates required to communicate with the
	// API server are invalid
	ErrInvalidCertificates = errors.New("invalid CA certificates")
)

Functions

This section is empty.

Types

type Adapter added in v0.1.1

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

func NewAdapter added in v0.1.1

func NewAdapter(config *Config) (*Adapter, error)

NewAdapter creates an Adapter for Kubernetes using a given configuration.

func (*Adapter) ListIngress added in v0.1.1

func (a *Adapter) ListIngress() ([]*Ingress, error)

ListIngress can be used to obtain the list of ingress resources for all namespaces.

func (*Adapter) UpdateIngressLoadBalancer added in v0.1.1

func (a *Adapter) UpdateIngressLoadBalancer(ingress *Ingress, loadBalancerDNSName string) error

UpdateIngressLoadBalancer can be used to update the loadBalancer object of an ingress resource. It will update the hostname property with the provided load balancer DNS name.

type Config added in v0.1.1

type Config struct {
	// BaseURL must be a URL to the base of the apiserver.
	BaseURL string

	// Server requires Bearer authentication. This client will not
	// attempt to use refresh tokens for an OAuth2 flow.
	// TODO: demonstrate an OAuth2 compatible client.
	BearerToken string

	// TLSClientConfig contains settings to enable transport layer
	// security
	TLSClientConfig

	// Server should be accessed without verifying the TLS
	// certificate. For testing only.
	Insecure bool

	// UserAgent is an optional field that specifies the caller of
	// this request.
	UserAgent string

	// The maximum length of time to wait before giving up on a
	// server request. A value of zero means no timeout.
	Timeout time.Duration
}

Config holds the common attributes that can be passed to a Kubernetes client on initialization.

Mostly copied from https://github.com/kubernetes/client-go/blob/master/rest/config.go

func InClusterConfig added in v0.1.1

func InClusterConfig() (*Config, error)

InClusterConfig creates a configuration for the Kubernetes Adapter that will communicate with the API server using TLS and authenticate with the cluster provide Bearer token. The environment should contain variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT. The CA certificate and Bearer token will also be taken from the Kubernetes environment.

func InsecureConfig added in v0.1.1

func InsecureConfig(apiServerBaseURL string) *Config

InsecureConfig creates a configuration for the Kubernetes Adapter that won't use any encryption or authentication mechanisms to communicate with the API Server. This should be used only for local development, as usually provided by the kubectl proxy

type Ingress

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

Ingress is the ingress-controller's business object

func (*Ingress) CertHostname added in v0.1.2

func (i *Ingress) CertHostname() string

CertHostname returns the DNS hostname associated with the ingress gotten from Kubernetes Spec

func (*Ingress) CertificateARN

func (i *Ingress) CertificateARN() string

CertificateARN returns the AWS certificate (IAM or ACM) ARN found in the ingress resource metadata. It returns an empty string if the annotation is missing.

func (*Ingress) Hostname

func (i *Ingress) Hostname() string

Hostname returns the DNS LoadBalancer hostname associated with the ingress gotten from Kubernetes Status

func (*Ingress) Name added in v0.6.2

func (i *Ingress) Name() string

Name returns the ingress name.

func (*Ingress) Namespace added in v0.6.2

func (i *Ingress) Namespace() string

Namespace returns the ingress namespace.

func (*Ingress) Scheme added in v0.5.0

func (i *Ingress) Scheme() string

Scheme returns the scheme associated with the ingress

func (*Ingress) SetCertificateARN added in v0.1.2

func (i *Ingress) SetCertificateARN(arn string)

SetCertificateARN sets Ingress.certificateARN to the arn as specified.

func (*Ingress) SetScheme added in v0.5.0

func (i *Ingress) SetScheme(scheme string)

SetScheme sets Ingress.scheme to the scheme as specified.

func (*Ingress) Shared added in v0.6.2

func (i *Ingress) Shared() bool

Shared return true if the ingress can share ALB with other ingresses.

func (*Ingress) String

func (i *Ingress) String() string

String returns a string representation of the Ingress instance containing the namespace and the resource name.

type TLSClientConfig added in v0.1.1

type TLSClientConfig struct {
	// Trusted root certificates for server
	CAFile string
}

TLSClientConfig contains settings to enable transport layer security

Jump to

Keyboard shortcuts

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