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 ¶
const DefaultNamespace = "default"
DefaultNamespace is the Kubernetes default namespace.
Variables ¶
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 MyIP ¶
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 ¶
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]