-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.go
149 lines (119 loc) · 4.58 KB
/
helper.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package logstash
import (
"fmt"
"github.com/thoas/go-funk"
logstashcrd "github.com/webcenter-fr/elasticsearch-operator/apis/logstash/v1"
)
const (
defaultImage = "docker.elastic.co/logstash/logstash"
)
// GetConfigMapConfigName permit to get the configMap name that store the config
func GetConfigMapConfigName(ls *logstashcrd.Logstash) (configMapName string) {
return fmt.Sprintf("%s-config-ls", ls.Name)
}
// GetConfigMapPipelineName permit to get the configMap name that store the piepline
func GetConfigMapPipelineName(ls *logstashcrd.Logstash) (configMapName string) {
return fmt.Sprintf("%s-pipeline-ls", ls.Name)
}
// GetConfigMapPatternName permit to get the configMap name that store the pattern
func GetConfigMapPatternName(ls *logstashcrd.Logstash) (configMapName string) {
return fmt.Sprintf("%s-pattern-ls", ls.Name)
}
// GetServiceName permit to get the service name
func GetServiceName(ls *logstashcrd.Logstash, serviceName string) string {
return fmt.Sprintf("%s-%s-ls", ls.Name, serviceName)
}
// GetGlobalServiceName pemrit to get the global service name
func GetGlobalServiceName(ls *logstashcrd.Logstash) string {
return fmt.Sprintf("%s-headless-ls", ls.Name)
}
// GetSecretNameForCAElasticsearch permit to get the secret name that store all Elasticsearch CA
// It return the secret name as string
func GetSecretNameForCAElasticsearch(ls *logstashcrd.Logstash) (secretName string) {
return fmt.Sprintf("%s-ca-es-ls", ls.Name)
}
// GetSecretNameForKeystore permit to get the secret name that store the secret
// It will inject each key on keystore
// It return empty string if not secret provided
func GetSecretNameForKeystore(ls *logstashcrd.Logstash) (secretName string) {
if ls.Spec.KeystoreSecretRef != nil {
return ls.Spec.KeystoreSecretRef.Name
}
return ""
}
// GetPDBName permit to get the pdb name
func GetPDBName(ls *logstashcrd.Logstash) (serviceName string) {
return fmt.Sprintf("%s-ls", ls.Name)
}
// GetStatefulsetName permit to get the statefulset name
func GetStatefulsetName(ls *logstashcrd.Logstash) (name string) {
return fmt.Sprintf("%s-ls", ls.Name)
}
// GetContainerImage permit to get the image name
func GetContainerImage(ls *logstashcrd.Logstash) string {
version := "latest"
if ls.Spec.Version != "" {
version = ls.Spec.Version
}
image := defaultImage
if ls.Spec.Image != "" {
image = ls.Spec.Image
}
return fmt.Sprintf("%s:%s", image, version)
}
// GetSecretNameForPki permit to get the secret name that store PKI
// It return the secret name as string
func GetSecretNameForPki(ls *logstashcrd.Logstash) (secretName string) {
return fmt.Sprintf("%s-pki-ls", ls.Name)
}
// GetSecretNameForTls permit to get the secret name that store all certificates for Logstash
// It return the secret name as string
func GetSecretNameForTls(ls *logstashcrd.Logstash) (secretName string) {
return fmt.Sprintf("%s-tls-ls", ls.Name)
}
// getLabels permit to return global label must be set on all resources
func getLabels(ls *logstashcrd.Logstash, customLabels ...map[string]string) (labels map[string]string) {
labels = map[string]string{
"cluster": ls.Name,
logstashcrd.LogstashAnnotationKey: "true",
}
for _, label := range customLabels {
for key, val := range label {
labels[key] = val
}
}
labels = funk.UnionStringMap(labels, ls.Labels)
return labels
}
// getAnnotations permit to return global annotations must be set on all resources
func getAnnotations(ls *logstashcrd.Logstash, customAnnotation ...map[string]string) (annotations map[string]string) {
annotations = map[string]string{
logstashcrd.LogstashAnnotationKey: "true",
}
for _, annotation := range customAnnotation {
for key, val := range annotation {
annotations[key] = val
}
}
return annotations
}
// GetSecretNameForCredentials permit to get the secret name that store the credentials
func GetSecretNameForCredentials(ls *logstashcrd.Logstash) (secretName string) {
return fmt.Sprintf("%s-credential-ls", ls.Name)
}
// GetNetworkPolicyName return the name for network policy
func GetNetworkPolicyName(ls *logstashcrd.Logstash) string {
return fmt.Sprintf("%s-allow-ls", ls.Name)
}
// GetPodMonitorName return the name for podMonitor
func GetPodMonitorName(ls *logstashcrd.Logstash) string {
return fmt.Sprintf("%s-ls", ls.Name)
}
// GetIngressName permit to get the ingress name
func GetIngressName(ls *logstashcrd.Logstash, ingressName string) string {
return fmt.Sprintf("%s-%s-ls", ls.Name, ingressName)
}
// GetMetricbeatName return the metricbeat namme
func GetMetricbeatName(ls *logstashcrd.Logstash) (name string) {
return fmt.Sprintf("%s-metricbeat-ls", ls.Name)
}