-
Notifications
You must be signed in to change notification settings - Fork 0
/
labels.go
102 lines (84 loc) · 3.21 KB
/
labels.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package v1
import v1 "k8s.io/api/core/v1"
const (
// OwningAccountLabel is the name of the label that we apply to
// service groups and load balancers to indicate in a query-friendly
// way to which Account they belong.
OwningAccountLabel string = GroupName + "/owning-account"
// OwningLBServiceGroupLabel is the name of the label that we apply to
// endpoints to indicate in a query-friendly way to which
// LBServiceGroup they belong.
OwningLBServiceGroupLabel string = GroupName + "/owning-lbservicegroup"
// OwningServicePrefixLabel is the name of the label that we apply to
// endpoints to indicate in a query-friendly way to which
// ServicePrefix they belong.
OwningServicePrefixLabel string = GroupName + "/owning-serviceprefix"
// OwningLoadBalancerLabel is the name of the label that we apply to
// endpoints to indicate in a query-friendly way to which
// LoadBalancer they belong.
OwningLoadBalancerLabel string = GroupName + "/owning-loadbalancer"
// OwningProxyLabel is the name of the label that we apply to
// endpoints to indicate in a query-friendly way to which
// Proxy they belong.
OwningProxyLabel string = GroupName + "/owning-proxy"
// OwningClusterLabel is the name of the label that we apply to
// endpoints to indicate in a query-friendly way to which Cluster
// they belong.
OwningClusterLabel string = GroupName + "/owning-cluster"
)
var (
// UserNSLabels is the set of labels that indicate that a k8s
// namespace is an EPIC User Namespace.
UserNSLabels = map[string]string{"app.kubernetes.io/component": "user-namespace", "app.kubernetes.io/part-of": ProductName}
// envoyProxyLabels is the set of labels that we apply to our
// EnvoyDeployment CRs. Note that if these change then you'll need
// to update HasEnvoyLabels() and the python setup-network program
// so they match.
envoyProxyLabels = map[string]string{
"app.kubernetes.io/part-of": ProductName,
}
)
// LabelsForEnvoy returns the labels that we apply to a new Envoy
// proxy deployment.
func LabelsForEnvoy(name string) map[string]string {
// Copy the template label map
labels := make(map[string]string, len(envoyProxyLabels))
for k, v := range envoyProxyLabels {
labels[k] = v
}
// Override the owning LB placeholder with our actual owning LB
labels[OwningLoadBalancerLabel] = name
return labels
}
// LabelsForProxy returns the labels that we apply to a new Envoy
// proxy deployment.
func LabelsForProxy(name string) map[string]string {
// Copy the template label map
labels := make(map[string]string, len(envoyProxyLabels))
for k, v := range envoyProxyLabels {
labels[k] = v
}
// Override the owning LB placeholder with our actual owning LB
labels[OwningProxyLabel] = name
return labels
}
// HasEnvoyLabels indicates whether a Pod has the LabelsForEnvoy,
// i.e., whether the Pod is an Envoy proxy pod.
func HasEnvoyLabels(pod v1.Pod) bool {
partOf, hasPartOf := pod.ObjectMeta.Labels["app.kubernetes.io/part-of"]
if !hasPartOf {
return false
}
if partOf != ProductName {
return false
}
// This label is added by Marin3r
component, hasComponent := pod.ObjectMeta.Labels["app.kubernetes.io/component"]
if !hasComponent {
return false
}
if component != "envoy-deployment" {
return false
}
return true
}