Categorygithub.com/yue9944882/kubernetes-client-lambda

# README

Kubernetes Client Lambda

Build Status codecov Go Doc

logo

What is Kubernetes Client Lambda?

Kubernetes Client Lambda (aka KCL) is a wrapper library for kubernetes/client-go. Basically it contains these following feature:

  • Dynamic client & client pool
  • Hide details about client-go's informer and lister.
  • Hide annoying group & versions and use resources as enum.
  • Lambda styled resource filtering & manipulating. (inspired by Groovy)
  • It's really easy to use.

With KCL, you can operate kubernetes resources like this example:

// See doc for more info about lambda functions Grep / Map..
import kubernetes "github.com/yue9944882/kubernetes-client-lambda"

// In-Cluster example
// var kcl kubernetes.KubernetesClientLambda = kubernetes.InCluster()
kubernetes.InCluster().Type(kubernetes.ReplicaSet).InNamespace("test").
    List().
    NamePrefix("foo-").
    Map(func(rs *api_ext_v1.ReplicaSet) rs*api_ext_v1.ReplicaSet {
        // Edit in-place or clone a new one
        rs.Meta.Labels["foo-label1"] = "test" 
        return rs
    }).Update()


// Out-Of-Cluster example
kubernetes.OutOfClusterDefault().Type(kubernetes.Pod).InNamespace("devops").
    List().
    NameEqual("test-pod").Each(
        func(pod *api_v1.Pod) {
            count++
    })

As the following example is shown, Calling Mock() on Kubernetes Type Enumeration will create the expected mocking resources for you:

import kubernetes "github.com/yue9944882/kubernetes-client-lambda"

var kcl KubernetesClientLambda = kubernetes.Mock()

How to Get it?

go get github.com/yue9944882/kubernetes-client-lambda

Supported Lambda Function Type

We support following types of lambda function:

Primitive Lambda Type

NameParameter TypeReturn Type
FunctionResource-
ConsumerResource
PredicateResourcebool
Producer-Resource
Kubernetes Resource Lambda Snippet
NamePipelinableDescription
NameEqualyesFilter out resources if its name mismatches
NamePrefixyesFilter out resources if its name doesn't have the prefix
NameRegexyesFilter out resources if its name doesn't match the regular expression
HasAnnotationyesFilter out resources if it doesn't have the annotation
HasAnnotationKeyyesFilter out resources if it doesn't have the annotation key
HasLabelyesFilter out resources if it doesn't have the label
HasLabelKeyyesFilter out resources if it doesn't have the label key

And these lambda can be consumed by following function:

Primitive Pipeline Type
NamePipelinableLambda TypeDescription
Collectyes-Deep copies the elements and put them into collection
AddyesProducerAdd the element returned by lambda into collection
MapyesConsumerAdd all the elements returned by lambda to a new collection
GrepyesPredicateRemove the element from collection if applied lambda returned a false
FirstyesPredicateTake only the first element when applied lambda returned a true
IternoFunctionApply the lambda to every elements in the collection

Primitive methods like CreateIfNotExist, DeleteIfExist have no parameter and just consumes all elements at the end of the pipelining. Here are supported primitive kubernetes operation functions below:

Basic Operation
OperationParamReturn1Return2
EachFunctionlambda error-
AnyPredicateboollambda error
EveryPredicateboollambda error
NotEmpty-boollambda error
Kubernetes Operation
OperationParamReturn1Return2
Create-bool(sucess)lambda error
CreateIfNotExists-bool(success)lambda error
Delete-bool(sucess)lambda error
DeleteIfExists-bool(success)lambda error
Update-bool(sucess)lambda error
UpdateIfExists-bool(success)lambda error
UpdateOrCreate-bool(success)lambda error

# Packages

No description provided by the author

# Functions

getResouceIndexerInstance blocks until initIndexer is invoked.
No description provided by the author
the mock KubernetesClient is statusful and if you want to reset its status then use MockReset.
No description provided by the author
OutOfClusterDefault loads configuration from ~/.kube/config.
OutOfClusterInContext is used to switch context of multi-cluster kubernetes.

# Variables

rbac.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
autoscaling.
No description provided by the author
extensions.
batch.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
core.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
apps.
storage.

# Structs

ErrMultiLambdaFailure contains one or more error occured from lambda invocation chain.
FakeClient is a fake implementation of dynamic.Interface.
FakeClientPool provides a fake implementation of dynamic.ClientPool.
FakeResourceClient is a fake implementation of dynamic.ResourceInterface.
Lambda is a basic and core type of KCL.
Resource is kubernetes resource enumeration hiding api version.

# Interfaces

Consumer is a function has one parameter and returns one value.
Function is a function has one parameter and has no return value.
KubernetesClientLambda provides manipulation interface for resources.
Predicate is a function has only one parameter and return boolean.
Producer is a function takes no parameter and returns a value.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author