Skip to content

Commit c02da40

Browse files
authored
Support for cassandra as matrics store (#6)
* Support for cassandra as matrics store * Update example * Shorten name
1 parent 2f9c111 commit c02da40

File tree

7 files changed

+280
-37
lines changed

7 files changed

+280
-37
lines changed

api/v1beta1/axonopscassandra_types.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type AxonOpsCassandraCluster struct {
6262
Image ContainerImage `json:"image,omitempty"`
6363
Replicas int `json:"replicas,omitempty"`
6464
ClusterName string `json:"clusterName,omitempty"`
65+
DC string `json:"dc,omitempty"`
6566
PersistentVolume PersistentVolumeSpec `json:"persistentVolume,omitempty"`
6667
JavaOpts string `json:"javaOpts,omitempty"`
6768
HeapSize string `json:"heapSize,omitempty"`
@@ -89,12 +90,14 @@ type AxonOpsDashboard struct {
8990
// AxonOpsServer defines the dashboard
9091
type AxonOpsServer struct {
9192
// Container image definition with repository and tag
92-
Image ContainerImage `json:"image,omitempty"`
93-
Annotations map[string]string `json:"annotations,omitempty"`
94-
Labels map[string]string `json:"labels,omitempty"`
95-
Env []EnvVars `json:"env,omitempty"`
96-
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
97-
PullPolicy string `json:"pullPolicy,omitempty"`
93+
Image ContainerImage `json:"image,omitempty"`
94+
Annotations map[string]string `json:"annotations,omitempty"`
95+
Labels map[string]string `json:"labels,omitempty"`
96+
Env []EnvVars `json:"env,omitempty"`
97+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
98+
PullPolicy string `json:"pullPolicy,omitempty"`
99+
CassandraMetricsEnabled bool `json:"cassandraMetricsEnabled,omitempty"`
100+
CassandraMetricsCluster AxonOpsCassandraCluster `json:"cassandraMetricsCluster,omitempty"`
98101
}
99102

100103
// AxonOpsServer defines the dashboard

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/axon-server.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ type ServerConfig struct {
155155
}
156156

157157
func GenerateServerConfig(cfg cassandraaxonopscomv1beta1.AxonOpsCassandra) (*appsv1.StatefulSet, error) {
158+
if cfg.Spec.AxonOps.Server.CassandraMetricsEnabled {
159+
cfg.Spec.AxonOps.Server.Env = append(cfg.Spec.AxonOps.Server.Env, cassandraaxonopscomv1beta1.EnvVars{
160+
Name: "CQL_HOSTS",
161+
Value: "ca-metrics-" + cfg.GetName(),
162+
})
163+
cfg.Spec.AxonOps.Server.Env = append(cfg.Spec.AxonOps.Server.Env, cassandraaxonopscomv1beta1.EnvVars{
164+
Name: "CQL_LOCAL_DC",
165+
Value: "axonops1",
166+
})
167+
}
158168
config := ServerConfig{
159169
Name: cfg.GetName(),
160170
Namespace: cfg.GetNamespace(),

apps/cassandra.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ spec:
163163
- name: CASSANDRA_ENDPOINT_SNITCH
164164
value: GossipingPropertyFileSnitch
165165
- name: CASSANDRA_DC
166-
value: dc1
166+
value: {{ .DC }}
167167
- name: CASSANDRA_RACK
168168
value: rack1
169169
- name: CASSANDRA_BROADCAST_RPC_ADDRESS
@@ -279,6 +279,7 @@ type CassandraConfig struct {
279279
Replicas int
280280
Image string
281281
ClusterName string
282+
DC string
282283
JavaOpts string
283284
HeapSize string
284285
StorageSize string
@@ -293,28 +294,29 @@ type CassandraConfig struct {
293294
PullPolicy string
294295
}
295296

296-
func GenerateCassandraConfig(cfg cassandraaxonopscomv1beta1.AxonOpsCassandra) (*appsv1.StatefulSet, error) {
297+
func GenerateCassandraConfig(name string, namespace string, storageSize string, storageClass string, cfg cassandraaxonopscomv1beta1.AxonOpsCassandraCluster) (*appsv1.StatefulSet, error) {
297298
config := CassandraConfig{
298-
Name: cfg.GetName(),
299-
Namespace: cfg.GetNamespace(),
300-
Replicas: utils.ValueOrDefaultInt(cfg.Spec.Cassandra.Replicas, 1),
299+
Name: name,
300+
Namespace: namespace,
301+
Replicas: utils.ValueOrDefaultInt(cfg.Replicas, 1),
301302
Image: fmt.Sprintf("%s:%s",
302-
utils.ValueOrDefault(cfg.Spec.Cassandra.Image.Repository, defaultCassandraImage),
303-
utils.ValueOrDefault(cfg.Spec.Cassandra.Image.Tag, defaultCassandraTag),
303+
utils.ValueOrDefault(cfg.Image.Repository, defaultCassandraImage),
304+
utils.ValueOrDefault(cfg.Image.Tag, defaultCassandraTag),
304305
),
305-
ClusterName: utils.ValueOrDefault(cfg.Spec.Cassandra.ClusterName, cfg.GetName()),
306-
JavaOpts: utils.ValueOrDefault(cfg.Spec.Cassandra.JavaOpts, "-Xms512m -Xmx512m"),
307-
StorageSize: utils.ValueOrDefault(cfg.Spec.AxonOps.Elasticsearch.PersistentVolume.Size, ""),
308-
StorageClass: utils.ValueOrDefault(cfg.Spec.AxonOps.Elasticsearch.PersistentVolume.StorageClass, ""),
309-
HeapSize: utils.ValueOrDefault(cfg.Spec.Cassandra.HeapSize, "512M"),
310-
Labels: cfg.Spec.Cassandra.Labels,
311-
Annotations: cfg.Spec.Cassandra.Annotations,
312-
Env: cfg.Spec.Cassandra.Env,
313-
CpuRequest: utils.ValueOrDefault(cfg.Spec.Cassandra.Resources.Requests.Cpu().String(), "500m"),
314-
MemoryRequest: utils.ValueOrDefault(cfg.Spec.Cassandra.Resources.Requests.Memory().String(), "1Gi"),
315-
CpuLimit: utils.ValueOrDefault(cfg.Spec.Cassandra.Resources.Limits.Cpu().String(), "1000m"),
316-
MemoryLimit: utils.ValueOrDefault(cfg.Spec.Cassandra.Resources.Limits.Memory().String(), "2Gi"),
317-
PullPolicy: utils.ValueOrDefault(cfg.Spec.Cassandra.PullPolicy, "IfNotPresent"),
306+
ClusterName: utils.ValueOrDefault(cfg.ClusterName, name),
307+
DC: utils.ValueOrDefault(cfg.DC, "dc1"),
308+
JavaOpts: utils.ValueOrDefault(cfg.JavaOpts, "-Xms512m -Xmx512m"),
309+
StorageSize: utils.ValueOrDefault(storageSize, ""),
310+
StorageClass: utils.ValueOrDefault(storageClass, ""),
311+
HeapSize: utils.ValueOrDefault(cfg.HeapSize, "512M"),
312+
Labels: cfg.Labels,
313+
Annotations: cfg.Annotations,
314+
Env: cfg.Env,
315+
CpuRequest: utils.ValueOrDefault(cfg.Resources.Requests.Cpu().String(), "500m"),
316+
MemoryRequest: utils.ValueOrDefault(cfg.Resources.Requests.Memory().String(), "1Gi"),
317+
CpuLimit: utils.ValueOrDefault(cfg.Resources.Limits.Cpu().String(), "1000m"),
318+
MemoryLimit: utils.ValueOrDefault(cfg.Resources.Limits.Memory().String(), "2Gi"),
319+
PullPolicy: utils.ValueOrDefault(cfg.PullPolicy, "IfNotPresent"),
318320
}
319321

320322
statefulSet := &appsv1.StatefulSet{}
@@ -342,12 +344,12 @@ func GenerateCassandraConfig(cfg cassandraaxonopscomv1beta1.AxonOpsCassandra) (*
342344
return statefulSet, nil
343345
}
344346

345-
func GenerateCassandraServiceConfig(cfg cassandraaxonopscomv1beta1.AxonOpsCassandra) (*corev1.Service, error) {
347+
func GenerateCassandraServiceConfig(name string, namespace string, labels map[string]string, annonations map[string]string) (*corev1.Service, error) {
346348
config := CassandraServiceConfig{
347-
Name: cfg.GetName(),
348-
Namespace: cfg.GetNamespace(),
349-
Labels: cfg.Spec.Cassandra.Labels,
350-
Annotations: cfg.Spec.Cassandra.Annotations,
349+
Name: name,
350+
Namespace: namespace,
351+
Labels: labels,
352+
Annotations: annonations,
351353
}
352354

353355
svc := &corev1.Service{}
@@ -380,8 +382,8 @@ func GenerateCassandraHeadlessServiceConfig(cfg cassandraaxonopscomv1beta1.AxonO
380382
config := CassandraServiceConfig{
381383
Name: cfg.GetName(),
382384
Namespace: cfg.GetNamespace(),
383-
Labels: cfg.Spec.Cassandra.Labels,
384-
Annotations: cfg.Spec.Cassandra.Annotations,
385+
Labels: cfg.Labels,
386+
Annotations: cfg.Annotations,
385387
}
386388

387389
svc := &corev1.Service{}

config/crd/bases/axonops.com_axonopscassandras.yaml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,121 @@ spec:
300300
additionalProperties:
301301
type: string
302302
type: object
303+
cassandraMetricsCluster:
304+
description: AxonOpsCassandraCluster defines the Apache Cassandra
305+
cluster to install
306+
properties:
307+
annotations:
308+
additionalProperties:
309+
type: string
310+
type: object
311+
clusterName:
312+
type: string
313+
dc:
314+
type: string
315+
env:
316+
items:
317+
description: EnvVars lists the environmetn variables
318+
to add to the deployment or statefulset
319+
properties:
320+
name:
321+
description: Environment variable name
322+
type: string
323+
value:
324+
description: Environment variable value
325+
type: string
326+
type: object
327+
type: array
328+
heapSize:
329+
type: string
330+
image:
331+
properties:
332+
repository:
333+
type: string
334+
tag:
335+
type: string
336+
type: object
337+
javaOpts:
338+
type: string
339+
labels:
340+
additionalProperties:
341+
type: string
342+
type: object
343+
persistentVolume:
344+
description: PersistentVolumeSpec defines the persistent
345+
volume specification
346+
properties:
347+
size:
348+
description: Storage size
349+
type: string
350+
storageClass:
351+
description: Optional Storage Class name
352+
type: string
353+
type: object
354+
pullPolicy:
355+
type: string
356+
replicas:
357+
type: integer
358+
resources:
359+
description: ResourceRequirements describes the compute
360+
resource requirements.
361+
properties:
362+
claims:
363+
description: |-
364+
Claims lists the names of resources, defined in spec.resourceClaims,
365+
that are used by this container.
366+
367+
368+
This is an alpha field and requires enabling the
369+
DynamicResourceAllocation feature gate.
370+
371+
372+
This field is immutable. It can only be set for containers.
373+
items:
374+
description: ResourceClaim references one entry
375+
in PodSpec.ResourceClaims.
376+
properties:
377+
name:
378+
description: |-
379+
Name must match the name of one entry in pod.spec.resourceClaims of
380+
the Pod where this field is used. It makes that resource available
381+
inside a container.
382+
type: string
383+
required:
384+
- name
385+
type: object
386+
type: array
387+
x-kubernetes-list-map-keys:
388+
- name
389+
x-kubernetes-list-type: map
390+
limits:
391+
additionalProperties:
392+
anyOf:
393+
- type: integer
394+
- type: string
395+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
396+
x-kubernetes-int-or-string: true
397+
description: |-
398+
Limits describes the maximum amount of compute resources allowed.
399+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
400+
type: object
401+
requests:
402+
additionalProperties:
403+
anyOf:
404+
- type: integer
405+
- type: string
406+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
407+
x-kubernetes-int-or-string: true
408+
description: |-
409+
Requests describes the minimum amount of compute resources required.
410+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
411+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
412+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
413+
type: object
414+
type: object
415+
type: object
416+
cassandraMetricsEnabled:
417+
type: boolean
303418
env:
304419
items:
305420
description: EnvVars lists the environmetn variables to
@@ -399,6 +514,8 @@ spec:
399514
type: object
400515
clusterName:
401516
type: string
517+
dc:
518+
type: string
402519
env:
403520
items:
404521
description: EnvVars lists the environmetn variables to add
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: axonops.com/v1beta1
2+
kind: AxonOpsCassandra
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: axonops-developer-operator
6+
app.kubernetes.io/managed-by: kustomize
7+
name: axonopscassandra-sample
8+
namespace: axonops-dev
9+
spec:
10+
cassandra:
11+
replicas: 1
12+
clusterName: "my-dev-env"
13+
axonops:
14+
elasticsearch:
15+
persistentVolume:
16+
size: 2Gi
17+
storageClass: local-path
18+
server:
19+
cassandraMetricsEnabled: true
20+
cassandraMetricsCluster:
21+
replicas: 2
22+
dc: axonops2
23+
persistentVolume:
24+
size: 2Gi
25+
storageClass: local-path

0 commit comments

Comments
 (0)