Skip to content

Commit 933b8da

Browse files
committed
helm charts: make crud chart for deploy ready to use app
1 parent 476ddeb commit 933b8da

18 files changed

+426
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111
- Support custom cluster domain name via variable `ClusterDomainName` in cartrige chart `values.yaml`
12+
- New chart for deploying ready-to-use crud based application

charts/crud/Chart.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v2
2+
appVersion: "1.0"
3+
description: A Helm chart for Tarantool CRUD
4+
name: crud-storage
5+
version: 0.0.1
6+
dependencies:
7+
- name: tarantool-operator
8+
version: "0.0.7"
9+
repository: "https://tarantool.github.io/tarantool-operator"
10+
- name: cartridge
11+
version: "0.0.7"
12+
repository: "https://tarantool.github.io/tarantool-operator"

charts/crud/README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# CRUD base ready-to-use application
2+
3+
## Deploy
4+
5+
Run `helm install`:
6+
7+
```shell
8+
$ helm install crud-app ./charts/crud/ --namespace tarantool --create-namespace
9+
---
10+
NAME: crud-app
11+
LAST DEPLOYED: Wed Dec 2 15:58:11 2020
12+
NAMESPACE: tarantool
13+
STATUS: deployed
14+
REVISION: 1
15+
```
16+
17+
Check pods:
18+
19+
```shell
20+
$ kubectl -n tarantool get pods
21+
---
22+
NAME READY STATUS RESTARTS AGE
23+
crud-0-0 1/1 Running 0 2m28s
24+
crud-0-1 1/1 Running 0 119s
25+
crud-1-0 1/1 Running 0 2m28s
26+
crud-1-1 1/1 Running 0 2m10s
27+
tarantool-operator-644f487f87-4cqlv 1/1 Running 0 2m31s
28+
```
29+
30+
## Schema creation
31+
32+
Go to Cartridge webUI
33+
34+
```shell
35+
$ kubectl -n tarantool port-forward crud-0-0 8081:8081
36+
```
37+
38+
Add new migration file `migrations/source/000_bootstrap.lua` on code page and apply configuration:
39+
40+
![](https://i.imgur.com/6PMZ5Ui.png)
41+
42+
```lua
43+
return {
44+
up = function()
45+
local utils = require('migrator.utils')
46+
local s = box.schema.create_space('customer', {
47+
format = {
48+
{ name = 'id', type = 'number' },
49+
{ name = 'name', type = 'string' },
50+
{ name = 'age', type = 'number' },
51+
{ name = 'bucket_id', type = 'unsigned' },
52+
},
53+
if_not_exists = true,
54+
})
55+
s:create_index('primary', {
56+
parts = { 'key' },
57+
if_not_exists = true,
58+
})
59+
s:create_index('bucket_id', {
60+
parts = { 'bucket_id' },
61+
if_not_exists = true,
62+
unique = false
63+
})
64+
utils.register_sharding_key('customer', {'bucket_id'})
65+
return true
66+
end
67+
}
68+
```
69+
70+
And apply migration:
71+
```shell
72+
$ curl --header "Content-Type: application/json" \
73+
--request POST \
74+
--data '{}' \
75+
http://localhost:8081/migrations/up
76+
---
77+
{"applied":["000_bootstrap.lua"]}
78+
```
79+
80+
## Using
81+
82+
Connect to any instance:
83+
84+
```shell
85+
$ kubectl -n tarantool exec -it crud-0-0 -- /bin/bash
86+
```
87+
```shell
88+
bash-4.4$ tarantoolctl connect admin:crud-app-cluster-cookie@localhost:3301
89+
connected to localhost:3301
90+
```
91+
92+
Try insert objects:
93+
94+
```shell
95+
localhost:3301> crud.insert('customer', {0, "Ivan", 22, box.NULL})
96+
---
97+
- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'},
98+
{'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}]
99+
rows:
100+
- [0, 'Ivan', 22, 18560]
101+
...
102+
103+
localhost:3301> crud.insert('customer', {1, "Artem", 21, box.NULL})
104+
---
105+
- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'},
106+
{'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}]
107+
rows:
108+
- [1, 'Artem', 21, 12477]
109+
...
110+
111+
localhost:3301> crud.insert('customer', {2, "Denis", 20, box.NULL})
112+
---
113+
- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'},
114+
{'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}]
115+
rows:
116+
- [2, 'Denis', 20, 21401]
117+
...
118+
```
119+
120+
And execute simple select:
121+
122+
```shell
123+
localhost:3301> crud.select('customer', {{'>=', 'age', 21}})
124+
---
125+
- metadata: [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'},
126+
{'name': 'age', 'type': 'number'}, {'name': 'bucket_id', 'type': 'unsigned'}]
127+
rows:
128+
- [0, 'Ivan', 22, 18560]
129+
- [1, 'Artem', 21, 12477]
130+
...
131+
```
132+
133+
## Customization
134+
135+
By default the cluster contains two replicasets of two nodes (master - replica). If you want to change this configuration, you must describe it in the file `crud_values.yaml`
136+
137+
For example:
138+
```yaml
139+
cartridge:
140+
RoleConfig:
141+
- RoleName: crud
142+
ReplicaCount: 2
143+
ReplicaSetCount: 5
144+
DiskSize: 1Gi
145+
CPUallocation: 0.25
146+
MemtxMemoryMB: 256
147+
RolesToAssign:
148+
- crud-storage
149+
- crud-router
150+
- migrator
151+
- metrics
152+
```
153+
And pass this values to `helm install`:
154+
155+
```shell
156+
$ helm install crud-app -f crud_values.yaml ./charts/crud/ --namespace tarantool --create-namespace
157+
```
158+
159+
**NOTE** - all specified fields are required. Look at [this](https://github.com/tarantool/tarantool-operator/issues/44) ticket.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Simple Dockerfile
2+
# Used by "pack" command as a base for build image
3+
# when --use-docker option is specified
4+
#
5+
# The base image must be centos:8
6+
FROM centos:8
7+
8+
# Here you can install some packages required
9+
# for your application build
10+
#
11+
# RUN set -x \
12+
# && curl -sL https://rpm.nodesource.com/setup_10.x | bash - \
13+
# && yum -y install nodejs
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Simple Dockerfile
2+
# Used by "pack docker" command as a base for runtime image
3+
#
4+
# The base image must be centos:8
5+
FROM centos:8
6+
7+
# Here you can install some packages required
8+
# for your application in runtime
9+
#
10+
#
11+
# For example, if you need to install some python packages,
12+
# you can do it this way:
13+
#
14+
# COPY requirements.txt /tmp
15+
# RUN yum install -y python3-pip
16+
# RUN pip3 install -r /tmp/requirements.txt
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# Simple post-build script
4+
# Will be ran after "tarantoolctl rocks make" on application packing
5+
# Could be useful to remove some build artifacts from result package
6+
7+
# For example:
8+
# rm -rf third_party
9+
# rm -rf node_modules
10+
# rm -rf doc
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# Simple pre-build script
4+
# Will be ran before "tarantoolctl rocks make" on application build
5+
# Could be useful to install non-standart rocks modules
6+
7+
# For example:
8+
# tarantoolctl rocks make --chdir ./third_party/my-custom-rock-module
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package = 'crud-app'
2+
version = 'scm-1'
3+
source = {
4+
url = '/dev/null',
5+
}
6+
-- Put any modules your app depends on here
7+
dependencies = {
8+
'tarantool',
9+
'lua >= 5.1',
10+
'checks == 3.0.1-1',
11+
'cartridge == 2.3.0-1',
12+
'metrics == 0.5.0-1',
13+
'crud >= 0.1.0-1',
14+
'migrations == 0.3.1-1',
15+
}
16+
build = {
17+
type = 'none';
18+
}

charts/crud/crud-app/deps.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
# Call this script to install test dependencies
3+
4+
set -e
5+
6+
# Test dependencies:
7+
tarantoolctl rocks install luatest 0.5.0
8+
tarantoolctl rocks install luacov 0.13.0
9+
tarantoolctl rocks install luacheck 0.25.0

charts/crud/crud-app/init.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env tarantool
2+
3+
require('strict').on()
4+
5+
if package.setsearchroot ~= nil then
6+
package.setsearchroot()
7+
else
8+
-- Workaround for rocks loading in tarantool 1.10
9+
-- It can be removed in tarantool > 2.2
10+
-- By default, when you do require('mymodule'), tarantool looks into
11+
-- the current working directory and whatever is specified in
12+
-- package.path and package.cpath. If you run your app while in the
13+
-- root directory of that app, everything goes fine, but if you try to
14+
-- start your app with "tarantool myapp/init.lua", it will fail to load
15+
-- its modules, and modules from myapp/.rocks.
16+
local fio = require('fio')
17+
local app_dir = fio.abspath(fio.dirname(arg[0]))
18+
print('App dir set to ' .. app_dir)
19+
package.path = app_dir .. '/?.lua;' .. package.path
20+
package.path = app_dir .. '/?/init.lua;' .. package.path
21+
package.path = app_dir .. '/.rocks/share/tarantool/?.lua;' .. package.path
22+
package.path = app_dir .. '/.rocks/share/tarantool/?/init.lua;' .. package.path
23+
package.cpath = app_dir .. '/?.so;' .. package.cpath
24+
package.cpath = app_dir .. '/?.dylib;' .. package.cpath
25+
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.so;' .. package.cpath
26+
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.dylib;' .. package.cpath
27+
end
28+
29+
local cartridge = require('cartridge')
30+
31+
local ok, err = cartridge.cfg({
32+
roles = {
33+
'cartridge.roles.vshard-storage',
34+
'cartridge.roles.vshard-router',
35+
'cartridge.roles.metrics',
36+
'cartridge.roles.crud-router',
37+
'cartridge.roles.crud-storage',
38+
'migrator',
39+
},
40+
cluster_cookie = 'crud-app-cluster-cookie',
41+
})
42+
43+
assert(ok, tostring(err))
44+
45+
local migrator = require('migrator')
46+
migrator.set_loader(require('migrator.config-loader').new())

0 commit comments

Comments
 (0)