mruoss

mruoss

Kubegen - Generate resource based Kubernetes clients

Kubegen generates Kubernetes clients in the form of resource based client modules directly into your project.

I have been co-maintaining the k8s library for some time now and while it is very dynamic and mighty, I always found it a bit big and clumsy for simple use cases. With Kubegen I went down a different road. Kubegen generates per resource client modules into your project. They are super straight-forward to use:

# list ConfigMaps in the default namespace:
{:ok, resp} = MyApp.K8sClient.Core.V1.ConfigMap.list("default")

# get the ConfigMap with name "my-config" in namespace "default":
{:ok, resp} = MyApp.K8sClient.Core.V1.ConfigMap.get("default", "my-config")

The generated modules use Kubereq to load the Kubernetes configuration and prepare the Req.Request for operations on the resource. Finally, it’s plain Req to make the HTTP requests and most function return {:ok, Req.Response.t()} in the happy case.

Generate your first Client Module

Generating your first client is quite straight-foward. Have a look at the project’s README.md on detailed instructions. But in a nutshell, the library offers a Mix task (mix kubegen) which reads some entries from your application configuration and generates the configured modules.

Generating clients for ConfigMap, Deployment, ClusterRole and a CRD looks like this:

Where’s the Kubernetes Configuration?

As part of the configuration you need to tell Kubegen how the Kubeconfig is loaded. Kubereq comes with a default loading pipeline which does the job in most basic setups (i.e. load the current context from $HOME/.kube/config or when running on a Kuberenetes cluster).

Most Liked

mruoss

mruoss

kubereq v0.4.0

I have released kubereq v0.4.0 today. See the changelog below. BTW: kino_k8s v2.0.0 was also released today. It uses kubereq now and all smart cells were consolidated into a single cell.

:warning: Breaking Changes :warning:

  • Kubereq.watch/3 and Kubereq.watch_single/4 now also return t:Kubereq.response/0.
    The stream which was returned directly before is now accessible through the :body
    key of the returned t:Req.Response.t/0 struct. The :stream_to option was removed.
    Kubereq.Watcher was added for implementing long running watch event handlers.

Changes

  • Kubereq.wait_until/5 gets by without Task.async/1.
  • Kubereq.create/3, Kubereq.update/3 and Kubereq.apply/5: Extract api_verison and kind from passed resource.

Added

  • Kubereq.Watcher - A behaviour module for implementing a Kubernetes watch event handler.
  • Streaming for paginated list operation via the :into option of Kubereq.list/3
    #46
  • Kubereq.can_i/3 - Checks whether the authenticated user is authorized to perform a specific action.
  • Error raising variants for all functions in Kubereq except Kubereq.wait_until/5.

Where Next?

Popular in Announcing Top

martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New
Crowdhailer
The latest release of Ace (0.10.0) includes serving content over HTTP/2. I have started writing a webserver to teach my self more about...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 10167 134
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

We're in Beta

About us Mission Statement