aboutme

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2017 License: Apache-2.0 Imports: 10 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

View Source
const DefaultNamespace = "default"

DefaultNamespace is the Kubernetes default namespace.

Variables

View Source
var (
	// EnvNamespace is the environment variable this looks for to get the namespace.
	//
	// You can set this via the Downward API.
	EnvNamespace = "POD_NAMESPACE"
	// EnvName is the environment variable this looks for to get the pod name.
	//
	// You can set this via the Downward API.
	EnvName = "POD_NAME"
)

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.

func NameFromEnv added in v0.2.0

func NameFromEnv() string

NameFromEnv gets the pod name from either the Downward API or the hostname.

func NamespaceFromEnv added in v0.2.0

func NamespaceFromEnv() string

NamespaceFromEnv attempts to get the namespace from the downward API.

If EnvNamespace is not set, or if the name is not recovered from the environment, then the DefaultNamespace is used.

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() *kubernetes.Clientset

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