kube

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PodPending means the pod has been accepted by the system, but one or more of the containers
	// has not been started. This includes time before being bound to a node, as well as time spent
	// pulling images onto the host.
	PodPending PodPhase = PodPhase(v1.PodPending)
	// PodRunning means the pod has been bound to a node and all of the containers have been started.
	// At least one container is still running or is in the process of being restarted.
	PodRunning PodPhase = PodPhase(v1.PodRunning)
	// PodSucceeded means that all containers in the pod have voluntarily terminated
	// with a container exit code of 0, and the system is not going to restart any of these containers.
	PodSucceeded PodPhase = PodPhase(v1.PodSucceeded)
	// PodFailed means that all containers in the pod have terminated, and at least one container has
	// terminated in a failure (exited with a non-zero exit code or was stopped by the system).
	PodFailed PodPhase = PodPhase(v1.PodFailed)
	// PodUnknown means that for some reason the state of the pod could not be obtained, typically due
	// to an error in communicating with the host of the pod.
	PodUnknown PodPhase = PodPhase(v1.PodUnknown)

	Added    EventType = EventType(watch.Added)
	Modified EventType = EventType(watch.Modified)
	Deleted  EventType = EventType(watch.Deleted)
	Bookmark EventType = EventType(watch.Bookmark)
	Error    EventType = EventType(watch.Error)

	// Maximum number of retries por handler
	MaxRetries = 3
)
View Source
const (
	BUFFER_POOL_SIZE = 32 * 1024 // Same as default pool size for httputil.ReverseProxy
)

Variables

View Source
var CacheSyncError = errors.New("Failed to synchronize cache")
View Source
var ErrorFactoryCancelled = errors.New("PodFactory is being cancelled")

Functions

This section is empty.

Types

type API

type API struct {
	Logger         *log.Logger
	KubeconfigPath string
	Namespace      string
	// contains filtered or unexported fields
}

API encapsulates calls to Kubernetes API

func Loop

func Loop(logger *log.Logger, namespace string, handler EventHandler, threads int, labels map[string]string) (*API, error)

Loop tries to build API by autodiscovering cluster and namespace

func (*API) Cancel

func (k *API) Cancel()

Cancel the factory and listeners

func (*API) CreatePod

func (k *API) CreatePod(ctx context.Context, desc *PodDescriptor) error

CreatePod with given PodDescriptor

func (*API) Decode

func (k *API) Decode(template string) (*PodDescriptor, error)

Decode reads the yaml descriptor for a pod

func (*API) DeletePod

func (k *API) DeletePod(ctx context.Context, name string) error

DeletePod destroys pod by name

func (*API) PodStatus

func (k *API) PodStatus(name string) (PodInfo, error)

PodStatus gets the pod's current status and IP address

func (*API) ServerVersion

func (k *API) ServerVersion() (*version.Info, error)

ServerVersion returns server version

type EventHandler

type EventHandler interface {
	Update(info PodInfo) error
}

EventHandler manages events

type EventType

type EventType string

EventType encapsulates kubernetes own EventType type

type Factory

type Factory struct {
	// Keeper must be at the top of the struct for atomic calls
	clock.Keeper
	Logger   *log.Logger
	Template *template.Template
	Lifetime time.Duration
	ForwardPort
	PrefixPort     map[string]ForwardPort // Additional ports for custom path prefixes
	ForwardedProto string
	BufferPool     sync.Pool
	SessionCookie  string

	Labels map[string]string
	// contains filtered or unexported fields
}

func NewFactory

func NewFactory(logger *log.Logger, tmpl *template.Template, lifetime time.Duration, defaultPort ForwardPort, prefixPort map[string]ForwardPort, forwardedProto string, sessionCookie string, labels map[string]string) *Factory

NewFactory creates a Factory for Managers

func (*Factory) Find

func (f *Factory) Find(api *API, creds auth.Credentials) (*Manager, error)

Find manager for the given credentials.

func (*Factory) Get

func (f *Factory) Get() []byte

Get implements httputil.BufferPool

func (*Factory) Put

func (f *Factory) Put(buf []byte)

Put implements httputil.BufferPool

func (*Factory) Update

func (f *Factory) Update(info PodInfo) error

Update manager status on pod info received

type ForwardPort added in v0.3.8

type ForwardPort struct {
	Scheme string
	Port   int
}

ForwardPort defines scheme and port for proxied pod

type JWTSession

type JWTSession interface {
	JWT() (string, time.Time, error)
}

JWTSession returns a JWT token and expiration time

type Manager

type Manager struct {
	// Timestamp of last update to be used by PodFactory.
	// Must be at the top of the struct for atomic ops to work.
	Timestamp  clock.AtomicTimestamp
	Logger     *log.Logger
	Descriptor *PodDescriptor
	// Scheme and port of the backend server to proxy to.
	// The IP address will be learnt from the kube cluster.
	ForwardPort
	PrefixPort     map[string]ForwardPort // Additional ports for custom path prefixes
	ForwardedProto string
	Pool           httputil.BufferPool
	// latest status detected and resulting reverse proxy
	SessionCookie string
	// contains filtered or unexported fields
}

Manager handles the suscription to a pod's events

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, api *API) error

Delete the pod

func (*Manager) Proxy

func (m *Manager) Proxy(ctx context.Context, api *API, create bool) (*PodProxy, PodInfo, error)

Proxy returns a PodProxy instance to current pod's IP. If create == true, the pod will be scheduled for creation if not existing. Beware that the proxy might be nil if no IP, even when error == nil.

func (*Manager) Update

func (m *Manager) Update(info PodInfo) error

Update the pod info where there is a status change

type PodDescriptor

type PodDescriptor = v1.Pod

PodDescriptor is an alias to avoid having to import the v1 apis in other files.

type PodInfo

type PodInfo struct {
	Name    string
	Type    EventType
	Phase   PodPhase
	Address string
	Ready   bool
}

PodInfo encapsulates the pod information delivered.

type PodKindError

type PodKindError string

PodKindError raised when received event for an object which is not a pod.

func (PodKindError) Error

func (err PodKindError) Error() string

type PodParameters

type PodParameters struct {
	Username  string
	Service   string
	Namespace string
}

PodParameters are the parameters for the pod template

type PodPhase

type PodPhase string

PodPhase encapsulates kubernetes own PodPhase type

type PodProxy

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

func (*PodProxy) CurrentSession

func (p *PodProxy) CurrentSession(session JWTSession)

CurrentSession resets the auth Session

func (*PodProxy) ServeHTTP added in v0.3.8

func (p *PodProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

Jump to

Keyboard shortcuts

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