Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor discover to use K8s.Cluster.Discovery
- Loading branch information
1 parent
b90af2c
commit 595e100
Showing
14 changed files
with
38 additions
and
282 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,36 @@ | ||
defmodule K8s.Cluster.Discovery.FileDriver do | ||
@moduledoc """ | ||
`K8s.Cluster.Discovery.Driver` implementation that returns kubernetes API features from file | ||
""" | ||
@behaviour K8s.Cluster.Discovery.Driver | ||
|
||
@api_versions_path "test/support/discovery_api_versions.json" | ||
@resource_definitions_path "test/support/discovery_resource_definitions.json" | ||
|
||
@impl true | ||
def api_versions(_cluster, _opts \\ []), do: parse_json(@api_versions_path) | ||
def api_versions(_cluster, opts \\ []) do | ||
file = opts[:path] || path_for(:api_versions_path) | ||
parse_json(file) | ||
end | ||
|
||
@impl true | ||
def resource_definitions(_cluster, _opts \\ []), do: parse_json(@resource_definitions_path) | ||
def resource_definitions(_cluster, opts \\ []) do | ||
file = opts[:path] || path_for(:resource_definitions_path) | ||
parse_json(file) | ||
end | ||
|
||
@spec parse_json(binary()) :: {:ok, list() | map()} | {:error, atom()} | ||
defp parse_json(nil), do: {:error, :file_not_found} | ||
|
||
defp parse_json(file) do | ||
with {:ok, json} <- File.read(file), | ||
{:ok, data} <- Jason.decode(json) do | ||
{:ok, data} | ||
end | ||
end | ||
|
||
@spec path_for(atom) :: nil | binary() | ||
defp path_for(file) do | ||
opts = Application.get_env(:k8s, :discovery_opts, %{}) | ||
opts[file] | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.