Skip to content

Commit 2ee6d05

Browse files
authored
Remove an unnecessary error return value by compiling the regex (#1977)
1 parent 90608c4 commit 2ee6d05

File tree

5 files changed

+32
-71
lines changed

5 files changed

+32
-71
lines changed

controllers/cluster_controller.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,7 @@ func (r *FoundationDBClusterReconciler) updatePodDynamicConf(logger logr.Logger,
323323

324324
imageType := internal.GetImageType(pod)
325325
if imageType == internal.FDBImageTypeUnified {
326-
config, err := internal.GetMonitorProcessConfiguration(cluster, processClass, serversPerPod, imageType, nil)
327-
if err != nil {
328-
return false, err
329-
}
326+
config := internal.GetMonitorProcessConfiguration(cluster, processClass, serversPerPod, imageType, nil)
330327
configData, err := json.Marshal(config)
331328
if err != nil {
332329
return false, err

internal/configmap_helper.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ func getConfigMapMetadata(cluster *fdbv1beta2.FoundationDBCluster) metav1.Object
145145
}
146146

147147
func getDataForMonitorConf(cluster *fdbv1beta2.FoundationDBCluster, imageType FDBImageType, pClass fdbv1beta2.ProcessClass, serversPerPod int) (string, []byte, error) {
148-
config, err := GetMonitorProcessConfiguration(cluster, pClass, serversPerPod, imageType, nil)
149-
if err != nil {
150-
return "", nil, err
151-
}
148+
config := GetMonitorProcessConfiguration(cluster, pClass, serversPerPod, imageType, nil)
152149
jsonData, err := json.Marshal(config)
153150
if err != nil {
154151
return "", nil, err

internal/configmap_helper_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ var _ = Describe("configmap_helper", func() {
9393
config := monitorapi.ProcessConfiguration{}
9494
err = json.Unmarshal([]byte(jsonData), &config)
9595
Expect(err).NotTo(HaveOccurred())
96-
expectedConfig, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
97-
Expect(err).NotTo(HaveOccurred())
96+
expectedConfig := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
9897
Expect(config).To(Equal(expectedConfig))
9998
})
10099

@@ -165,17 +164,15 @@ var _ = Describe("configmap_helper", func() {
165164
config := monitorapi.ProcessConfiguration{}
166165
err = json.Unmarshal([]byte(jsonData), &config)
167166
Expect(err).NotTo(HaveOccurred())
168-
expectedConfig, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
169-
Expect(err).NotTo(HaveOccurred())
167+
expectedConfig := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
170168
Expect(config).To(Equal(expectedConfig))
171169

172170
jsonData, present = configMap.Data["fdbmonitor-conf-storage-json-multiple"]
173171
Expect(present).To(BeTrue())
174172
config = monitorapi.ProcessConfiguration{}
175173
err = json.Unmarshal([]byte(jsonData), &config)
176174
Expect(err).NotTo(HaveOccurred())
177-
expectedConfig, err = GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 2, FDBImageTypeUnified, nil)
178-
Expect(err).NotTo(HaveOccurred())
175+
expectedConfig = GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 2, FDBImageTypeUnified, nil)
179176
Expect(config).To(Equal(expectedConfig))
180177
})
181178

@@ -213,17 +210,15 @@ var _ = Describe("configmap_helper", func() {
213210
config := monitorapi.ProcessConfiguration{}
214211
err = json.Unmarshal([]byte(jsonData), &config)
215212
Expect(err).NotTo(HaveOccurred())
216-
expectedConfig, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassLog, 1, FDBImageTypeUnified, nil)
217-
Expect(err).NotTo(HaveOccurred())
213+
expectedConfig := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassLog, 1, FDBImageTypeUnified, nil)
218214
Expect(config).To(Equal(expectedConfig))
219215

220216
jsonData, present = configMap.Data["fdbmonitor-conf-log-json-multiple"]
221217
Expect(present).To(BeTrue())
222218
config = monitorapi.ProcessConfiguration{}
223219
err = json.Unmarshal([]byte(jsonData), &config)
224220
Expect(err).NotTo(HaveOccurred())
225-
expectedConfig, err = GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassLog, 2, FDBImageTypeUnified, nil)
226-
Expect(err).NotTo(HaveOccurred())
221+
expectedConfig = GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassLog, 2, FDBImageTypeUnified, nil)
227222
Expect(config).To(Equal(expectedConfig))
228223
})
229224

internal/monitor_conf.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,13 @@ func GetStartCommandWithSubstitutions(cluster *fdbv1beta2.FoundationDBCluster, p
4949
}
5050

5151
imageType := GetDesiredImageType(cluster)
52-
config, err := GetMonitorProcessConfiguration(cluster, processClass, processCount, imageType, substitutions)
53-
if err != nil {
54-
return "", err
55-
}
52+
config := GetMonitorProcessConfiguration(cluster, processClass, processCount, imageType, substitutions)
5653

5754
extractPlaceholderEnvVars(substitutions, config.Arguments)
5855

5956
config.BinaryPath = fmt.Sprintf("%s/fdbserver", substitutions["BINARY_DIR"])
6057

6158
arguments, err := config.GenerateArguments(processNumber, substitutions)
62-
6359
if err != nil {
6460
return "", err
6561
}
@@ -131,10 +127,7 @@ func GetMonitorConf(cluster *fdbv1beta2.FoundationDBCluster, processClass fdbv1b
131127
func getMonitorConfStartCommandLines(cluster *fdbv1beta2.FoundationDBCluster, processClass fdbv1beta2.ProcessClass, substitutions map[string]string, processNumber int, processCount int) ([]string, error) {
132128
confLines := make([]string, 0, 20)
133129

134-
config, err := GetMonitorProcessConfiguration(cluster, processClass, processCount, FDBImageTypeSplit, substitutions)
135-
if err != nil {
136-
return nil, err
137-
}
130+
config := GetMonitorProcessConfiguration(cluster, processClass, processCount, FDBImageTypeSplit, substitutions)
138131

139132
if substitutions == nil {
140133
substitutions = make(map[string]string)
@@ -162,8 +155,10 @@ func getMonitorConfStartCommandLines(cluster *fdbv1beta2.FoundationDBCluster, pr
162155
return confLines, nil
163156
}
164157

158+
var equalPattern = regexp.MustCompile(`\s*=\s*`)
159+
165160
// GetMonitorProcessConfiguration builds the monitor conf template for the unified image.
166-
func GetMonitorProcessConfiguration(cluster *fdbv1beta2.FoundationDBCluster, processClass fdbv1beta2.ProcessClass, processCount int, imageType FDBImageType, customParameterSubstitutions map[string]string) (monitorapi.ProcessConfiguration, error) {
161+
func GetMonitorProcessConfiguration(cluster *fdbv1beta2.FoundationDBCluster, processClass fdbv1beta2.ProcessClass, processCount int, imageType FDBImageType, customParameterSubstitutions map[string]string) monitorapi.ProcessConfiguration {
167162
configuration := monitorapi.ProcessConfiguration{
168163
Version: cluster.Spec.Version,
169164
}
@@ -240,10 +235,6 @@ func GetMonitorProcessConfiguration(cluster *fdbv1beta2.FoundationDBCluster, pro
240235
podSettings := cluster.GetProcessSettings(processClass)
241236

242237
if podSettings.CustomParameters != nil {
243-
equalPattern, err := regexp.Compile(`\s*=\s*`)
244-
if err != nil {
245-
return configuration, err
246-
}
247238
for _, argument := range podSettings.CustomParameters {
248239
sanitizedArgument := "--" + equalPattern.ReplaceAllString(string(argument), "=")
249240
for key, value := range customParameterSubstitutions {
@@ -268,7 +259,7 @@ func GetMonitorProcessConfiguration(cluster *fdbv1beta2.FoundationDBCluster, pro
268259
}})
269260
}
270261

271-
return configuration, nil
262+
return configuration
272263
}
273264

274265
// getKnobParameter will return the knob parameter with a trailing =. If the provided knob is a locality the key will be

internal/monitor_conf_test.go

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ var _ = Describe("monitor_conf", func() {
5656
It("generates conf with an no processes", func() {
5757
Expect(cluster).NotTo(BeNil())
5858
cluster.Status.ConnectionString = ""
59-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
60-
Expect(err).NotTo(HaveOccurred())
59+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
6160
Expect(config.RunServers).NotTo(BeNil())
6261
Expect(*config.RunServers).To(BeFalse())
6362
Expect(config.Version).To(Equal(fdbv1beta2.Versions.Default.String()))
@@ -66,8 +65,7 @@ var _ = Describe("monitor_conf", func() {
6665

6766
When("running a storage instance", func() {
6867
It("generates the conf", func() {
69-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
70-
Expect(err).NotTo(HaveOccurred())
68+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
7169
Expect(config.Version).To(Equal(fdbv1beta2.Versions.Default.String()))
7270
Expect(config.BinaryPath).To(BeEmpty())
7371
Expect(config.RunServers).To(BeNil())
@@ -102,8 +100,7 @@ var _ = Describe("monitor_conf", func() {
102100

103101
When("running a log instance", func() {
104102
It("generates the conf", func() {
105-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassLog, 1, FDBImageTypeUnified, nil)
106-
Expect(err).NotTo(HaveOccurred())
103+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassLog, 1, FDBImageTypeUnified, nil)
107104
Expect(config.Version).To(Equal(fdbv1beta2.Versions.Default.String()))
108105
Expect(config.BinaryPath).To(BeEmpty())
109106
Expect(config.RunServers).To(BeNil())
@@ -115,8 +112,7 @@ var _ = Describe("monitor_conf", func() {
115112

116113
When("using the split image type", func() {
117114
It("generates the conf", func() {
118-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeSplit, nil)
119-
Expect(err).NotTo(HaveOccurred())
115+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeSplit, nil)
120116
Expect(config.Version).To(Equal(fdbv1beta2.Versions.Default.String()))
121117
Expect(config.BinaryPath).To(BeEmpty())
122118
Expect(config.RunServers).To(BeNil())
@@ -151,8 +147,7 @@ var _ = Describe("monitor_conf", func() {
151147

152148
When("running multiple processes", func() {
153149
It("adds a process ID argument", func() {
154-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 2, FDBImageTypeUnified, nil)
155-
Expect(err).NotTo(HaveOccurred())
150+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 2, FDBImageTypeUnified, nil)
156151
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
157152
Expect(config.Arguments[7]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
158153
{Value: "--locality_process_id="},
@@ -167,8 +162,7 @@ var _ = Describe("monitor_conf", func() {
167162
})
168163

169164
It("includes the process number in the data directory", func() {
170-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 2, FDBImageTypeUnified, nil)
171-
Expect(err).NotTo(HaveOccurred())
165+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 2, FDBImageTypeUnified, nil)
172166
Expect(config.Arguments[6]).To(Equal(monitorapi.Argument{
173167
ArgumentType: monitorapi.ConcatenateArgumentType,
174168
Values: []monitorapi.Argument{
@@ -186,8 +180,7 @@ var _ = Describe("monitor_conf", func() {
186180
})
187181

188182
It("does not have a listen address", func() {
189-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
190-
Expect(err).NotTo(HaveOccurred())
183+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
191184
Expect(config.Arguments).To(HaveLen(baseArgumentLength))
192185
Expect(config.Arguments[2]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
193186
{Value: "--public_address=["},
@@ -206,8 +199,7 @@ var _ = Describe("monitor_conf", func() {
206199
})
207200

208201
It("adds a separate listen address", func() {
209-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
210-
Expect(err).NotTo(HaveOccurred())
202+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
211203
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
212204
Expect(config.Arguments[2]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
213205
{Value: "--public_address=["},
@@ -229,8 +221,7 @@ var _ = Describe("monitor_conf", func() {
229221
})
230222

231223
It("does not have a listen address", func() {
232-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
233-
Expect(err).NotTo(HaveOccurred())
224+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
234225
Expect(config.Arguments).To(HaveLen(baseArgumentLength))
235226
Expect(config.Arguments[2]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
236227
{Value: "--public_address=["},
@@ -250,8 +241,7 @@ var _ = Describe("monitor_conf", func() {
250241
})
251242

252243
It("includes the TLS flag in the address", func() {
253-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
254-
Expect(err).NotTo(HaveOccurred())
244+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
255245
Expect(config.Arguments).To(HaveLen(baseArgumentLength))
256246
Expect(config.Arguments[2]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
257247
{Value: "--public_address=["},
@@ -271,8 +261,7 @@ var _ = Describe("monitor_conf", func() {
271261
})
272262

273263
It("includes both addresses", func() {
274-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
275-
Expect(err).NotTo(HaveOccurred())
264+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
276265
Expect(config.Arguments).To(HaveLen(baseArgumentLength))
277266
Expect(config.Arguments[2]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
278267
{Value: "--public_address=["},
@@ -296,8 +285,7 @@ var _ = Describe("monitor_conf", func() {
296285
})
297286

298287
It("includes both addresses", func() {
299-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
300-
Expect(err).NotTo(HaveOccurred())
288+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
301289
Expect(config.Arguments).To(HaveLen(baseArgumentLength))
302290
Expect(config.Arguments[2]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
303291
{Value: "--public_address=["},
@@ -322,8 +310,7 @@ var _ = Describe("monitor_conf", func() {
322310
})
323311

324312
It("includes the custom parameters", func() {
325-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
326-
Expect(err).NotTo(HaveOccurred())
313+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
327314
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
328315
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{Value: "--knob_disable_posix_kernel_aio=1"}))
329316
})
@@ -345,8 +332,7 @@ var _ = Describe("monitor_conf", func() {
345332
})
346333

347334
It("includes the custom parameters for that class", func() {
348-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
349-
Expect(err).NotTo(HaveOccurred())
335+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
350336
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
351337
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{Value: "--knob_test=test1"}))
352338
})
@@ -362,8 +348,7 @@ var _ = Describe("monitor_conf", func() {
362348
})
363349

364350
It("uses the variable as the zone ID", func() {
365-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
366-
Expect(err).NotTo(HaveOccurred())
351+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
367352
Expect(config.Arguments).To(HaveLen(baseArgumentLength))
368353

369354
Expect(config.Arguments[9]).To(Equal(monitorapi.Argument{ArgumentType: monitorapi.ConcatenateArgumentType, Values: []monitorapi.Argument{
@@ -379,8 +364,7 @@ var _ = Describe("monitor_conf", func() {
379364
})
380365

381366
It("includes the verification rules", func() {
382-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
383-
Expect(err).NotTo(HaveOccurred())
367+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
384368
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
385369
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{Value: "--tls_verify_peers=S.CN=foundationdb.org"}))
386370
})
@@ -392,8 +376,7 @@ var _ = Describe("monitor_conf", func() {
392376
})
393377

394378
It("includes the log group", func() {
395-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
396-
Expect(err).NotTo(HaveOccurred())
379+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
397380
Expect(config.Arguments).To(HaveLen(baseArgumentLength))
398381
Expect(config.Arguments[5]).To(Equal(monitorapi.Argument{Value: "--loggroup=test-fdb-cluster"}))
399382
})
@@ -405,8 +388,7 @@ var _ = Describe("monitor_conf", func() {
405388
})
406389

407390
It("adds an argument for the data center", func() {
408-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
409-
Expect(err).NotTo(HaveOccurred())
391+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
410392
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
411393
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{Value: "--locality_dcid=dc01"}))
412394
})
@@ -418,8 +400,7 @@ var _ = Describe("monitor_conf", func() {
418400
})
419401

420402
It("adds an argument for the data hall", func() {
421-
config, err := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
422-
Expect(err).NotTo(HaveOccurred())
403+
config := GetMonitorProcessConfiguration(cluster, fdbv1beta2.ProcessClassStorage, 1, FDBImageTypeUnified, nil)
423404
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
424405
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{Value: "--locality_data_hall=dh01"}))
425406
})

0 commit comments

Comments
 (0)