Git Product home page Git Product logo

kuberl's Introduction

Erlang Kubernetes client

Erlang client for Kubernetes 1.16 generated through Swagger.

Watch Behaviour

The behaviour kuberl_watch starts a process to stream the results of a watch requests and calls the callback handle_event with the notification type (added, modified, deleted) and the resource object.

Using the API

Configuration

The API server endpoint and key can be configured in environment configuration variables:

[{kuberl, [{api_key, <<"... bearer token ...">>},
           {host, "https://x.x.x.x"}]}].

This will set a default configuration used if none is passed to API requests.

A new configuration can be created with functions in kuberl:

Cfg = kuberl:cfg_with_bearer_token(kuberl:cfg_with_host("https://x.x.x.x"), <<"... bearer token ...">>),
kuberl_core_api:get_api_versions(ctx:background(), #{cfg => Cfg}).

Optionally the environment config can be overridden at runtime:

kuberl:set_default_cfg(Cfg).

Update Generated Code

Without Nix

With swagger-codegen built under ../swagger-codegen the script in the bin directory can be used to update the generated Erlang modules:

bin/update-generated-code.sh

This script will generate the code to a temporary directory under /tmp and then copy only the modules to gen/.

With Nix

Install Nix, direnv, and lorri.

# Run the lorri daemon
lorri daemon

# or watch this directory (once)
lorri watch # --once

# load the environment
direnv allow

# generate the code
kuberl_gen

kuberl_gen will generate the code to a temporary directory under /tmp and then copy only the modules to gen/.

kuberl's People

Contributors

tsloughter avatar vitorenesduarte avatar yurrriq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kuberl's Issues

Authentication header missing from request

I've configured sys.config as per the README, but for some reason, my requests have no Authentication header, so I keep getting 401'd. Please advise.

28> kuberl_core_api:get_api_versions(ctx:background(), #{cfg => kuberl:new_cfg()}).
(<0.256.0>) call hackney:request(get,<<"https://api.mycluster.fake/api">>,[{<<"Content-Type">>,<<"application/json">>}],<<"[]">>,[{ssl_options,[{server_name_indication,disable}]}])
(<0.256.0>) call hackney:request(get,{hackney_url,hackney_ssl,https,<<"api.mycluster.fake">>,<<"/api">>,
             <<"/api">>,<<>>,<<>>,"api.mycluster.fake",443,<<>>,<<>>},[{<<"Content-Type">>,<<"application/json">>}],<<"[]">>,[{ssl_options,[{server_name_indication,disable}]}])
{error,#{apiVersion => <<"v1">>,code => 401,kind => <<"Status">>,
         message => <<"Unauthorized">>,metadata => #{},
         reason => <<"Unauthorized">>,status => <<"Failure">>},
       #{headers =>
             [{<<"Content-Type">>,<<"application/json">>},
              {<<"Www-Authenticate">>,
               <<"Basic realm=\"kubernetes-master\"">>},
              {<<"Date">>,<<"Tue, 29 May 2018 21:28:52 GMT">>},
              {<<"Content-Length">>,<<"129">>}],
         status => 401}}

Figure out resourceVersion

I don't think it is currently using resourceVersion correctly, at least in cases like the example which lists all pods for all namespaces.

Without a resourceVersion it will fetch all pods again on every reconnect after a timeout. But as far as I can tell resourceVersion is about the individual resource, like a single pod, and isn't clear if it can be used as the example currently is where the resourceVersion of last pod decoded is used as the version for the next request.

401: Unauthorized error

Hi,

Thanks for a wonderful package kuberl. I was thinking of writing this kind of project along this lines. Maybe I can help in this project as time goes by.

For now, I am trying to execute the example code highlighted in README.md. The following might not be a bug, probably the way I am using it.

I started minikube from my Mac OSX. And then I compiled my own app with kuberl as a dependency from a Docker container running OTP 20. And then copied the .kube from my home directory to the container's home directory, so that container can see the same kube-config.

From container I can do:

root@piccolo:~# kubectl get nodes
NAME       STATUS    ROLES     AGE       VERSION
minikube   Ready     <none>    46d       v1.9.0

I got the bearer token as follows:

TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')
Then I started my app and from Erlang shell, I set up Cfg variable and then tried to get api versions as follows:

(piccolo@piccolo)2> Cfg.
#{api_key_prefix => #{<<"authorization">> => <<"Bearer">>},
  auth =>
      #{'BearerToken' =>
            <<"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9"...>>},
  hackney_opts =>
      [{ssl_options,[{server_name_indication,disable}]}],
  host => "https://192.168.64.2:8443"}
(piccolo@piccolo)3> kuberl_core_api:get_api_versions(ctx:background(), #{cfg => Cfg}).
{error,#{apiVersion => <<"v1">>,code => 401,kind => <<"Status">>,
         message => <<"Unauthorized">>,metadata => #{},
         reason => <<"Unauthorized">>,status => <<"Failure">>},
       #{headers =>
             [{<<"Content-Type">>,<<"application/json">>},
              {<<"Date">>,<<"Tue, 13 Mar 2018 23:21:00 GMT">>},
              {<<"Content-Length">>,<<"129">>}],
         status => 401}}

May I know what is it I am doing wrong? Or do you think the way I am getting Bearer token is right?

How did you test this, like how to fetch bearer token, or test environment?

Thanks
-Vasu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.