Skip to content

Commit 69cd011

Browse files
Merge pull request #3 from tegridy-io/feat/create-databases
Support creating databases from component
2 parents 6a85f41 + 816f9ff commit 69cd011

20 files changed

+2464
-8
lines changed

.cruft.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"template": "https://github.com/projectsyn/commodore-component-template.git",
3-
"commit": "73f964d1a9b834a772169d1ffe2b4406f90b2472",
3+
"commit": "dcae06138d227340acb8056d0d031f32d75c09b5",
44
"checkout": "main",
55
"context": {
66
"cookiecutter": {
77
"name": "CockroachDB Operator",
88
"slug": "cockroach-operator",
99
"parameter_key": "cockroach_operator",
10-
"test_cases": "defaults",
10+
"test_cases": "defaults create-db",
1111
"add_lib": "n",
1212
"add_pp": "n",
1313
"add_golden": "y",

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fetch-depth: "0"
1414
- name: Build changelog from PRs with labels
1515
id: build_changelog
16-
uses: mikepenz/release-changelog-builder-action@v3
16+
uses: mikepenz/release-changelog-builder-action@v4
1717
with:
1818
configuration: ".github/changelog-configuration.json"
1919
# PreReleases still get a changelog, but the next full release gets a diff since the last full release,

.github/workflows/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
matrix:
3434
instance:
3535
- defaults
36+
- create-db
3637
defaults:
3738
run:
3839
working-directory: ${{ env.COMPONENT_NAME }}
@@ -48,6 +49,7 @@ jobs:
4849
matrix:
4950
instance:
5051
- defaults
52+
- create-db
5153
defaults:
5254
run:
5355
working-directory: ${{ env.COMPONENT_NAME }}

Makefile.vars.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ YAMLLINT_CONFIG ?= .yamllint.yml
3434
YAMLLINT_IMAGE ?= docker.io/cytopia/yamllint:latest
3535
YAMLLINT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) $(YAMLLINT_IMAGE)
3636

37-
VALE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --volume "$${PWD}"/docs/modules:/pages docker.io/vshn/vale:2.1.1
37+
VALE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --volume "$${PWD}"/docs/modules:/pages ghcr.io/vshn/vale:2.15.5
3838
VALE_ARGS ?= --minAlertLevel=error --config=/pages/ROOT/pages/.vale.ini /pages
3939

40-
ANTORA_PREVIEW_CMD ?= $(DOCKER_CMD) run --rm --publish 35729:35729 --publish 2020:2020 $(antora_git_volume) --volume "${PWD}/docs":/preview/antora/docs docker.io/vshn/antora-preview:3.0.1.1 --style=syn --antora=docs
40+
ANTORA_PREVIEW_CMD ?= $(DOCKER_CMD) run --rm --publish 35729:35729 --publish 2020:2020 $(antora_git_volume) --volume "${PWD}/docs":/preview/antora/docs ghcr.io/vshn/antora-preview:3.1.2.3 --style=syn --antora=docs
4141

4242
COMMODORE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(git_volume) $(root_volume) docker.io/projectsyn/commodore:latest
4343
COMPILE_CMD ?= $(COMMODORE_CMD) component compile . $(commodore_args)
@@ -50,4 +50,4 @@ KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
5050
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)
5151

5252
instance ?= defaults
53-
test_instances = tests/defaults.yml
53+
test_instances = tests/defaults.yml tests/create-db.yml

class/defaults.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ parameters:
1111
operator:
1212
registry: docker.io
1313
repository: cockroachdb/cockroach-operator
14-
tag: v2.10.0
14+
tag: v2.11.0
15+
cockroach:
16+
registry: docker.io
17+
repository: cockroachdb/cockroach
18+
tag: v23.1.8
19+
20+
databases: {}

component/main.jsonnet

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,114 @@ local inv = kap.inventory();
55
// The hiera parameters for the component
66
local params = inv.parameters.cockroach_operator;
77

8+
local database(name) = [
9+
// namespace
10+
kube.Namespace(params.databases[name].namespace),
11+
// database
12+
kube._Object('crdb.cockroachlabs.com/v1alpha1', 'CrdbCluster', name + '-database') {
13+
assert params.databases[name].nodes >= 3 : 'Parameter nodes should be >= 3.',
14+
metadata+: {
15+
labels+: {
16+
'app.kubernetes.io/component': 'database',
17+
'app.kubernetes.io/managed-by': 'commodore',
18+
'app.kubernetes.io/name': name + '-database',
19+
},
20+
namespace: params.databases[name].namespace,
21+
},
22+
spec+: {
23+
nodes: params.databases[name].nodes,
24+
image: {
25+
name: '%(registry)s/%(repository)s:%(tag)s' % params.images.cockroach,
26+
pullPolicy: 'IfNotPresent',
27+
},
28+
tlsEnabled: true,
29+
dataStore: {
30+
pvc: {
31+
spec: {
32+
accessModes: [ params.databases[name].storage.accessMode ],
33+
storageClassName: params.databases[name].storage.storageClass,
34+
resources: {
35+
requests: { storage: params.databases[name].storage.size },
36+
},
37+
volumeMode: 'Filesystem',
38+
},
39+
},
40+
},
41+
affinity: {
42+
podAntiAffinity: {
43+
requiredDuringSchedulingIgnoredDuringExecution: [
44+
{
45+
labelSelector: {
46+
matchExpressions: [
47+
{
48+
key: 'app.kubernetes.io/name',
49+
operator: 'In',
50+
values: [ name + '-database' ],
51+
},
52+
],
53+
},
54+
topologyKey: 'kubernetes.io/hostname',
55+
},
56+
],
57+
},
58+
},
59+
},
60+
},
61+
// client
62+
kube.Deployment(name + '-database-client') {
63+
metadata+: {
64+
labels+: {
65+
'app.kubernetes.io/component': 'client',
66+
'app.kubernetes.io/managed-by': 'commodore',
67+
'app.kubernetes.io/name': name + '-database-client',
68+
},
69+
namespace: params.databases[name].namespace,
70+
},
71+
spec+: {
72+
replicas: 1,
73+
template+: {
74+
spec+: {
75+
serviceAccountName: 'default',
76+
securityContext: {
77+
seccompProfile: { type: 'RuntimeDefault' },
78+
},
79+
containers_:: {
80+
default: kube.Container('client') {
81+
image: '%(registry)s/%(repository)s:%(tag)s' % params.images.cockroach,
82+
env_:: {
83+
COCKROACH_CERTS_DIR: '/cockroach/certs-dir',
84+
COCKROACH_HOST: name + '-database-public',
85+
},
86+
command: [ 'sleep', 'infinity' ],
87+
securityContext: {
88+
allowPrivilegeEscalation: false,
89+
capabilities: { drop: [ 'ALL' ] },
90+
},
91+
volumeMounts_:: {
92+
certs: { mountPath: '/cockroach/certs-dir' },
93+
},
94+
},
95+
},
96+
volumes_:: {
97+
certs: {
98+
secret: {
99+
secretName: name + '-database-root',
100+
items: [
101+
{ key: 'ca.crt', path: 'ca.crt' },
102+
{ key: 'tls.crt', path: 'client.root.crt' },
103+
{ key: 'tls.key', path: 'client.root.key' },
104+
],
105+
},
106+
},
107+
},
108+
},
109+
},
110+
},
111+
},
112+
];
113+
8114
// Define outputs below
9115
{
116+
['20_db_' + name]: database(name)
117+
for name in std.objectFields(params.databases)
10118
}

docs/modules/ROOT/pages/.vale.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Vale config

tests/create-db.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
cockroach_operator:
3+
databases:
4+
apps:
5+
namespace: app-database
6+
nodes: 3
7+
storage:
8+
accessMode: ReadWriteOnce
9+
storageClass: ''
10+
size: 5Gi

tests/golden/create-db/cockroach-operator/apps/cockroach-operator.yaml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: MutatingWebhookConfiguration
3+
metadata:
4+
creationTimestamp: null
5+
name: cockroach-operator-mutating-webhook-configuration
6+
webhooks:
7+
- admissionReviewVersions:
8+
- v1
9+
clientConfig:
10+
service:
11+
name: cockroach-operator-webhook-service
12+
namespace: syn-cockroach-operator
13+
path: /mutate-crdb-cockroachlabs-com-v1alpha1-crdbcluster
14+
failurePolicy: Fail
15+
name: mcrdbcluster.kb.io
16+
rules:
17+
- apiGroups:
18+
- crdb.cockroachlabs.com
19+
apiVersions:
20+
- v1alpha1
21+
operations:
22+
- CREATE
23+
- UPDATE
24+
resources:
25+
- crdbclusters
26+
sideEffects: None

0 commit comments

Comments
 (0)