reshifter: github.com/mhausenblas/reshifter/pkg/discovery Index | Examples | Files

package discovery

import "github.com/mhausenblas/reshifter/pkg/discovery"

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

Package Files

discovery.go doc.go visitors.go

func CountKeysFor Uses

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.

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.

Code:

// 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 Uses

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.

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.

Code:

// 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 Uses

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.

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.

Code:

// 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 Uses

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 Uses

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.

Package discovery imports 14 packages (graph) and is imported by 4 packages. Updated 2017-07-31. Refresh now. Tools for package owners.