Skip to content

Commit 9e3dcee

Browse files
committed
CI: add lint and unit test stages
1 parent 933b8da commit 9e3dcee

File tree

5 files changed

+29
-46
lines changed

5 files changed

+29
-46
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
name: Test
22
on: [push]
3+
34
jobs:
4-
build:
5+
lint:
6+
name: lint
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- name: lint
12+
uses: golangci/golangci-lint-action@v2
13+
14+
unit_testing:
515
name: Build
616
runs-on: ubuntu-latest
17+
needs: lint
718
env:
819
OPERATOR_SDK_VERSION: v0.12.0
920
steps:
@@ -19,31 +30,5 @@ jobs:
1930
- name: Install modules
2031
run: go mod download
2132

22-
- name: Install operator-sdk
23-
run: |
24-
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu
25-
chmod +x ./operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu
26-
27-
- name: Build operator
28-
run: ./operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu build tarantool/tarantool-operator:${GITHUB_SHA}
29-
30-
- name: Setup test kubernetes cluster
31-
uses: helm/kind-action@v1.0.0-rc.1
32-
with:
33-
cluster_name: kind
34-
35-
- name: Load operator image into test cluster
36-
run: kind load docker-image tarantool/tarantool-operator:${GITHUB_SHA}
37-
38-
- name: Create CRDs
39-
run: |
40-
kubectl create \
41-
-f deploy/crds/tarantool_v1alpha1_cluster_crd.yaml \
42-
-f deploy/crds/tarantool_v1alpha1_replicasettemplate_crd.yaml \
43-
-f deploy/crds/tarantool_v1alpha1_role_crd.yaml
44-
4533
- name: Test
46-
run: |
47-
./operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu test local \
48-
--image tarantool/tarantool-operator:${GITHUB_SHA} \
49-
./test/e2e
34+
run: go test ./pkg/...

pkg/controller/cluster/cluster_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func (r *ReconcileCluster) Reconcile(request reconcile.Request) (reconcile.Resul
340340

341341
for _, sts := range stsList.Items {
342342
stsAnnotations := sts.GetAnnotations()
343-
weight, _ := stsAnnotations["tarantool.io/replicaset-weight"]
343+
weight := stsAnnotations["tarantool.io/replicaset-weight"]
344344

345345
if weight == "0" {
346346
reqLogger.Info("weight is set to 0, checking replicaset buckets for scheduled deletion")
@@ -384,7 +384,7 @@ func (r *ReconcileCluster) Reconcile(request reconcile.Request) (reconcile.Resul
384384
return reconcile.Result{RequeueAfter: time.Duration(5 * time.Second)}, err
385385
}
386386

387-
if tarantool.IsJoined(pod) == false {
387+
if !tarantool.IsJoined(pod) {
388388
reqLogger.Info("Not all instances joined, skip weight change", "StatefulSet.Name", sts.GetName())
389389
return reconcile.Result{RequeueAfter: time.Duration(5 * time.Second)}, nil
390390
}
@@ -421,7 +421,10 @@ func (r *ReconcileCluster) Reconcile(request reconcile.Request) (reconcile.Resul
421421
reqLogger.Info("Added bootstrapped annotation", "StatefulSet.Name", sts.GetName())
422422

423423
cluster.Status.State = "Ready"
424-
r.client.Status().Update(context.TODO(), cluster)
424+
err = r.client.Status().Update(context.TODO(), cluster)
425+
if err != nil {
426+
return reconcile.Result{RequeueAfter: time.Duration(5 * time.Second)}, err
427+
}
425428
return reconcile.Result{RequeueAfter: time.Duration(5 * time.Second)}, nil
426429
}
427430

pkg/controller/role/role_controller.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
goerrors "errors"
8-
97
"github.com/google/uuid"
108
tarantoolv1alpha1 "github.com/tarantool/tarantool-operator/pkg/apis/tarantool/v1alpha1"
119
appsv1 "k8s.io/api/apps/v1"
@@ -102,6 +100,10 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
102100
}),
103101
})
104102

103+
if err != nil {
104+
return err
105+
}
106+
105107
return nil
106108
}
107109

@@ -137,7 +139,7 @@ func (r *ReconcileRole) Reconcile(request reconcile.Request) (reconcile.Result,
137139
}
138140

139141
if len(role.GetOwnerReferences()) == 0 {
140-
return reconcile.Result{}, goerrors.New(fmt.Sprintf("Orphan role %s", role.GetName()))
142+
return reconcile.Result{}, fmt.Errorf("Orphan role %s", role.GetName())
141143
}
142144

143145
templateSelector, err := metav1.LabelSelectorAsSelector(role.Spec.Selector)
@@ -193,7 +195,7 @@ func (r *ReconcileRole) Reconcile(request reconcile.Request) (reconcile.Result,
193195
}
194196

195197
if len(templateList.Items) == 0 {
196-
return reconcile.Result{}, goerrors.New("no template")
198+
return reconcile.Result{}, fmt.Errorf("no template")
197199
}
198200

199201
template := templateList.Items[0]

pkg/topology/builtin.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ type BootstrapVshardResponse struct {
5555

5656
// FailoverData Structure of data for changing failover status
5757
type FailoverData struct {
58-
failover *FailoverParams `json:"failover_params"`
59-
}
60-
61-
// FailoverParams returns the mode of failover which has been enabled
62-
type FailoverParams struct {
63-
mode string `json:"mode"`
6458
}
6559

6660
// FailoverResponse type struct for returning on failovers
@@ -256,7 +250,7 @@ func (s *BuiltInTopologyService) Join(pod *corev1.Pod) error {
256250
return err
257251
}
258252

259-
if resp.JoinInstance == true {
253+
if resp.JoinInstance {
260254
return nil
261255
}
262256

@@ -294,7 +288,7 @@ func (s *BuiltInTopologyService) Expel(pod *corev1.Pod) error {
294288
return err
295289
}
296290

297-
if resp.Data.ExpelInstance == false && (resp.Errors == nil || len(resp.Errors) == 0) {
291+
if !resp.Data.ExpelInstance && (resp.Errors == nil || len(resp.Errors) == 0) {
298292
return errors.New("something really bad happened")
299293
}
300294

@@ -323,7 +317,7 @@ func (s *BuiltInTopologyService) SetWeight(replicasetUUID string, replicaWeight
323317
return err
324318
}
325319

326-
if resp.Response == true {
320+
if resp.Response {
327321
return nil
328322
}
329323

@@ -353,7 +347,7 @@ func (s *BuiltInTopologyService) BootstrapVshard() error {
353347

354348
reqLogger.Info("Bootstrapping vshard")
355349

356-
req := fmt.Sprint("mutation bootstrap {bootstrapVshardResponse: bootstrap_vshard}")
350+
req := "mutation bootstrap {bootstrapVshardResponse: bootstrap_vshard}"
357351
j := fmt.Sprintf("{\"query\": \"%s\"}", req)
358352
rawResp, err := http.Post(s.serviceHost, "application/json", strings.NewReader(j))
359353
if err != nil {

test/e2e/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func InitializeScenario(ctx *framework.TestCtx, name string) error {
3232
for {
3333
b, err := dec.Read()
3434
if err != nil {
35-
fmt.Errorf("%s", err)
3635
if err == io.EOF {
3736
break
3837
}

0 commit comments

Comments
 (0)