Coder Social home page Coder Social logo

bazel rules about k8s HOT 7 CLOSED

jsonnet-libs avatar jsonnet-libs commented on May 16, 2024
bazel rules

from k8s.

Comments (7)

xvzf avatar xvzf commented on May 16, 2024

Since there is no build system yet - just do a PR and we can go from that?

from k8s.

Duologic avatar Duologic commented on May 16, 2024

I was planning to automate it through Github actions for now. I'm not familiar with Bazel.

from k8s.

Duologic avatar Duologic commented on May 16, 2024

The github actions are now in place.

The most common way to pull in jsonnet libraries is currently through jsonnet-bundler, this also does leverages the http-archive afaik. Maybe a jsonnet_bundler bazel rule could be a thing? Or maybe the jsonnet_library could build-in the http_archive rule?

My main question is: why put the burden of integrating into someone else's CI system on the source files?

from k8s.

0x1DA117 avatar 0x1DA117 commented on May 16, 2024

There is no need to put Bazel rules into the repository.

@Geethree you can put the following into your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")

new_git_repository(
    name = "com_github_jsonnet-libs_k8s-libsonnet",
    remote = "https://github.com/jsonnet-libs/k8s-libsonnet",
    commit = "f47562c4e3bfaf46a5a5bc6a9e1e76a4fc76c18e",
    build_file_content = """
load("@io_bazel_rules_jsonnet//jsonnet:jsonnet.bzl", "jsonnet_library")

jsonnet_library(
    name = "1.20",
    srcs = glob(["1.20/**/*.libsonnet"]),
    visibility = ["//visibility:public"],
    imports = ["."],
)
""",

You can now use it in your BUILD files like this:

jsonnet_to_json(
    name = "statefulset",
    src = "statefulset.jsonnet",
    outs = ["statefulset.json"],
    deps = [
        "@com_github_jsonnet-libs_k8s-libsonnet//:1.20",
    ],
)

My example Jsonnet file looks like this:

local k = import "1.20/main.libsonnet";

{
  cockroachdb: {
    statefulset: k.apps.v1.statefulSet.new(
      name="cockroachdb",
      replicas=1,
      containers=[ 
        k.core.v1.container.new("cockroachdb", "cockroachdb/cockroach")
      ]
    )
  }
}

Personally I do not like that I have to use the path 1.20 when importing, but I couldn't find a better way yet.

from k8s.

0x1DA117 avatar 0x1DA117 commented on May 16, 2024

Update: to get rid of the 1.20 in the import path, you can write a small wrapper and import that instead.

Wrapper content:

(import '1.20/main.libsonnet')

This also offers the benefit that you can add additional functionality like Grafana did (https://github.com/grafana/jsonnet-libs/tree/master/ksonnet-util).

The import line in other packages will then look like this:

local k = import "path/to/wrapper.libsonnet";

from k8s.

Duologic avatar Duologic commented on May 16, 2024

It is a common pattern to have this wrapper in lib/k.libsonnet, for example this works well with ksonnet-util on which quite a bit of libraries depend upon.

from k8s.

Duologic avatar Duologic commented on May 16, 2024

Judging on above discussion, I believe the original question was answered with a suggested solution by @0xIDANT. I think we can close it based on that.

from k8s.

Related Issues (20)

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.