-
Notifications
You must be signed in to change notification settings - Fork 4
/
container.go
41 lines (35 loc) · 982 Bytes
/
container.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package system
import (
"regexp"
"sync"
)
// Kubernetes represents information about the kubernetes environment.
type Kubernetes struct {
// Namespace is the namespace of the pod.
Namespace string
// PodName is the name of the pod.
PodName string
// PodUID is the unique identifier of the pod.
PodUID string
// NodeName is the name of the node.
NodeName string
}
// Container metadata.
type Container struct {
// ID of the container.
ID string
// Kubernetes metadata.
Kubernetes *Kubernetes
}
var (
containerOnce sync.Once
container *Container
podUIDRegex = regexp.MustCompile(`(?:^/kubepods[\\S]*/pod([^/]+)$)|(?:kubepods[^/]*-pod([^/]+)\.slice)`)
containerIDRegex = regexp.MustCompile(`^[[:xdigit:]]{64}$|^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4,}$|^[[:xdigit:]]{32}-[[:digit:]]{10}$`)
)
func containerInfo() *Container {
containerOnce.Do(func() {
container, _ = detectContainer()
})
return container
}