Code Monkey home page Code Monkey logo

ktransform's Introduction

ktransform

Kubernetes CRD and controller to transform Secrets and ConfigMaps using jq queries.

Installation

Install CRDs:

kubectl apply -k github.com/mgoltzsche/ktransform/deploy/crds

Install the operator in the current namespace:

kubectl apply -k github.com/mgoltzsche/ktransform/deploy

Usage

The following example transforms two docker registry Secrets and a ConfigMap into a makisu config Secret.

Create the input Secrets:

for i in 1 2; do
  kubectl create secret docker-registry regcred$i \
    --docker-server=registry${i}.example.org \
    --docker-username=usr --docker-password=pw$i \
    [email protected]
done

Create an input ConfigMap:

kubectl create configmap myconf \
  --from-literal=myconf=$'registries:\n- registry0.example.org\n- registry1.example.org' \
  --from-literal=myval=somevalue

Merge and convert all three resources to a single Secret:

kubectl apply -f - <<-EOF
apiVersion: ktransform.mgoltzsche.github.com/v1alpha1
kind: SecretTransform
metadata:
  name: dockertomakisuconf
spec:
  input:
    secret1:
      secret: regcred1
    secret2:
      secret: regcred2
    config:
      configMap: myconf
  output:
  - secret:
      name: makisu-conf
      type: Opaque
    transformation:
      primary: .config.myconf.object.registries[0]
      secondary: .config.myconf.object.registries[1]
      myval: .config.myval.string
      makisu.conf: |
        (.secret1[".dockerconfigjson"].object.auths * .secret2[".dockerconfigjson"].object.auths) |
          with_entries(.value |= {
            ".*": {
              security: {
                basic: .auth | @base64d | split(":") | {
                  username: .[0],
                  password: .[1]
                }
              }
            }
          })
EOF

A SecretTransform's status is reflected in its Synced condition. In case of an error this condition provides more information.

When the condition is met the Secret makisu-conf has been written:

$ kubectl get secret makisu-conf -o jsonpath='{.data.primary}' | base64 -d && echo
registry0.example.org
$ kubectl get secret makisu-conf -o jsonpath='{.data.secondary}' | base64 -d && echo
registry1.example.org
$ kubectl get secret makisu-conf -o jsonpath='{.data.myval}' | base64 -d && echo
somevalue
$ kubectl get secret makisu-conf -o jsonpath='{.data.makisu\.conf}' | base64 -d | jq .
{
  "registry1.example.org": {
    ".*": {
      "security": {
        "basic": {
          "password": "pw1",
          "username": "usr"
        }
      }
    }
  },
  "registry2.example.org": {
    ".*": {
      "security": {
        "basic": {
          "password": "pw2",
          "username": "usr"
        }
      }
    }
  }
}

When any input or output resource changes the transformation is reconciled. If an input resource does not (yet) exist or is deleted the transformation is reconciled after 30 seconds.

Updating workloads referring to transformation outputs

While ktransform continuously applies transformations when any input or output changes it does not update Deployments/StatefulSets/DaemonSets that refer to output resources. However this can be achieved using wave.

How to build

make

How to test

Run unit tests:

make unit-tests

Run e2e tests:

make start-minikube
make e2e-tests

ktransform's People

Contributors

mgoltzsche avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

rozcietrzewiacz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.