Skip to content

Commit 36b99b2

Browse files
author
Fletcher Haynes
committed
Initial commit
0 parents  commit 36b99b2

File tree

8 files changed

+182
-0
lines changed

8 files changed

+182
-0
lines changed

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
*tags*

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Exkube
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8+
by adding `exkube` to your list of dependencies in `mix.exs`:
9+
10+
```elixir
11+
def deps do
12+
[{:exkube, "~> 0.1.0"}]
13+
end
14+
```
15+
16+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
17+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
18+
be found at [https://hexdocs.pm/exkube](https://hexdocs.pm/exkube).
19+

config/config.exs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
use Mix.Config
4+
5+
config :exkube, insecure_ca: :secure
6+
# This configuration is loaded before any dependency and is restricted
7+
# to this project. If another project depends on this project, this
8+
# file won't be loaded nor affect the parent project. For this reason,
9+
# if you want to provide default values for your application for
10+
# 3rd-party users, it should be done in your "mix.exs" file.
11+
12+
# You can configure for your application as:
13+
#
14+
# config :exkube, key: :value
15+
#
16+
# And access this configuration in your application as:
17+
#
18+
# Application.get_env(:exkube, :key)
19+
#
20+
# Or configure a 3rd-party app:
21+
#
22+
# config :logger, level: :info
23+
#
24+
25+
# It is also possible to import configuration files, relative to this
26+
# directory. For example, you can emulate configuration per environment
27+
# by uncommenting the line below and defining dev.exs, test.exs and such.
28+
# Configuration from the imported file will override the ones defined
29+
# here (which is why it is important to import them last).
30+
#
31+
# import_config "#{Mix.env}.exs"

lib/exkube.ex

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule Exkube.Base do
2+
@moduledoc """
3+
Module for interacting with the Kubernetes API.
4+
"""
5+
6+
alias Poison, as: JSON
7+
use HTTPoison.Base
8+
require Logger
9+
10+
@doc """
11+
Checks the health endpoint of Kubernetes cluster
12+
13+
Returns `{:ok, "ok"}` if healthy or `{:error, %{status_code, body}}` if not
14+
"""
15+
def status(api_url) do
16+
url = api_url <> "/healthz"
17+
result = HTTPoison.request!(:get, url, "", [], hackney: [Application.get_env(:exkube, :insecure_ca)])
18+
%HTTPoison.Response{status_code: status_code, body: body} = result
19+
20+
case status_code do
21+
200 ->
22+
{:ok, body}
23+
_ ->
24+
{:error, %{status_code: status_code, body: body}}
25+
end
26+
27+
end
28+
29+
end

mix.exs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
defmodule Exkube.Mixfile do
2+
use Mix.Project
3+
4+
def project do
5+
[app: :exkube,
6+
version: "0.1.0",
7+
description: description(),
8+
package: package(),
9+
links: links(),
10+
elixir: "~> 1.4",
11+
build_embedded: Mix.env == :prod,
12+
start_permanent: Mix.env == :prod,
13+
deps: deps()]
14+
end
15+
16+
# Configuration for the OTP application
17+
#
18+
# Type "mix help compile.app" for more information
19+
def application do
20+
# Specify extra applications you'll use from Erlang/Elixir
21+
[
22+
extra_applications: [:logger],
23+
applications: [:httpoison, :poison]
24+
]
25+
end
26+
27+
# Dependencies can be Hex packages:
28+
#
29+
# {:my_dep, "~> 0.3.0"}
30+
#
31+
# Or git/path repositories:
32+
#
33+
# {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
34+
#
35+
# Type "mix help deps" for more examples and options
36+
defp deps do
37+
[
38+
{:httpoison, "~> 0.11.2"},
39+
{:poison, "~> 3.1.0"}
40+
]
41+
end
42+
43+
defp description do
44+
"""
45+
A module for interacting with Kubernetes clusters
46+
"""
47+
end
48+
49+
defp package do
50+
# These are the default files included in the package
51+
[
52+
name: :exkube,
53+
maintainers: ["Fletcher Haynes <[email protected]>"],
54+
licenses: ["Apache 2.0"]
55+
]
56+
end
57+
58+
defp links do
59+
%{}
60+
end
61+
62+
end

mix.lock

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%{"certifi": {:hex, :certifi, "1.2.1", "c3904f192bd5284e5b13f20db3ceac9626e14eeacfbb492e19583cf0e37b22be", [:rebar3], [], "hexpm"},
2+
"hackney": {:hex, :hackney, "1.8.6", "21a725db3569b3fb11a6af17d5c5f654052ce9624219f1317e8639183de4a423", [:rebar3], [{:certifi, "1.2.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.0.2", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
3+
"httpoison": {:hex, :httpoison, "0.11.2", "9e59f17a473ef6948f63c51db07320477bad8ba88cf1df60a3eee01150306665", [:mix], [{:hackney, "~> 1.8.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
4+
"idna": {:hex, :idna, "5.0.2", "ac203208ada855d95dc591a764b6e87259cb0e2a364218f215ad662daa8cd6b4", [:rebar3], [{:unicode_util_compat, "0.2.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
5+
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
6+
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
7+
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
8+
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
9+
"unicode_util_compat": {:hex, :unicode_util_compat, "0.2.0", "dbbccf6781821b1c0701845eaf966c9b6d83d7c3bfc65ca2b78b88b8678bfa35", [:rebar3], [], "hexpm"}}

test/exkube_test.exs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule ExkubeTest do
2+
use ExUnit.Case
3+
4+
5+
test "get status" do
6+
result = Exkube.Base.status("https://api.kubernetes.ausw1a.int.uops.internal.unity3d.com")
7+
assert result == {:ok, "ok"}
8+
end
9+
end

test/test_helper.exs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ExUnit.start()

0 commit comments

Comments
 (0)