aboutme

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2015 License: Apache-2.0 Imports: 9 Imported by: 6

README

aboutme: Self-discovery for Kubernetes containers

This library provides hooks for containers to learn about themselves and their pods.

Essentially, this uses environmental data to connect to a k8s API server and find out about the current pod's configuration.

Documentation

Overview

Package aboutme provides information to a pod about itself.

Typical usage is to let the Pod auto-detect information about itself:

	my, err := aboutme.FromEnv()
 if err != nil {
		// Error connecting to tke k8s API server
	}

	fmt.Printf("My Pod Name is %s", my.Name)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPByInterface

func IPByInterface(name string) (string, error)

func MyIP

func MyIP() (string, error)

MyIP examines the local interfaces and guesses which is its IP.

Containers tend to put the IP address in eth0, so this attempts to look up that interface and retrieve its IP. It is fairly naive. To get more thorough IP information, you may prefer to use the `net` package and look up the desired information.

Because this queries the interfaces, not the Kube API server, this could, in theory, return an IP address different from Me.IP.

Types

type Me

type Me struct {
	ApiServer, Name                      string
	IP, NodeIP, Namespace, SelfLink, UID string
	Labels                               map[string]string
	Annotations                          map[string]string
	// contains filtered or unexported fields
}

func FromEnv

func FromEnv() (*Me, error)

FromEnv uses the environment to create a new Me.

To use this, a client MUST be running inside of a Pod environment. It uses a combination of environment variables and file paths to determine information about the cluster.

func (*Me) Client

func (me *Me) Client() *unversioned.Client

Client returns an initialized Kubernetes API client.

func (*Me) ShuntEnv

func (me *Me) ShuntEnv()

ShuntEnv puts the Me object into the environment.

The properties of Me are placed into the environment according to the following rules:

  • In general, all variables are prefaced with MY_ (MY_IP, MY_NAMESPACE)
  • Labels become MY_LABEL_[NAME]=[value]
  • Annotations become MY_ANNOTATION_[NAME] = [value]

Jump to

Keyboard shortcuts

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