mruoss
Hey there
The title basically says it all. Here’s what I would like to do in kino_k8s. I’d like to render maps that are (look like) Kubernetes resources as YAML markdown. And maybe later render maps that are lists of Kubernetes resources as table. Unfortunately, these are regular maps, not structs. I fear conflicts if multiple libs do the following. Or is this safe to do?
defimpl Kino.Render, for: Map do
def to_livebook(resource)
when is_map_key(resource, "apiVersion") and
is_map_key(resource, "kind") and
not is_map_key(resource, "items") do
"""
```yaml
#{Ymlr.document!(resource)}
```
"""
|> Kino.Markdown.new()
|> Kino.Render.to_livebook()
end
def to_livebook(resource), do: Kino.Output.inspect(resource)
end
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
nulltree
Reminds me of Rust.
There, a typical solution would be to wrap the foreign type in an own. Translated to Elixir, maybe you could parse your map to a struct and then implement
Kino.Renderfor that?Am aware I’m not answering your actual question, though.
mruoss
I think I see what you mean. But that is not really a possibility. It would have to be done in the
k8slibrary (because the point of implementingKino.Renderinkino_k8sis to render whatk8sreturns as YAML. And currently,k8sreturns resources as maps.Converting maps into structs in
k8swould be super nasty (tons of “unsafe” calls toString.to_atom()etc.) because a Kubernetes resource could be of arbitrary shape containing arbitrary data (think of CRDs).nulltree
I was thinking along the lines of having a step that stores (‘parsing’ was imprecise) the map in a struct shaped like this and then
defimpling onMyStruct.But that may not fit your case ofc.
mruoss
Oh okay yes, that is more feasible. Gotta think about that…
mruoss
Yes, I could add something like this as the last instruction of the generated code:
struct!(MyStruct, k8s_result: resource). But in the smart cell, I can also just returnKino.Markdowndirectly (which is what I’m doing now).But if somebody plays with the
k8slibrary, they would still get a “normal” map fromk8s…nulltree
That’s how I understood the requirements so far, and yes, this should fit the bill.
Ofc, the
k8slibrary could also return this kind of ‘type-wrapper’ struct, but I am not yet versed enough in Elixir to understand whether that would be considered idiomatic.mruoss
If you implement
Kino.Render, the implementation is used to render the result of any cell. Not only smart cells.True. Would be hell of a change of its API, though
nulltree
Yeah, tbh I never worked with
Kinoor smart cells so far and am a bit out of my depth regarding best practices here, just wanted to introduce the idea of a ‘newtype’ / ‘type wrapper’ as I could see multiple implementations conflicting. So far wrapping the map in the struct and then render the structs implementation seems reasonable for my limited understanding, but am sure others with more experience can chime in.True.
mruoss
In any case thanks your input.
jonatanklosko
Hey, I don’t think we should be implementing
Kino.Renderfor any built-in data types outside ofkino, because doing that would lead to conflicts sooner or later. Unlessk8sreturns a struct, I think the user should call|> KinoK8s.resource()or similar to convert map to kino markdown (and the smart cell can do that for them).