/
operatorconfig.go
237 lines (190 loc) · 6.06 KB
/
operatorconfig.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package autodetect
import (
"strings"
"sync"
"github.com/spf13/viper"
v1 "github.com/jaegertracing/jaeger-operator/apis/v1"
)
// Platform holds the auto-detected running platform.
type Platform int
const (
// KubernetesPlatform represents the cluster is Kubernetes.
KubernetesPlatform Platform = iota
// OpenShiftPlatform represents the cluster is OpenShift.
OpenShiftPlatform
)
func (p Platform) String() string {
return [...]string{"Kubernetes", "OpenShift"}[p]
}
// ESOperatorIntegration holds the if the ES Operator integration is enabled.
type ESOperatorIntegration int
const (
// ESOperatorIntegrationYes represents the ES Operator integration is enabled.
ESOperatorIntegrationYes ESOperatorIntegration = iota
// ESOperatorIntegrationNo represents the ES Operator integration is disabled.
ESOperatorIntegrationNo
)
func (p ESOperatorIntegration) String() string {
return [...]string{"Yes", "No"}[p]
}
// KafkaOperatorIntegration holds the if the Kafka Operator integration is enabled.
type KafkaOperatorIntegration int
const (
// KafkaOperatorIntegrationYes represents the Kafka Operator integration is enabled.
KafkaOperatorIntegrationYes KafkaOperatorIntegration = iota
// KafkaOperatorIntegrationNo represents the Kafka Operator integration is disabled.
KafkaOperatorIntegrationNo
)
func (p KafkaOperatorIntegration) String() string {
return [...]string{"Yes", "No"}[p]
}
// AuthDelegatorAvailability holds the if the AuthDelegator available.
type AuthDelegatorAvailability int
const (
// AuthDelegatorAvailabilityYes represents the AuthDelegator is available.
AuthDelegatorAvailabilityYes AuthDelegatorAvailability = iota
// AuthDelegatorAvailabilityNo represents the AuthDelegator is not available.
AuthDelegatorAvailabilityNo
// AuthDelegatorAvailabilityUnknown represents the AuthDelegator availability is not known.
AuthDelegatorAvailabilityUnknown
)
func (p AuthDelegatorAvailability) String() string {
return [...]string{"Yes", "No", "Unknown"}[p]
}
var OperatorConfiguration operatorConfigurationWrapper
type operatorConfigurationWrapper struct {
mu sync.RWMutex
}
func (c *operatorConfigurationWrapper) SetPlatform(p interface{}) {
var platform string
switch v := p.(type) {
case string:
platform = v
case Platform:
platform = v.String()
default:
platform = KubernetesPlatform.String()
}
c.mu.Lock()
viper.Set(v1.FlagPlatform, platform)
c.mu.Unlock()
}
func (c *operatorConfigurationWrapper) GetPlatform() Platform {
c.mu.RLock()
p := viper.GetString(v1.FlagPlatform)
c.mu.RUnlock()
if strings.ToLower(p) == "openshift" {
return OpenShiftPlatform
}
return KubernetesPlatform
}
func (c *operatorConfigurationWrapper) IsPlatformAutodetectionEnabled() bool {
c.mu.RLock()
p := viper.GetString(v1.FlagPlatform)
c.mu.RUnlock()
return strings.EqualFold(p, v1.FlagPlatformAutoDetect)
}
func (c *operatorConfigurationWrapper) SetESIngration(e interface{}) {
var integration string
switch v := e.(type) {
case string:
integration = v
case ESOperatorIntegration:
integration = v.String()
default:
integration = ESOperatorIntegrationNo.String()
}
c.mu.Lock()
viper.Set(v1.FlagESProvision, integration)
c.mu.Unlock()
}
func (c *operatorConfigurationWrapper) GetESPIntegration() ESOperatorIntegration {
c.mu.RLock()
e := viper.GetString(v1.FlagESProvision)
c.mu.RUnlock()
if strings.ToLower(e) == "yes" {
return ESOperatorIntegrationYes
}
return ESOperatorIntegrationNo
}
// IsESOperatorIntegrationEnabled returns true if the integration with the
// Elasticsearch OpenShift Operator is enabled
func (c *operatorConfigurationWrapper) IsESOperatorIntegrationEnabled() bool {
return c.GetESPIntegration() == ESOperatorIntegrationYes
}
func (c *operatorConfigurationWrapper) SetKafkaIntegration(e interface{}) {
var integration string
switch v := e.(type) {
case string:
integration = v
case KafkaOperatorIntegration:
integration = v.String()
default:
integration = KafkaOperatorIntegrationNo.String()
}
c.mu.Lock()
viper.Set(v1.FlagKafkaProvision, integration)
c.mu.Unlock()
}
func (c *operatorConfigurationWrapper) GetKafkaIntegration() KafkaOperatorIntegration {
c.mu.RLock()
e := viper.GetString(v1.FlagKafkaProvision)
c.mu.RUnlock()
if strings.ToLower(e) == "yes" {
return KafkaOperatorIntegrationYes
}
return KafkaOperatorIntegrationNo
}
// IsKafkaOperatorIntegrationEnabled returns true if the integration with the
// Kafaka Operator is enabled
func (c *operatorConfigurationWrapper) IsKafkaOperatorIntegrationEnabled() bool {
return c.GetKafkaIntegration() == KafkaOperatorIntegrationYes
}
func (c *operatorConfigurationWrapper) SetAuthDelegatorAvailability(e interface{}) {
var availability string
switch v := e.(type) {
case string:
availability = v
case AuthDelegatorAvailability:
availability = v.String()
default:
availability = AuthDelegatorAvailabilityUnknown.String()
}
c.mu.Lock()
viper.Set(v1.FlagAuthDelegatorAvailability, availability)
c.mu.Unlock()
}
func (c *operatorConfigurationWrapper) GetAuthDelegator() AuthDelegatorAvailability {
c.mu.RLock()
e := viper.GetString(v1.FlagAuthDelegatorAvailability)
c.mu.RUnlock()
var available AuthDelegatorAvailability
switch strings.ToLower(e) {
case "yes":
available = AuthDelegatorAvailabilityYes
case "no":
available = AuthDelegatorAvailabilityNo
default:
available = AuthDelegatorAvailabilityUnknown
}
return available
}
// IsAuthDelegatorAvailable returns true if the AuthDelegator is available
func (c *operatorConfigurationWrapper) IsAuthDelegatorAvailable() bool {
return c.GetAuthDelegator() == AuthDelegatorAvailabilityYes
}
// IsAuthDelegatorAvailable returns true if the AuthDelegator is set
func (c *operatorConfigurationWrapper) IsAuthDelegatorSet() bool {
return c.GetAuthDelegator() != AuthDelegatorAvailabilityUnknown
}
func (c *operatorConfigurationWrapper) SetOautProxyImage(image string) {
c.mu.Lock()
viper.Set(v1.FlagOpenShiftOauthProxyImage, image)
c.mu.Unlock()
}
func (c *operatorConfigurationWrapper) GetOautProxyImage() string {
c.mu.RLock()
image := viper.GetString(v1.FlagOpenShiftOauthProxyImage)
c.mu.RUnlock()
return image
}