Giter Site home page Giter Site logo

kubestar's Introduction

kubestar

GoDev

Build kuberenetes config with Starklark (a dialect of python) and protobuffers. Generate config with python functions, strongly typed to protobuffer objects. Build out modules for different applications and import them with a function syntax for easy configuration.

Here's some example syntax to declare an apps/v1 Deployment object:

apps_v1.Deployment(
  metadata={
    "name": "nginx-deployment",
    "labels": {
      "app": "nginx",
    },
  },
  spec=apps_v1.DeploymentSpec(
    replicas=3,
    selector=struct(matchLabels={
      "app": "nginx",
    }),
    template=core_v1.PodTemplateSpec(
      metadata=apis_meta_v1.ObjectMeta(
        labels={
          "app": "nginx",
        }),
      spec=core_v1.PodSpec(containers=[
        nginx_container(),
      ]),
    ),
  ),
)

Please see examples for more.

How does it work?

  1. kubestar loads all starlark files in a given glob pattern.
  2. Each main() function is ran expecting an array of kubernetes protobuf objects.
  3. Finally, the protobuf is than encoded to yaml and written to the named file with the '.star' -> '.yaml'.

Alternative to:

Install

go install github.com/emcfarlane/kubestar@latest

Examples

Have a look at the examples and try with:

kubestar examples/nginx_deployment.star -v 
examples
├── nginx_deployment.star
└── nginx_deployment.yaml (generated)

Features

Protobuf syntax

Protobuf wrapping is provided by github.com/emcfarlane/starlarkproto. See the repo for more details. Similar types will be cast to protobuffer types.

Load common modules

Load common modules with relative path syntax, or absolute based from the cmd init.

load("./my_application.star", "object")

Protobuffer file descriptors

Protobuffer file descriptors can be loaded using proto.file(path). See protos.star for all global namespaced file descriptors.

apps_v1 = proto.file("k8s.io/api/apps/v1/generated.proto")

Drop the k8s.io/ prefix and /generated.proto suffix and finally replace / with _.

Global config files

Important config can be declared in a global file with the flag -global filename.star. This will exec the file and expose as global config to all source files.

Strongly typed

On generation any errors will generate a stacktrace. For example, adding a bad field, okay=True field would yield:

$ kubestar examples/*.star
Traceback (most recent call last):
  examples/nginx_deployment.star:44:19: in main
  examples/nginx_deployment.star:35:36: in deployment
  examples/nginx_deployment.star:6:29: in nginx_container
Error in Container: Container has no .okay attribute

Contrib

K8s protobuffers are currently gogo generated: kubernetes/kubernetes#96564 We will need to clone api and apimachinery repos to a k8s.io/ directory like:

k8s.io
├── api
└── apimachinery

Then generate the protos.pb file:

export GOOGLEAPIS_DIR=~/src/github.com/googleapis/api-common-protos
export K8S_DIR=~/src/github.com
./gen.sh

kubestar's People

Contributors

emcfarlane avatar

Stargazers

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

Watchers

 avatar  avatar

kubestar's Issues

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.