libk8s

package
v0.0.0-...-49b5ceb Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package libk8s provides a JavaScript library for Kubernetes.

This exposes substantial portions of the Go API to JavaScript. Using this library, scripts can interact with a Kubernetes API server using a structure very similar to the native Go API for Kubernetes.

In many cases, we emulate JavaScript patterns in Go (such as the frequent use of 'Get' and 'Set' in function names). We do this because it is more important that the user-facing JavaScript runtime follow idiomatic JS than that the internal API follows idiomatic Go.

The JavaScript API is basically a simplified version of the Client-Go API. We've made the following simplifications:

  • Namespace is bubbled to almost the top of the API so that it is set once and re-used internally. 'k = kubernetes.withNS("default"); k.coreV1.pods.get(...)'
  • Discovery and namespace info is moved to the top of the API for convenience.
  • Using annotations, we export the most stable version of a group without version numbers. For example `k.coreV1.pods` is the same as `k.core.pods`.
  • Credential info is not passed into the runtime.
  • Kubernetes objects (e.g. a pod definition) are plain JavaScript objects, not JSON, exact replcias of Go types, or special constructions. When passed into a Go function, they are converted into the native Go type by unmarshaling JSON.
  • Wherever possible, we've converted functions to properties.

Index

Constants

View Source
const KubernetesErrorType = "KubernetesError"

KubernetesErrorType is the string name of the JavaScript error type.

Variables

This section is empty.

Functions

func KubeClient

func KubeClient() (kubernetes.Interface, error)

KubeClient returns an initialized Kubernetes client.

Normally, it is best to use Register() instead.

This will attempt to load a KUBECONFIG from a variety of well-known locations and formats. Then it will initialize a client with the found configuration.

func MustToObject

func MustToObject(v interface{}, o *otto.Otto) otto.Value

MustToObject runs ToObject, and panics on failure.

func Register

func Register(vm *otto.Otto) error

Register registers the top-level Kubernetes API objects with the JS runtime.

func RegisterWithClient

func RegisterWithClient(vm *otto.Otto, c kubernetes.Interface) error

RegisterWithClient registers the Kubernetes object to an existing Kubernetes client.

func ToObject

func ToObject(v interface{}, o *otto.Otto) (otto.Value, error)

ToObject marshals an interface to JSON, and then creates a JavaScript object. The object is then returned as a value.

Types

type AppsV1beta1

type AppsV1beta1 struct {
	StatefulSet *StatefulSet `otto:"statefulset"`
}

type Arity0

type Arity0 func() otto.Value

Arity0 is a JavaScript function with arity 0

type BatchV1

type BatchV1 struct {
	Job *Job `otto:"job"`
}

type ClientSet

type ClientSet struct {
	GetNS func() otto.Value `otto:"getNS"`

	CoreV1            *CoreV1            `otto:"coreV1,alias=core"`
	AppsV1beta1       *AppsV1beta1       `otto:"appsV1beta1,alias=apps"`
	BatchV1           *BatchV1           `otto:"batchV1,alias=batch"`
	ExtensionsV1beta1 *ExtensionsV1beta1 `otto:"extensionsV1beta1,alias=extensions"`
}

ClientSet models the Kubernetes Interface interface.

It provides access to all of the defined resource groups.

In JavaScript, you get one of these using `kubernetes.withNS(ns)`.

func NewClientSet

func NewClientSet(vm *otto.Otto, c kubernetes.Interface, ns string) *ClientSet

type ConfigMap

type ConfigMap struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewConfigMap

func NewConfigMap(c kubernetes.Interface, o *otto.Otto, ns string) *ConfigMap

type CoreV1

type CoreV1 struct {
	Namespace             *Namespace             `otto:"namespace"`
	Pod                   *Pod                   `otto:"pod"`
	Secret                *Secret                `otto:"secret"`
	Service               *Service               `otto:"service"`
	ServiceAccount        *ServiceAccount        `otto:"serviceaccount"`
	PersistentVolumeClaim *PersistentVolumeClaim `otto:"persistentvolumeclaim"`
	ReplicationController *ReplicationController `otto:"replicationcontroller"`
}

type DaemonSet

type DaemonSet struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewDaemonSet

func NewDaemonSet(c kubernetes.Interface, o *otto.Otto, ns string) *DaemonSet

type Deployment

type Deployment struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewDeployment

func NewDeployment(c kubernetes.Interface, o *otto.Otto, ns string) *Deployment

type Discovery

type Discovery struct {
	ServerVersion                      Arity0                          `otto:"serverVersion"`
	ServerGroups                       Arity0                          `otto:"serverGroups"`
	SwaggerSchema                      func(string, string) otto.Value `otto:"swaggerSchema"`
	ServerResourcesForGroupVersion     func(string) otto.Value         `otto:"serverResourcesForGroupVersion"`
	ServerResources                    Arity0                          `otto:"serverResources"`
	ServerPreferredNamespacedResources Arity0                          `otto:"serverPreferredNamespacedResources"`
	ServerPreferredResources           Arity0                          `otto:"serverPreferredResources"`
}

func NewDiscovery

func NewDiscovery(c kubernetes.Interface, o *otto.Otto) *Discovery

type ExtensionsV1beta1

type ExtensionsV1beta1 struct {
	ConfigMap          *ConfigMap          `otto:"configmap"`
	Deployment         *Deployment         `otto:"deployment"`
	ReplicaSet         *ReplicaSet         `otto:"replicaset"`
	DaemonSet          *DaemonSet          `otto:"daemonset"`
	Ingress            *Ingress            `otto:"ingress"`
	PodSecurityPolicy  *PodSecurityPolicy  `otto:"podsecuritypolicy"`
	ThirdPartyResource *ThirdPartyResource `otto:"thirdpartyresource"`
}

type Ingress

type Ingress struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewIngress

func NewIngress(c kubernetes.Interface, o *otto.Otto, ns string) *Ingress

type Job

type Job struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewJob

func NewJob(c kubernetes.Interface, o *otto.Otto, ns string) *Job

type Kubernetes

type Kubernetes struct {
	// WithNS initializes another Kubernetes object, but with a different namespace.
	WithNS func(string) otto.Value `otto:"withNS"`
	// GetNS returns the default namespace, if set.
	GetNS func() otto.Value `otto:"getNS"`
	// GetNamespaces returns an array of all of the namespace names.
	// This is bubbled to the top so that scripts may discover the available
	// namespaces before creating namespaced objects.
	GetNamespaces func() otto.Value `otto:"getNamespaces"`
	// Discovery returns the Discovery object for whatever the stable discovery
	// implementation is. This is bubbled to the top so that the top-level
	// client can make decisions about which API version to use before actually
	// (intentionally) using the API.
	Discovery *Discovery `otto:"discovery"`
	// Namespace gives full access to the Namespace group.
	// This uses the most stable version of Namespaces (currently CoreV1). It is
	// exposed here so that clients can determine information about namespace
	// before working with the core API.
	Namespace *Namespace `otto:"namespace"`
}

Kubernetes is the top-level object exposed to JavaScript.

It provides access to the latest supported versions of the built-in API, along with partiall tooling for ThirdPartyResources.

Not all of the API is exposed. Emphasis has been given to commonly-used APIs that follow a consistent pattern.

In many cases, the APIs function by executing Go functions and then marshaling the results to their JSON equivalent, which can then be loaded into the JavaScript runtime as-is.

Objects created in JavaScript are passed into Go as maps, and are then typed by unmarshaling them into their respective JSON struct.

func NewKubernetes

func NewKubernetes(vm *otto.Otto, c kubernetes.Interface, ns string) *Kubernetes

type Namespace

type Namespace struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewNamespace

func NewNamespace(c kubernetes.Interface, o *otto.Otto) *Namespace

type PersistentVolumeClaim

type PersistentVolumeClaim struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewPersistentVolumeClaim

func NewPersistentVolumeClaim(c kubernetes.Interface, o *otto.Otto, ns string) *PersistentVolumeClaim

type Pod

type Pod struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewPod

func NewPod(c kubernetes.Interface, o *otto.Otto, ns string) *Pod

type PodSecurityPolicy

type PodSecurityPolicy struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewPodSecurityPolicy

func NewPodSecurityPolicy(c kubernetes.Interface, o *otto.Otto) *PodSecurityPolicy

type ReplicaSet

type ReplicaSet struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewReplicaSet

func NewReplicaSet(c kubernetes.Interface, o *otto.Otto, ns string) *ReplicaSet

type ReplicationController

type ReplicationController struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewReplicationController

func NewReplicationController(c kubernetes.Interface, o *otto.Otto, ns string) *ReplicationController

type Runtime

type Runtime struct {
	DefaultNamespace string `otto:"defaultNamespace"`
	// contains filtered or unexported fields
}

func (*Runtime) MustRemarshal

func (r *Runtime) MustRemarshal(src, dest interface{})

MustRemarshal remarshals the src interface into the dest interface.

It does this via the built-in JSON marshal.

The intent of this function is to leverage the JSON marshal to convert between untyped native JS objects and typed Go Kubernetes API objects.

func (*Runtime) MustToObject

func (r *Runtime) MustToObject(v interface{}) otto.Value

MustToObject runs ToObject, and panics on failure.

func (*Runtime) POE

func (r *Runtime) POE(err error)

POE panics on error (in a way that is try/catchable to JS)

If the given error is non-nil, this panics. THe panic value is a custom JavaScript type (KubernetesError)

func (*Runtime) ToObject

func (r *Runtime) ToObject(v interface{}) (otto.Value, error)

ToObject marshals an interface to JSON, and then creates a JavaScript object. The object is then returned as a value.

type Secret

type Secret struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewSecret

func NewSecret(c kubernetes.Interface, o *otto.Otto, ns string) *Secret

type Service

type Service struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewService

func NewService(c kubernetes.Interface, o *otto.Otto, ns string) *Service

type ServiceAccount

type ServiceAccount struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewServiceAccount

func NewServiceAccount(c kubernetes.Interface, o *otto.Otto, ns string) *ServiceAccount

type StatefulSet

type StatefulSet struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	UpdateStatus     func(map[string]interface{}) otto.Value `otto:"updateStatus"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewStatefulSet

func NewStatefulSet(c kubernetes.Interface, o *otto.Otto, ns string) *StatefulSet

type ThirdPartyResource

type ThirdPartyResource struct {
	Create           func(map[string]interface{}) otto.Value `otto:"create"`
	Delete           func(string, map[string]interface{})    `otto:"delete"`
	List             func(map[string]interface{}) otto.Value `otto:"list"`
	Get              func(string) otto.Value                 `otto:"get"`
	Update           func(map[string]interface{}) otto.Value `otto:"update"`
	DeleteCollection func(dopt, lopt map[string]interface{}) `otto:"deleteCollection"`
}

func NewThirdPartyResource

func NewThirdPartyResource(c kubernetes.Interface, o *otto.Otto) *ThirdPartyResource

Jump to

Keyboard shortcuts

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