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).

First Post! Switch mode

mruoss

mruoss OP

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.
— All posts loaded —

Where Next?

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 14960 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
quatermain
Hello, I’m sharing my plugin here in forum after some time so it has time to mature and proof yourself. I use Claude Code daily on a pr...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

We're in Beta

About us Mission Statement