discovery

package
v0.3.22-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package discovery contains functionality to discover the type of etcd used in back up and restore operations as well as what Kubernetes distro is used.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountKeysFor

func CountKeysFor(endpoint string, startkey, endkey string) (numkeys, totalsize int, err error)

CountKeysFor iterates over well-known keys of a given Kubernetes distro and returns the number of keys and their values total size, in the respective key range/subtree.

Example

Shows how to glean stats from etcd by walking well-known keys of a given Kubernetes distro. It assumes that the etcd process is servering on 127.0.0.1:2379 and the vanilla Kubernetes distro is using it.

// define the URL etcd is available at:
etcdurl := "http://127.0.0.1:2379"

// carry out the stats walk and handle errors as they occur:
numkeys, totalsize, err := CountKeysFor(etcdurl, types.LegacyKubernetesPrefix, types.LegacyKubernetesPrefixLast)
if err != nil {
	log.Fatal(err)
	return
}
fmt.Printf("Found %d keys and overall payload size of %d bytes.\n", numkeys, totalsize)
Output:

Found 1024 keys and overall payload size of 350876 bytes.

func ProbeEtcd

func ProbeEtcd(endpoint string) (version, apiversion string, secure bool, err error)

ProbeEtcd probes an endpoint at path /version to figure which version of etcd it is and in which mode (secure or insecure) it is used.

Example

Shows how to probe etcd to determine which version is running and in which mode (secure or insecure) it is used. It assumes that the etcd process is servering on 127.0.0.1:2379.

// define the URL etcd is available at:
etcdurl := "http://127.0.0.1:2379"

// carry out the probe and handle errors as they occur:
version, apiversion, secure, err := ProbeEtcd(etcdurl)
if err != nil {
	log.Fatal(err)
	return
}
fmt.Printf("Discovered etcd in version %s, using API %s, and running in secure mode: %t\n", version, apiversion, secure)
Output:

Discovered etcd in version 3.1.0, running in secure mode: false

func ProbeKubernetesDistro

func ProbeKubernetesDistro(endpoint string) (distro types.KubernetesDistro, err error)

ProbeKubernetesDistro probes an etcd cluster for which Kubernetes distribution is present by scanning the available keys.

Example

Shows how to probe etcd to determine which Kubernetes distribution is present (if at all) by scanning the available keys. It assumes that the etcd process is servering on 127.0.0.1:2379 and the OpenShift Kubernetes distro is using it.

// define the URL etcd is available at:
etcdurl := "http://127.0.0.1:2379"

// a textual description of the Kubernetes distro
var distro string

// carry out the probe and handle errors as they occur:
distrotype, err := ProbeKubernetesDistro(etcdurl)
if err != nil {
	log.Fatal(err)
	return
}
switch distrotype {
case types.Vanilla:
	distro = "Vanilla Kubernetes"
case types.OpenShift:
	distro = "OpenShift"
default:
	distro = "no Kubernetes distro found"
}
fmt.Printf("Discovered Kubernetes distro: %s\n", distro)
Output:

Discovered Kubernetes distro: OpenShift

func Visit2

func Visit2(kapi client.KeysAPI, path, target string, reapfn types.Reap, reapfnName string) error

Visit2 recursively visits an etcd2 server from the path given and applies the reap function on leaf nodes, that is, keys that don't have sub-keys, otherwise descents the tree.

func Visit3

func Visit3(c3 *clientv3.Client, target, path, endkey string, reapfn types.Reap, reapfnName string) error

Visit3 visits the given path of an etcd3 server and applies the reap function on the keys in the respective range, depending on the Kubernetes distro.

Types

This section is empty.

Jump to

Keyboard shortcuts

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