-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
# Kubegen | ||
|
||
**TODO: Add description** | ||
Generate resource scoped Kubernetes clients with `Kubegen`. | ||
|
||
[![Module Version](https://img.shields.io/hexpm/v/kubegen.svg)](https://hex.pm/packages/kubegen) | ||
[![Last Updated](https://img.shields.io/github/last-commit/mruoss/kubegen.svg)](https://github.com/mruoss/kubegen/commits/main) | ||
|
||
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/kubegen/) | ||
[![Total Download](https://img.shields.io/hexpm/dt/kubegen.svg)](https://hex.pm/packages/kubegen) | ||
[![License](https://img.shields.io/hexpm/l/kubegen.svg)](https://github.com/mruoss/kubegen/blob/main/LICENSE) | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
by adding `kubegen` to your list of dependencies in `mix.exs`: | ||
`kubegen` is a code generator. Add the package as dev dependency: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
{:kubegen, "~> 0.1.0"} | ||
{:kubegen, "~> 0.1.0", only: :dev, runtime: false} | ||
] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at <https://hexdocs.pm/kubegen>. | ||
The docs can be found at <https://hexdocs.pm/kubegen>. | ||
|
||
## Usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule Mix.Tasks.Kubegen.Search do | ||
@moduledoc ~S""" | ||
Search Group-Version-Kind (GVK) for Core Resources. | ||
Kubegen requires you to pass GVK as keys in `config.exs`. This mix tasks | ||
lets you search for GVK for a specific resource kind | ||
""" | ||
@shortdoc "Search Group-Version-Kind for Core Resources." | ||
|
||
use Mix.Task | ||
|
||
@impl Mix.Task | ||
def run([input]) do | ||
discovery = elem(Code.eval_file("build/discovery.ex"), 0) | ||
gvks = Map.keys(discovery) | ||
|
||
if input in gvks do | ||
IO.puts(~s'"#{input} is a valid GVK."') | ||
exit({:shutdown, 0}) | ||
end | ||
|
||
list = | ||
gvks | ||
|> Enum.map(fn gvk -> {gvk, String.split(gvk, "/") |> Enum.reverse() |> List.first()} end) | ||
|> Enum.map(fn {gvk, kind} -> {gvk, kind, String.jaro_distance(input, kind)} end) | ||
|> Enum.filter(fn {_, _, score} -> score > 0.7 end) | ||
|> Enum.sort_by(&elem(&1, 2), :desc) | ||
|> Enum.map(&[IO.ANSI.green(), elem(&1, 0), IO.ANSI.reset(), "\n"]) | ||
|
||
case list do | ||
[] -> | ||
Owl.IO.puts([ | ||
IO.ANSI.red(), | ||
"No resource matches your search term." | ||
]) | ||
|
||
list -> | ||
Owl.IO.puts([ | ||
"Did you mean one of these?\n\n", | ||
list | ||
]) | ||
end | ||
end | ||
end |