Git Product home page Git Product logo

go-template-utils's Introduction

License

What is go-template-utils?

A library for processing Go templates in policy templates or other Open Cluster Management objects.

Go to the Contributing guide to learn how to get involved.

  • The go-template-utils repository is part of the open-cluster-management community. For more information, visit: open-cluster-management.io.

How do templates work?

To get started, use the templates.NewResolver function along with a templates.Config instance.

See the ResolveTemplate example for an example of how to use this library.

Under the hood, go-template-utils wraps the text/template package. This means that as long as the input to templates.ResolveTemplate can be marshaled to YAML, any of the text/template package features can be used.

Additionally, the following custom functions are supported:

  • atoi parses an input string and returns an integer like the Atoi function. For example, {{ "6" | atoi }}.
  • autoindent will automatically indent the input string based on the leading spaces. For example, {{ "Templating\nrocks!" | autoindent }}.
  • base64enc decodes the input Base64 string to its decoded form. For example, {{ "VGVtcGxhdGVzIHJvY2shCg==" | base64dec }}.
  • base64enc encodes an input string in the Base64 format. For example, {{ "Templating rocks!" | base64enc }}.
  • indent will indent the input string by specified amount. For example, {{ "Templating\nrocks!" | indent 4 }}.
  • fromClusterClaim returns the value of a specific ClusterClaim. For example, {{ fromClusterClaim "name" }}.
  • fromConfigMap returns the value of a key inside a ConfigMap. For example, {{ fromConfigMap "namespace" "config-map-name" "key" }}.
  • fromSecret returns the value of a key inside a Secret. For example, {{ fromSecret "namespace" "secret-name" "key" }}. If the EncryptionMode is set to EncryptionEnabled, this will return an encrypted value.
  • lookup is a generic lookup function for any Kubernetes object. For example, {{ (lookup "v1" "Secret" "namespace" "name").Data.key }}.
  • protect is a function that encrypts any string using AES-CBC.
  • toBool - parses an input boolean string converts it to a boolean but also removes any quotes around the map value. For example, key: "{{ "true" | toBool }}" => key: true.
  • toInt parses an input string and returns an integer but also removes any quotes around the map value. For example, key: "{{ "6" | toInt }}" => key: 6.
  • toLiteral removes any quotes around the template string after it is processed. For example, key: "{{ "[10.10.10.10, 1.1.1.1]" | toLiteral }} => key: [10.10.10.10, 1.1.1.1]. A good use-case for this is when a ConfigMap field contains a JSON string that you want to literally replace the template with and have it treated as the underlying JSON type.

go-template-utils's People

Contributors

mprahl avatar dhaiducek avatar ckandag avatar gparvin avatar brian-jarvis avatar

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.