client-go-multidialer

module
v0.0.0-...-bd27a7b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2021 License: Apache-2.0

README

client-go-multidialer

client-go says: "just give me a working TCP connection, I will do the REST"

This provides a new constructor to client-go with a custom Dialer that offers high availability by providing a working connection, if possible, to any of the apiservers in the cluster.

It needs to be initialized with one working apiserver IP that will be the seed, once it connects it will obtain the rest of apiserver endpoints.

Usage

The instantiation is similar to the current client-go constructor, with the addition of one context parameter:

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	clientset, err := client.NewForConfig(ctx, config)
	if err != nil {
		panic(err.Error())
	}

How it works

It provides a custom dialer to the client-go client, it also wraps the actual dialer in case client-go was already using one, like in the Kubelet case.

The custom dialer implement the following logic:

  1. Connects to the provided endpoint
  2. Spawn a go routine that queries the apiserver to the get current available endpoints, these are available under the special endpoint object "kubernetes" on the "default" namespace
  3. When the http transport in client-go ask for a connection to the dialer:
    • tries to connect to the last working apiserver endpoint, if it fails
    • tries to connect to the other endpoints, if it succeeds returns the connection and store the endpoint as the one to be used next time
    • if none of the endpoints work, it falls back to the initial configured endpoint

The fact that it gathers the apiserver endpoints periodically allows to change the apiserver IPs, shrink or grow the cluster.

Implementation

The implementation is composed of:

Examples

There are two examples on how to use it to create a client-go:

Directories

Path Synopsis
This is a simple mechanism to provide HA without relying on external components.
This is a simple mechanism to provide HA without relying on external components.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL