Categorygithub.com/yue9944882/kubernetes-client-lambda
repositorypackage
1.1.0
Repository: https://github.com/yue9944882/kubernetes-client-lambda.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# 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