-
Notifications
You must be signed in to change notification settings - Fork 185
/
utils.go
45 lines (37 loc) 路 1.01 KB
/
utils.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
package runtime_details
import (
"context"
"github.com/keyval-dev/odigos/common/consts"
"github.com/keyval-dev/odigos/odiglet/pkg/log"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func isObjectLabeled(obj client.Object) bool {
labels := obj.GetLabels()
if labels != nil {
val, exists := labels[consts.OdigosInstrumentationLabel]
if exists && val == consts.InstrumentationEnabled {
return true
}
}
return false
}
func isInstrumentationDisabledExplicitly(obj client.Object) bool {
labels := obj.GetLabels()
if labels != nil {
val, exists := labels[consts.OdigosInstrumentationLabel]
if exists && val == consts.InstrumentationDisabled {
return true
}
}
return false
}
func isNamespaceLabeled(ctx context.Context, obj client.Object, c client.Client) bool {
var ns corev1.Namespace
err := c.Get(ctx, client.ObjectKey{Name: obj.GetNamespace()}, &ns)
if err != nil {
log.Logger.Error(err, "error fetching namespace object")
return false
}
return isObjectLabeled(&ns)
}