Coder Social home page Coder Social logo

kylemcc / kube-gen Goto Github PK

View Code? Open in Web Editor NEW
64.0 4.0 22.0 15.61 MB

Generate files from Kubernetes events

License: BSD 3-Clause "New" or "Revised" License

Go 88.50% Makefile 9.92% Dockerfile 1.59%
kubernetes kubernetes-events golang automation templates

kube-gen's Introduction

kube-gen

latest 0.4.0 license Check Commit

kube-gen is a template rendering tool that generates files and executes commands based on Kubernetes events and metadata.

Installation

Binary Download

See the Releases page

Docker Container

kube-gen can be run as a standalone container, or bundled in a container with other applications.

Images are available on Dockerhub:

$ docker run kylemcc/kube-gen ...

Or Github Package Registry:

$ docker run ghcr.io/kylemcc/kube-gen/kube-gen ...

Usage

When run with no arguments (or with -h/-help), kube-gen prints the following usage message.

$ kube-gen
Usage: kube-gen [options] <template> [<output>]

Render templates using Kubernetes metadata and events

Options:
  -host string
        If not set will use kubeconfig. If using proxy - set it to http://localhost:8001
  -interval int

  -kubeconfig string
        (optional) absolute path to the kubeconfig file (default "/Users/kyle/.kube/config")
  -log-cmd
        log the output of the pre/post commands (default true)
  -overwrite
        overwrite the output file if it exists (default true)
  -post-cmd string
        command to run after template generation in complete
  -pre-cmd string
        command to run before template generation
  -quiet
        when set to true, nothing is logged
  -type value
        types of resources to pull [pods, services, endpoints] - May be specified multiple times. If not specified, all types will be returned
  -version
        display version information
  -wait string
        <minimum>[:<maximum>] - the minimum and optional maximum time to wait after an event fires.E.g.: 500ms:5s
  -watch
        watch for new events

Arguments:
  template: path or URL of the template file to render, or - to read from STDIN
  output: (Optional) path to write the rendered content. If not specified,
          rendered content is printed to STDOUT. By default, this file will
          be overwritten if it exists. Use -overwrite=false to return an
          error instead

Authentication / Connecting to the Kubernetes API

By default, kube-gen will look for a kubeconfig file at $HOME/.kube/config. A different kubeconfig file may be specified by using the -kubeconfig flag. Alternatively, kube-gen provides a -host flag that, if set, will supersede the -kubeconfig. The -host flag is best paired with kubectl proxy, which listens on 127.0.0.1:8001 by default. The -host flag may also be set to the value of kube-apiserver's --insecure-bind-address / --insecure-port.

Watching for changes

The -watch flag configures kube-gen to watch the API for changes to Services, Pods, and Endpoints (support for other types is forthcoming). This mode is useul when combined with the -pre-cmd, -post-cmd, and -wait parameters.

Template Language

kube-gen supports templates written in Go`s text/template language. It supports all of the built in functions, as well as numerous custom functions described below. Many of the custom functions (and the documentation for those functions) have been borrowed from docker-gen. Those functions, along with the accompanying License and Copyright are located in the dockergen_template_functions.go source file.

kube-gen's People

Contributors

dependabot[bot] avatar kylemcc avatar npenkov avatar panaji avatar philmadden83 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kube-gen's Issues

[question] Can `kube-gen` be restricted to a namespace?

Currently it seems that kube-gen requires a ClusterRole in order to work. It appears that there aren't any controls for limiting the scope of kube-gen to a specific namespace.

For our use case, we want to run https://github.com/kylemcc/kube-nginx-proxy in certain namespaces, and only generate nginx configurations for services / pods within the same namespace. In this scenario, we would also want to only use namespace scoped roles, not cluster scoped roles.

Is this currently possible? Maybe using environment variables or undocumented flags?

[feature] Add Sprig to the template processor

There may be underlying reasons why this wasn't included at some point, but seeing as the Sprig library is pretty well maintained, it would make sense to include it with the kube-gen template processor.

https://github.com/Masterminds/sprig

I think it only requires adding the following here

import (
:

import (
  "github.com/Masterminds/sprig/v3"
  "html/template"
)

and merging these functions here

var Funcs = template.FuncMap{
:

tpl := template.Must(
  template.New("base").Funcs(sprig.FuncMap()).ParseGlob("*.html")
)

Working Example

Hi ,

Thanks for the awesome job ! This is very useful.

Can you please provide some working example of templates ? How to uses functions and stuff , how to get annotation from ingress for example.

That would be very useful !

Thanks

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.