Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/operator/assets/assets.go
4095 views
1
// Package assets contains helper types used for loading in static assets when
2
// configuring the Grafana Agent.
3
package assets
4
5
import (
6
"fmt"
7
8
prom_v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
9
v1 "k8s.io/api/core/v1"
10
)
11
12
// Key is a path-like identifier representing a Secret or ConfigMap value. It is
13
// used for looking up values during config generation that cannot be loaded
14
// directly from a file (e.g., BasicAuth Username).
15
//
16
// The naming convention is either:
17
//
18
// /secrets/<namespace>/<name>/<key>
19
//
20
// or:
21
//
22
// /configMaps/<namespace>/<name>/<key>
23
//
24
// Resources associated with a key should be watched for changes and trigger a
25
// reconcile when modified.
26
type Key string
27
28
// SecretStore is an in-memory cache for secrets, intended to be used for
29
// static secrets in generated configuration files.
30
type SecretStore map[Key]string
31
32
// KeyForSecret returns the key for a given namespace and a secret key
33
// selector.
34
func KeyForSecret(namespace string, sel *v1.SecretKeySelector) Key {
35
if sel == nil {
36
return Key("")
37
}
38
return Key(fmt.Sprintf("/secrets/%s/%s/%s", namespace, sel.Name, sel.Key))
39
}
40
41
// KeyForConfigMap returns the key for a given namespace and a config map
42
// key selector.
43
func KeyForConfigMap(namespace string, sel *v1.ConfigMapKeySelector) Key {
44
if sel == nil {
45
return Key("")
46
}
47
return Key(fmt.Sprintf("/configMaps/%s/%s/%s", namespace, sel.Name, sel.Key))
48
}
49
50
// KeyForSelector retrieves the key for a SecretOrConfigMap.
51
func KeyForSelector(namespace string, sel *prom_v1.SecretOrConfigMap) Key {
52
switch {
53
case sel.ConfigMap != nil:
54
return KeyForConfigMap(namespace, sel.ConfigMap)
55
case sel.Secret != nil:
56
return KeyForSecret(namespace, sel.Secret)
57
default:
58
return Key("")
59
}
60
}
61
62