Skip to content

Commit bb25591

Browse files
committed
Add opts to K8s.Conn.from_file/N and K8s.Conn.from_service_account/N
1 parent b5cb571 commit bb25591

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Added
1515

1616
- Added further PATCH mechanisms - [#229](https://github.com/coryodaniel/k8s/pull/229)
17+
- Add `opts` to `K8s.Conn.from_file/N` and `K8s.Conn.from_service_account/N` in order to be able to pass `:insecure_skip_tls_verify` option directly. - [#230](https://github.com/coryodaniel/k8s/issues/230), [#203](https://github.com/coryodaniel/k8s/issues/203)
1718

1819
<!--------------------- Don't add new entries after this line --------------------->
1920

lib/k8s/conn.ex

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ defmodule K8s.Conn do
7676
{:ok, user} <- find_configuration(config["users"], user_name, "user"),
7777
cluster_name <- opts[:cluster] || context["cluster"],
7878
{:ok, cluster} <- find_configuration(config["clusters"], cluster_name, "cluster"),
79+
insecure_skip_tls_verify <-
80+
Keyword.get(opts, :insecure_skip_tls_verify, cluster["insecure-skip-tls-verify"]),
7981
{:ok, cert} <- PKI.cert_from_map(cluster, base_path) do
8082
conn = %Conn{
8183
cluster_name: cluster_name,
8284
user_name: user_name,
8385
url: cluster["server"],
8486
ca_cert: cert,
8587
auth: get_auth(user, base_path),
86-
insecure_skip_tls_verify: cluster["insecure-skip-tls-verify"]
88+
insecure_skip_tls_verify: insecure_skip_tls_verify
8789
}
8890

8991
{:ok, maybe_update_defaults(conn, config)}
@@ -99,13 +101,25 @@ defmodule K8s.Conn do
99101
100102
[kubernetes.io :: Accessing the API from a Pod](https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#accessing-the-api-from-a-pod)
101103
"""
102-
@spec from_service_account :: {:ok, t()} | {:error, :enoent | K8s.Conn.Error.t()}
104+
@spec from_service_account() ::
105+
{:ok, t()} | {:error, :enoent | K8s.Conn.Error.t()}
103106
def from_service_account do
104-
from_service_account(@default_service_account_path)
107+
from_service_account(@default_service_account_path, [])
105108
end
106109

107-
@spec from_service_account(String.t()) :: {:ok, t()} | {:error, :enoent | K8s.Conn.Error.t()}
108-
def from_service_account(service_account_path) do
110+
@spec from_service_account(opts_or_sa_path :: String.t() | Keyword.t()) ::
111+
{:ok, t()} | {:error, :enoent | K8s.Conn.Error.t()}
112+
def from_service_account(opts) when is_list(opts) do
113+
from_service_account(@default_service_account_path, opts)
114+
end
115+
116+
def from_service_account(service_account_path) when is_binary(service_account_path) do
117+
from_service_account(service_account_path, [])
118+
end
119+
120+
@spec from_service_account(service_account_path :: String.t(), opts :: Keyword.t()) ::
121+
{:ok, t()} | {:error, :enoent | K8s.Conn.Error.t()}
122+
def from_service_account(service_account_path, opts \\ []) do
109123
cert_path = Path.join(service_account_path, "ca.crt")
110124
token_path = Path.join(service_account_path, "token")
111125

test/support/integration_helper.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ defmodule K8s.Test.IntegrationHelper do
66
{:ok, conn} =
77
"TEST_KUBECONFIG"
88
|> System.get_env("./integration.k3d.yaml")
9-
|> K8s.Conn.from_file()
9+
|> K8s.Conn.from_file(insecure_skip_tls_verify: true)
1010

1111
struct!(conn,
12-
insecure_skip_tls_verify: true,
1312
discovery_driver: K8s.Discovery.Driver.HTTP,
1413
discovery_opts: [],
1514
http_provider: K8s.Client.MintHTTPProvider

0 commit comments

Comments
 (0)