kubernetes

package
v0.15.14 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 28 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

View Source
const (
	IngressAPIVersionExtensions = "extensions/v1beta1"
	IngressAPIVersionNetworking = "networking.k8s.io/v1"
)
View Source
const (
	DefaultClusterLocalDomain = ".cluster.local"
)

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")
)
View Source
var ErrNoPermissionToAccessResource = errors.New("no permission to access resource")
View Source
var ErrResourceNotFound = errors.New("resource not found")

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, ingressAPIVersion string, ingressClassFilters []string, ingressDefaultSecurityGroup, ingressDefaultSSLPolicy, ingressDefaultLoadBalancerType, clusterLocalDomain string, disableInstrumentedHttpClient bool) (*Adapter, error)

NewAdapter creates an Adapter for Kubernetes using a given configuration.

func (*Adapter) GetConfigMap added in v0.8.13

func (a *Adapter) GetConfigMap(namespace, name string) (*ConfigMap, error)

GetConfigMap retrieves the ConfigMap with name from namespace.

func (*Adapter) IngressFiltersString added in v0.6.9

func (a *Adapter) IngressFiltersString() string

Get ingress class filters that are used to filter ingresses acted upon.

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 filtered by class. It returns the Ingress business object, that for the controller does not matter to be routegroup or ingress..

func (*Adapter) ListResources added in v0.10.0

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

ListResources can be used to obtain the list of ingress and routegroup resources for all namespaces filtered by class. It returns the Ingress business object, that for the controller does not matter to be routegroup or ingress..

func (*Adapter) ListRoutegroups added in v0.10.0

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

ListRoutegroups can be used to obtain the list of Ingress resources for all namespaces filtered by class. It returns the Ingress business object, that for the controller does not matter to be routegroup or ingress.

func (*Adapter) NewInclusterConfigClientset added in v0.12.17

func (a *Adapter) NewInclusterConfigClientset(ctx context.Context) error

func (*Adapter) PodInformer added in v0.12.17

func (a *Adapter) PodInformer(ctx context.Context, endpointChan chan<- []string) (err error)

PodInformer is a event handler for Pod events registered to, that builds a local list of valid and relevant pods and sends an event to the endpoint channel, triggering a resync of the targets.

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.

func (*Adapter) WithTargetCNIPodSelector added in v0.12.17

func (a *Adapter) WithTargetCNIPodSelector(ns string, selector string) *Adapter

WithTargetCNIPodSelector returns the receiver adapter after setting the TargetCNIPodSelector config.

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.
	TokenProvider secrets.SecretsProvider

	// 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 ConfigMap added in v0.8.13

type ConfigMap struct {
	Namespace string
	Name      string
	Data      map[string]string
}

ConfigMap is the ingress-controller's representation of a Kubernetes ConfigMap

func (*ConfigMap) String added in v0.8.13

func (c *ConfigMap) String() string

String implements fmt.Stringer.

type Ingress

type Ingress struct {
	ResourceType     IngressType
	Namespace        string
	Name             string
	Shared           bool
	HTTP2            bool
	ClusterLocal     bool
	CertificateARN   string
	Hostname         string
	Scheme           string
	SecurityGroup    string
	SSLPolicy        string
	IPAddressType    string
	LoadBalancerType string
	WAFWebACLID      string
	Hostnames        []string
}

Ingress is the ingress-controller's business object. It is used to store Kubernetes ingress and routegroup resources.

func (*Ingress) String

func (i *Ingress) String() string

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

type IngressType added in v0.12.30

type IngressType string
const (
	TypeIngress    IngressType = "ingress"
	TypeRouteGroup IngressType = "routegroup"
)

type ResourceLocation added in v0.8.13

type ResourceLocation struct {
	Name      string
	Namespace string
}

ResourceLocation defines the location of Kubernetes resource in a particular namespace.

func ParseResourceLocation added in v0.8.13

func ParseResourceLocation(s string) (*ResourceLocation, error)

ParseResourceLocation parses a Kubernetes resource location from string. Returns an error if the string does not match the expected format of `namespace/name`.

func (*ResourceLocation) String added in v0.8.13

func (r *ResourceLocation) String() string

String implements fmt.Stringer.

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