Skip to content

Commit d24957a

Browse files
committed
testing: strategy and instrumentation
1 parent e897661 commit d24957a

File tree

7 files changed

+353
-0
lines changed

7 files changed

+353
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/tarantool/tarantool-operator
22

33
require (
4+
github.com/ghodss/yaml v1.0.0
45
github.com/go-openapi/spec v0.19.0
56
github.com/google/uuid v1.1.1
67
github.com/machinebox/graphql v0.2.2

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ github.com/Azure/go-autorest v11.1.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSW
1515
github.com/Azure/go-autorest v11.5.2+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
1616
github.com/Azure/go-autorest v11.7.0+incompatible h1:gzma19dc9ejB75D90E5S+/wXouzpZyA+CV+/MJPSD/k=
1717
github.com/Azure/go-autorest v11.7.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
18+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
1819
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
1920
github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
2021
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
@@ -80,6 +81,7 @@ github.com/emicklei/go-restful v2.9.3+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT
8081
github.com/emicklei/go-restful-swagger12 v0.0.0-20170926063155-7524189396c6/go.mod h1:qr0VowGBT4CS4Q8vFF8BSeKz34PuqKGxs/L0IAQA9DQ=
8182
github.com/evanphx/json-patch v3.0.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
8283
github.com/evanphx/json-patch v4.0.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
84+
github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=
8385
github.com/evanphx/json-patch v4.1.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
8486
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
8587
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
@@ -197,6 +199,7 @@ github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
197199
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
198200
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
199201
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
202+
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
200203
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
201204
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
202205
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
@@ -212,6 +215,7 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
212215
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
213216
github.com/konsorten/go-windows-terminal-sequences v0.0.0-20180402223658-b729f2633dfe/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
214217
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
218+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
215219
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
216220
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
217221
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -236,6 +240,7 @@ github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsO
236240
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
237241
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
238242
github.com/maxbrunsfeld/counterfeiter v0.0.0-20181017030959-1aadac120687/go.mod h1:aoVsckWnsNzazwF2kmD+bzgdr4GBlbK91zsdivQJ2eU=
243+
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
239244
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
240245
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
241246
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
@@ -314,12 +319,14 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm
314319
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
315320
github.com/sirupsen/logrus v1.1.1/go.mod h1:zrgwTnHtNr00buQ1vSptGe8m1f/BbgsPukg8qsT7A+A=
316321
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
322+
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
317323
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
318324
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
319325
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
320326
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
321327
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
322328
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
329+
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
323330
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
324331
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
325332
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=

test/e2e/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Tarantool Operator end-2-end tests
2+
3+
Testing strategy:
4+
5+
1. provision kubernetes resources from YAML manifest
6+
7+
1. act on provisioned resources
8+
9+
1. assert expected system state
10+
11+
1. clean up
12+
13+
Some conventions:
14+
15+
1. setup manifests located under `scenario` dir
16+
17+
1. tests must be independent and no reliance on previous tests allowed
18+
19+
1. tests must be able to run in parallel each test in it's own namespace
20+
21+
1. each setup manifest must be written in a way that allows to use it without tests

test/e2e/main_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package e2e
2+
3+
import (
4+
"testing"
5+
6+
f "github.com/operator-framework/operator-sdk/pkg/test"
7+
)
8+
9+
func TestMain(m *testing.M) {
10+
f.MainEntry(m)
11+
}

test/e2e/scenario/basic.yaml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
apiVersion: tarantool.io/v1alpha1
2+
kind: Cluster
3+
metadata:
4+
name: examples-kv-cluster
5+
spec:
6+
selector:
7+
matchLabels:
8+
tarantool.io/cluster-id: "examples-kv-cluster"
9+
---
10+
apiVersion: tarantool.io/v1alpha1
11+
kind: Role
12+
metadata:
13+
name: storage
14+
namespace: default
15+
labels:
16+
tarantool.io/cluster-id: "examples-kv-cluster"
17+
tarantool.io/role: "storage"
18+
spec:
19+
selector:
20+
matchLabels:
21+
tarantool.io/replicaset-template: "storage-template"
22+
numReplicasets: 1
23+
---
24+
apiVersion: tarantool.io/v1alpha1
25+
kind: Role
26+
metadata:
27+
name: routers
28+
namespace: default
29+
labels:
30+
tarantool.io/cluster-id: "examples-kv-cluster"
31+
tarantool.io/role: "router"
32+
spec:
33+
selector:
34+
matchLabels:
35+
tarantool.io/replicaset-template: "router-template"
36+
numReplicasets: 1
37+
---
38+
apiVersion: tarantool.io/v1alpha1
39+
kind: ReplicasetTemplate
40+
metadata:
41+
name: storage-template
42+
labels:
43+
tarantool.io/cluster-id: "examples-kv-cluster"
44+
tarantool.io/replicaset-template: "storage-template"
45+
tarantool.io/role: "storage"
46+
spec:
47+
replicas: 1
48+
selector:
49+
matchLabels:
50+
tarantool.io/pod-template: "storage-pod-template"
51+
volumeClaimTemplates:
52+
- metadata:
53+
name: www
54+
spec:
55+
accessModes: [ "ReadWriteOnce" ]
56+
resources:
57+
requests:
58+
storage: 1Gi
59+
template:
60+
metadata:
61+
labels:
62+
tarantool.io/cluster-id: "examples-kv-cluster"
63+
tarantool.io/pod-template: "storage-pod-template"
64+
spec:
65+
terminationGracePeriodSeconds: 10
66+
dnsConfig:
67+
options:
68+
- name: ndots
69+
value: "1"
70+
containers:
71+
- name: pim-storage
72+
image: tarantool/tarantool-operator-examples-kv:0.0.2
73+
volumeMounts:
74+
- mountPath: "/var/lib/tarantool"
75+
name: www
76+
ports:
77+
- containerPort: 3301
78+
- containerPort: 8081
79+
env:
80+
- name: TARANTOOL_INSTANCE_NAME
81+
valueFrom:
82+
fieldRef:
83+
fieldPath: metadata.name
84+
- name: TARANTOOL_WORK_DIR
85+
value: "/var/lib/tarantool"
86+
- name: TARANTOOL_MEMTX_MEMORY
87+
value: "33554432"
88+
- name: TARANTOOL_LOG
89+
value: "/dev/stdout"
90+
- name: TARANTOOL_ADVERTISE_HOST
91+
valueFrom:
92+
fieldRef:
93+
fieldPath: metadata.name
94+
- name: TARANTOOL_ADVERTISE_URI
95+
value: "$(TARANTOOL_ADVERTISE_HOST).examples-kv-cluster:3301"
96+
---
97+
apiVersion: tarantool.io/v1alpha1
98+
kind: ReplicasetTemplate
99+
metadata:
100+
name: router-template
101+
labels:
102+
tarantool.io/cluster-id: "examples-kv-cluster"
103+
tarantool.io/replicaset-template: "router-template"
104+
tarantool.io/role: "router"
105+
spec:
106+
replicas: 1
107+
selector:
108+
matchLabels:
109+
tarantool.io/pod-template: "router-pod-template"
110+
volumeClaimTemplates:
111+
- metadata:
112+
name: www
113+
spec:
114+
accessModes: [ "ReadWriteOnce" ]
115+
resources:
116+
requests:
117+
storage: 1Gi
118+
template:
119+
metadata:
120+
labels:
121+
tarantool.io/cluster-id: "examples-kv-cluster"
122+
tarantool.io/pod-template: "router-pod-template"
123+
spec:
124+
terminationGracePeriodSeconds: 10
125+
dnsConfig:
126+
options:
127+
- name: ndots
128+
value: "1"
129+
containers:
130+
- name: pim-router
131+
image: tarantool/tarantool-operator-examples-kv:0.0.2
132+
volumeMounts:
133+
- mountPath: "/var/lib/tarantool"
134+
name: www
135+
ports:
136+
- containerPort: 3301
137+
- containerPort: 8081
138+
env:
139+
- name: TARANTOOL_INSTANCE_NAME
140+
valueFrom:
141+
fieldRef:
142+
fieldPath: metadata.name
143+
- name: TARANTOOL_WORK_DIR
144+
value: "/var/lib/tarantool"
145+
- name: TARANTOOL_MEMTX_MEMORY
146+
value: "33554432"
147+
- name: TARANTOOL_LOG
148+
value: "/dev/stdout"
149+
- name: TARANTOOL_ADVERTISE_HOST
150+
valueFrom:
151+
fieldRef:
152+
fieldPath: metadata.name
153+
- name: TARANTOOL_ADVERTISE_URI
154+
value: "$(TARANTOOL_ADVERTISE_HOST).examples-kv-cluster:3301"
155+
---
156+
apiVersion: networking.k8s.io/v1beta1
157+
kind: Ingress
158+
metadata:
159+
name: examples-kv-topology
160+
annotations:
161+
nginx.ingress.kubernetes.io/ssl-redirect: "false"
162+
spec:
163+
rules:
164+
- http:
165+
paths:
166+
- backend:
167+
serviceName: router
168+
servicePort: 8081
169+
path: /kv
170+
- backend:
171+
serviceName: router
172+
servicePort: 8081
173+
path: /kv_dump
174+
- backend:
175+
serviceName: router
176+
servicePort: 8081
177+
path: /
178+
---
179+
apiVersion: v1
180+
kind: Service
181+
metadata:
182+
name: router
183+
labels:
184+
tarantool.io/role: "router"
185+
spec:
186+
ports:
187+
- port: 8081
188+
name: web
189+
protocol: TCP
190+
selector:
191+
tarantool.io/role: "router"

test/e2e/simple_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package e2e
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
framework "github.com/operator-framework/operator-sdk/pkg/test"
8+
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
9+
apierrors "k8s.io/apimachinery/pkg/api/errors"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/util/wait"
12+
)
13+
14+
func TestOperatorMustCreateStatefulSetPerCartridgeRole(t *testing.T) {
15+
ctx := framework.NewTestCtx(t)
16+
defer ctx.Cleanup()
17+
18+
clenupOpts := &framework.CleanupOptions{
19+
TestContext: ctx,
20+
Timeout: time.Second * 60,
21+
RetryInterval: time.Second * 1,
22+
}
23+
if err := ctx.InitializeClusterResources(clenupOpts); err != nil {
24+
t.Fatalf("failed to initialize cluster resources: %v", err)
25+
}
26+
t.Log("Initialized cluster resources")
27+
28+
namespace, err := ctx.GetNamespace()
29+
if err != nil {
30+
t.Fatalf("failed to get namespace %s", err)
31+
}
32+
33+
kubeClient := framework.Global.KubeClient
34+
err = e2eutil.WaitForOperatorDeployment(t, kubeClient, namespace, "tarantool-operator", 1, time.Second*1, time.Second*60)
35+
if err != nil {
36+
t.Fatalf("failed to deploy operator %s", err)
37+
}
38+
39+
if err = InitializeScenario(ctx, "basic"); err != nil {
40+
t.Fatalf("failed to initialize scenario %s", err)
41+
}
42+
43+
expectedRoles := 2
44+
err = wait.Poll(time.Second*1, time.Second*60, func() (done bool, err error) {
45+
sts, err := kubeClient.AppsV1().StatefulSets(namespace).List(metav1.ListOptions{})
46+
if err != nil {
47+
if apierrors.IsNotFound(err) {
48+
return false, nil
49+
}
50+
return false, err
51+
}
52+
53+
if len(sts.Items) == expectedRoles {
54+
return true, nil
55+
}
56+
57+
return false, nil
58+
})
59+
if err != nil {
60+
t.Fatal(err)
61+
}
62+
}

0 commit comments

Comments
 (0)