Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit 0872fec

Browse files
committed
Tidy up issues highlighted by Go Report Card
1 parent ac34af2 commit 0872fec

File tree

6 files changed

+45
-40
lines changed

6 files changed

+45
-40
lines changed

pkg/apis/mysql/v1alpha1/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ type ClusterSpec struct {
2929
Version string `json:"version"`
3030
// Members defines the number of MySQL instances in a cluster
3131
Members int32 `json:"members,omitempty"`
32-
// BaseServerID defines the base number used to create uniq server_id for MySQL instances in a cluster.
33-
// The baseServerId value need to be in range from 1 to 4294967286
34-
// If ommited in the manifest file, or set to 0, defaultBaseServerID value will be used.
32+
// BaseServerID defines the base number used to create unique server_id
33+
// for MySQL instances in the cluster. Valid range 1 to 4294967286.
34+
// If omitted in the manifest file (or set to 0) defaultBaseServerID
35+
// value will be used.
3536
BaseServerID uint32 `json:"baseServerId,omitempty"`
3637
// MultiMaster defines the mode of the MySQL cluster. If set to true,
3738
// all instances will be R/W. If false (the default), only a single instance

pkg/cluster/innodb/innodb_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestDeepCopyReplicaSet(t *testing.T) {
6565
Primary: "localhost:3310",
6666
Status: "OK",
6767
Topology: map[string]*Instance{
68-
"localhost:3310": &Instance{
68+
"localhost:3310": {
6969
Address: "localhost:3310",
7070
Mode: "R/O",
7171
Role: "HA",
@@ -107,7 +107,7 @@ func TestDeepCopyClusterStatus(t *testing.T) {
107107
Primary: "localhost:3310",
108108
Status: "OK",
109109
Topology: map[string]*Instance{
110-
"localhost:3310": &Instance{
110+
"localhost:3310": {
111111
Address: "localhost:3310",
112112
Mode: "R/O",
113113
Role: "HA",

pkg/controllers/cluster/controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,15 @@ func (m *MySQLController) syncHandler(key string) error {
421421
return nil
422422
}
423423

424-
// ensureMySQLOperatorVersion updates the MySQLOperator resource types that require it to make it consistent with the specifed operator version.
424+
// ensureMySQLOperatorVersion updates the MySQLOperator resource types that
425+
//require it to make it consistent with the specified operator version.
425426
func (m *MySQLController) ensureMySQLOperatorVersion(c *v1alpha1.Cluster, ss *apps.StatefulSet, operatorVersion string) error {
426427
// Ensure the Pods belonging to the Cluster are updated to the correct 'mysql-agent' image for the current MySQLOperator version.
427428
container := statefulsets.MySQLAgentName
428429
pods, err := m.podLister.List(SelectorForCluster(c))
430+
if err != nil {
431+
return errors.Wrapf(err, "listing pods matching %q", SelectorForCluster(c).String())
432+
}
429433
for _, pod := range pods {
430434
if requiresMySQLAgentPodUpgrade(pod, container, operatorVersion) && canUpgradeMySQLAgent(pod) {
431435
glog.Infof("Upgrading cluster pod '%s/%s' to latest operator version: %s", pod.Namespace, pod.Name, operatorVersion)

pkg/controllers/cluster/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func TestMySQLControllerSyncClusterFromScratch(t *testing.T) {
408408
assertOperatorServiceInvariants(t, fakeController, cluster)
409409
assertOperatorStatefulSetInvariants(t, fakeController, cluster)
410410
assertOperatorVersionInvariants(t, fakeController, namespace, name, version)
411-
cluster, err := fakeController.opClient.MySQLV1alpha1().Clusters(namespace).Get(name, metav1.GetOptions{})
411+
_, err := fakeController.opClient.MySQLV1alpha1().Clusters(namespace).Get(name, metav1.GetOptions{})
412412
if err != nil {
413413
t.Fatalf("Get client Cluster err: %+v", err)
414414
}
@@ -482,7 +482,7 @@ func mockClusterPod(ss *apps.StatefulSet, ordinal int) *v1.Pod {
482482
},
483483
Spec: v1.PodSpec{
484484
Containers: []v1.Container{
485-
v1.Container{Name: statefulsets.MySQLAgentName, Image: image},
485+
{Name: statefulsets.MySQLAgentName, Image: image},
486486
},
487487
},
488488
}

pkg/controllers/cluster/labeler/cluster_labeler_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func fakeWorker(clc *ClusterLabelerController) {
6161

6262
func TestClusterLabelerLabelsPrimaryAndSecondaries(t *testing.T) {
6363
pods := []corev1.Pod{
64-
corev1.Pod{
64+
{
6565
TypeMeta: metav1.TypeMeta{
6666
APIVersion: "v1",
6767
Kind: "Pod",
@@ -74,7 +74,7 @@ func TestClusterLabelerLabelsPrimaryAndSecondaries(t *testing.T) {
7474
},
7575
},
7676
},
77-
corev1.Pod{
77+
{
7878
TypeMeta: metav1.TypeMeta{
7979
APIVersion: "v1",
8080
Kind: "Pod",
@@ -87,7 +87,7 @@ func TestClusterLabelerLabelsPrimaryAndSecondaries(t *testing.T) {
8787
},
8888
},
8989
},
90-
corev1.Pod{
90+
{
9191
TypeMeta: metav1.TypeMeta{
9292
APIVersion: "v1",
9393
Kind: "Pod",
@@ -109,19 +109,19 @@ func TestClusterLabelerLabelsPrimaryAndSecondaries(t *testing.T) {
109109
Status: "OK",
110110
StatusText: "Cluster is ONLINE and can tolerate up to ONE failure.",
111111
Topology: map[string]*innodb.Instance{
112-
"test-cluster-0.test-cluster:3306": &innodb.Instance{
112+
"test-cluster-0.test-cluster:3306": {
113113
Address: "test-cluster-0.test-cluster:3306",
114114
Mode: "R/W",
115115
Role: "HA",
116116
Status: innodb.InstanceStatusOnline,
117117
},
118-
"test-cluster-1.test-cluster:3306": &innodb.Instance{
118+
"test-cluster-1.test-cluster:3306": {
119119
Address: "test-cluster-1.test-cluster:3306",
120120
Mode: "R/O",
121121
Role: "HA",
122122
Status: innodb.InstanceStatusOnline,
123123
},
124-
"test-cluster-2.test-cluster:3306": &innodb.Instance{
124+
"test-cluster-2.test-cluster:3306": {
125125
Address: "test-cluster-2.test-cluster:3306",
126126
Mode: "R/O",
127127
Role: "HA",
@@ -174,7 +174,7 @@ func TestClusterLabelerLabelsPrimaryAndSecondaries(t *testing.T) {
174174

175175
func TestClusterLabelerRelabelsOldPrimary(t *testing.T) {
176176
pods := []corev1.Pod{
177-
corev1.Pod{
177+
{
178178
TypeMeta: metav1.TypeMeta{
179179
APIVersion: "v1",
180180
Kind: "Pod",
@@ -188,7 +188,7 @@ func TestClusterLabelerRelabelsOldPrimary(t *testing.T) {
188188
},
189189
},
190190
},
191-
corev1.Pod{
191+
{
192192
TypeMeta: metav1.TypeMeta{
193193
APIVersion: "v1",
194194
Kind: "Pod",
@@ -202,7 +202,7 @@ func TestClusterLabelerRelabelsOldPrimary(t *testing.T) {
202202
},
203203
},
204204
},
205-
corev1.Pod{
205+
{
206206
TypeMeta: metav1.TypeMeta{
207207
APIVersion: "v1",
208208
Kind: "Pod",
@@ -225,19 +225,19 @@ func TestClusterLabelerRelabelsOldPrimary(t *testing.T) {
225225
Status: "OK",
226226
StatusText: "Cluster is ONLINE and can tolerate up to ONE failure.",
227227
Topology: map[string]*innodb.Instance{
228-
"test-cluster-0.test-cluster:3306": &innodb.Instance{
228+
"test-cluster-0.test-cluster:3306": {
229229
Address: "test-cluster-0.test-cluster:3306",
230230
Mode: "R/O",
231231
Role: "HA",
232232
Status: innodb.InstanceStatusOnline,
233233
},
234-
"test-cluster-1.test-cluster:3306": &innodb.Instance{
234+
"test-cluster-1.test-cluster:3306": {
235235
Address: "test-cluster-1.test-cluster:3306",
236236
Mode: "R/W",
237237
Role: "HA",
238238
Status: innodb.InstanceStatusOnline,
239239
},
240-
"test-cluster-2.test-cluster:3306": &innodb.Instance{
240+
"test-cluster-2.test-cluster:3306": {
241241
Address: "test-cluster-2.test-cluster:3306",
242242
Mode: "R/O",
243243
Role: "HA",
@@ -280,7 +280,7 @@ func TestClusterLabelerRelabelsOldPrimary(t *testing.T) {
280280

281281
func TestClusterLabelerDoesntRelabelCorrectlyLabeledPods(t *testing.T) {
282282
pods := []corev1.Pod{
283-
corev1.Pod{
283+
{
284284
TypeMeta: metav1.TypeMeta{
285285
APIVersion: "v1",
286286
Kind: "Pod",
@@ -294,7 +294,7 @@ func TestClusterLabelerDoesntRelabelCorrectlyLabeledPods(t *testing.T) {
294294
},
295295
},
296296
},
297-
corev1.Pod{
297+
{
298298
TypeMeta: metav1.TypeMeta{
299299
APIVersion: "v1",
300300
Kind: "Pod",
@@ -308,7 +308,7 @@ func TestClusterLabelerDoesntRelabelCorrectlyLabeledPods(t *testing.T) {
308308
},
309309
},
310310
},
311-
corev1.Pod{
311+
{
312312
TypeMeta: metav1.TypeMeta{
313313
APIVersion: "v1",
314314
Kind: "Pod",
@@ -331,19 +331,19 @@ func TestClusterLabelerDoesntRelabelCorrectlyLabeledPods(t *testing.T) {
331331
Status: "OK",
332332
StatusText: "Cluster is ONLINE and can tolerate up to ONE failure.",
333333
Topology: map[string]*innodb.Instance{
334-
"test-cluster-0.test-cluster:3306": &innodb.Instance{
334+
"test-cluster-0.test-cluster:3306": {
335335
Address: "test-cluster-0.test-cluster:3306",
336336
Mode: "R/W",
337337
Role: "HA",
338338
Status: innodb.InstanceStatusOnline,
339339
},
340-
"test-cluster-1.test-cluster:3306": &innodb.Instance{
340+
"test-cluster-1.test-cluster:3306": {
341341
Address: "test-cluster-1.test-cluster:3306",
342342
Mode: "R/O",
343343
Role: "HA",
344344
Status: innodb.InstanceStatusOnline,
345345
},
346-
"test-cluster-2.test-cluster:3306": &innodb.Instance{
346+
"test-cluster-2.test-cluster:3306": {
347347
Address: "test-cluster-2.test-cluster:3306",
348348
Mode: "R/O",
349349
Role: "HA",
@@ -366,7 +366,7 @@ func TestClusterLabelerDoesntRelabelCorrectlyLabeledPods(t *testing.T) {
366366

367367
func TestClusterLabelerRemovesLabelFromInstanceInMissingState(t *testing.T) {
368368
pods := []corev1.Pod{
369-
corev1.Pod{
369+
{
370370
TypeMeta: metav1.TypeMeta{
371371
APIVersion: "v1",
372372
Kind: "Pod",
@@ -380,7 +380,7 @@ func TestClusterLabelerRemovesLabelFromInstanceInMissingState(t *testing.T) {
380380
},
381381
},
382382
},
383-
corev1.Pod{
383+
{
384384
TypeMeta: metav1.TypeMeta{
385385
APIVersion: "v1",
386386
Kind: "Pod",
@@ -394,7 +394,7 @@ func TestClusterLabelerRemovesLabelFromInstanceInMissingState(t *testing.T) {
394394
},
395395
},
396396
},
397-
corev1.Pod{
397+
{
398398
TypeMeta: metav1.TypeMeta{
399399
APIVersion: "v1",
400400
Kind: "Pod",
@@ -417,19 +417,19 @@ func TestClusterLabelerRemovesLabelFromInstanceInMissingState(t *testing.T) {
417417
Status: "OK",
418418
StatusText: "Cluster is ONLINE and can tolerate up to ONE failure.",
419419
Topology: map[string]*innodb.Instance{
420-
"test-cluster-0.test-cluster:3306": &innodb.Instance{
420+
"test-cluster-0.test-cluster:3306": {
421421
Address: "test-cluster-0.test-cluster:3306",
422422
Mode: "R/W",
423423
Role: "HA",
424424
Status: innodb.InstanceStatusOnline,
425425
},
426-
"test-cluster-1.test-cluster:3306": &innodb.Instance{
426+
"test-cluster-1.test-cluster:3306": {
427427
Address: "test-cluster-1.test-cluster:3306",
428428
Mode: "R/O",
429429
Role: "HA",
430430
Status: innodb.InstanceStatusOnline,
431431
},
432-
"test-cluster-2.test-cluster:3306": &innodb.Instance{
432+
"test-cluster-2.test-cluster:3306": {
433433
Address: "test-cluster-2.test-cluster:3306",
434434
Mode: "R/O",
435435
Role: "HA",

pkg/resources/statefulsets/statefulset.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func mysqlServerContainer(cluster *v1alpha1.Cluster, mysqlServerImage string, ro
207207
// TODO(apryde): Add BaseImage to cluster CRD.
208208
Image: fmt.Sprintf("%s:%s", mysqlServerImage, cluster.Spec.Version),
209209
Ports: []v1.ContainerPort{
210-
v1.ContainerPort{
210+
{
211211
ContainerPort: 3306,
212212
},
213213
},
@@ -220,11 +220,11 @@ func mysqlServerContainer(cluster *v1alpha1.Cluster, mysqlServerImage string, ro
220220
replicationGroupSeedsEnvVar(replicationGroupSeeds),
221221
multiMasterEnvVar(cluster.Spec.MultiMaster),
222222
rootPassword,
223-
v1.EnvVar{
223+
{
224224
Name: "MYSQL_ROOT_HOST",
225225
Value: "%",
226226
},
227-
v1.EnvVar{
227+
{
228228
Name: "MYSQL_LOG_CONSOLE",
229229
Value: "true",
230230
},
@@ -252,7 +252,7 @@ func mysqlAgentContainer(cluster *v1alpha1.Cluster, mysqlAgentImage string, root
252252
replicationGroupSeedsEnvVar(replicationGroupSeeds),
253253
multiMasterEnvVar(cluster.Spec.MultiMaster),
254254
rootPassword,
255-
v1.EnvVar{
255+
{
256256
Name: "MY_POD_IP",
257257
ValueFrom: &v1.EnvVarSource{
258258
FieldRef: &v1.ObjectFieldSelector{
@@ -318,21 +318,21 @@ func NewForCluster(cluster *v1alpha1.Cluster, images operatoropts.Images, servic
318318
VolumeSource: v1.VolumeSource{
319319
Projected: &v1.ProjectedVolumeSource{
320320
Sources: []v1.VolumeProjection{
321-
v1.VolumeProjection{
321+
{
322322
Secret: &v1.SecretProjection{
323323
LocalObjectReference: v1.LocalObjectReference{
324324
Name: cluster.Spec.SSLSecret.Name,
325325
},
326326
Items: []v1.KeyToPath{
327-
v1.KeyToPath{
327+
{
328328
Key: "ca.crt",
329329
Path: "ca.crt",
330330
},
331-
v1.KeyToPath{
331+
{
332332
Key: "tls.crt",
333333
Path: "tls.crt",
334334
},
335-
v1.KeyToPath{
335+
{
336336
Key: "tls.key",
337337
Path: "tls.key",
338338
},

0 commit comments

Comments
 (0)