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
- func KubeClient() (kubernetes.Interface, error)
- func MustToObject(v interface{}, o *otto.Otto) otto.Value
- func Register(vm *otto.Otto) error
- func RegisterWithClient(vm *otto.Otto, c kubernetes.Interface) error
- func ToObject(v interface{}, o *otto.Otto) (otto.Value, error)
- type AppsV1beta1
- type Arity0
- type BatchV1
- type ClientSet
- type ConfigMap
- type CoreV1
- type DaemonSet
- type Deployment
- type Discovery
- type ExtensionsV1beta1
- type Ingress
- type Job
- type Kubernetes
- type Namespace
- type PersistentVolumeClaim
- type Pod
- type PodSecurityPolicy
- type ReplicaSet
- type ReplicationController
- type Runtime
- type Secret
- type Service
- type ServiceAccount
- type StatefulSet
- type ThirdPartyResource
Constants ¶
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 ¶
MustToObject runs ToObject, and panics on failure.
func RegisterWithClient ¶
func RegisterWithClient(vm *otto.Otto, c kubernetes.Interface) error
RegisterWithClient registers the Kubernetes object to an existing Kubernetes client.
Types ¶
type AppsV1beta1 ¶
type AppsV1beta1 struct {
StatefulSet *StatefulSet `otto:"statefulset"`
}
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 ¶
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 ¶
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 ¶
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 ¶
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"` }
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"` }
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 ¶
MustToObject runs ToObject, and panics on failure.
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"` }
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 ¶
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