-
Notifications
You must be signed in to change notification settings - Fork 99
/
configmap.go
63 lines (52 loc) · 1.85 KB
/
configmap.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package orchestratorexplorer
import (
"fmt"
"strconv"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object/configmap"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (f *orchestratorExplorerFeature) buildOrchestratorExplorerConfigMap() (*corev1.ConfigMap, error) {
if f.customConfig != nil && f.customConfig.ConfigMap != nil {
return nil, nil
}
if f.customConfig != nil && f.customConfig.ConfigData != nil {
return configmap.BuildConfigMapConfigData(f.owner.GetNamespace(), f.customConfig.ConfigData, f.configConfigMapName, orchestratorExplorerConfFileName)
}
configMap := buildDefaultConfigMap(f.owner.GetNamespace(), f.configConfigMapName, orchestratorExplorerCheckConfig(f.runInClusterChecksRunner, f.customResources))
return configMap, nil
}
func buildDefaultConfigMap(namespace, cmName string, content string) *corev1.ConfigMap {
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: cmName,
Namespace: namespace,
},
Data: map[string]string{
orchestratorExplorerConfFileName: content,
},
}
return configMap
}
func orchestratorExplorerCheckConfig(clusterCheckRunners bool, crs []string) string {
stringClusterCheckRunners := strconv.FormatBool(clusterCheckRunners)
config := fmt.Sprintf(`---
cluster_check: %s
ad_identifiers:
- _kube_orchestrator
init_config:
instances:
- skip_leader_election: %s
`, stringClusterCheckRunners, stringClusterCheckRunners)
if len(crs) > 0 {
config = config + " crd_collectors:\n"
for _, cr := range crs {
config = config + fmt.Sprintf(" - %s\n", cr)
}
}
return config
}