Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

phaniharsha avatar image
phaniharsha asked Erick Ramirez edited

Is it possible to add custom labels in CassandraDatacenter?

Hi All,
I have deployed Cassandra operator and trying to add custom labels in CassandraDatacenter yaml, where statefulset/Cassandra cluster should use those labels

can you help me in adding custom labels in example-cassdc-full.yaml .

https://github.com/datastax/cass-operator/blob/master/operator/example-cassdc-yaml/cassandra-3.11.x/example-cassdc-full.yaml

cass-operator
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

john.sanda_194109 avatar image
john.sanda_194109 answered phaniharsha commented

Hi @phaniharsha It is possible to do what you want using the .spec.podTemplateSpec property. Here is an example:

apiVersion: cassandra.datastax.com/v1beta1
kind: CassandraDatacenter
metadata:
  name: dc1
spec:
  clusterName: custom-labels-example
  serverType: cassandra
  serverVersion: "3.11.10"
  dockerImageRunsAsCassandra: true
  serverImage: datastax/cassandra-mgmtapi-3_11_10:v0.1.23
  managementApiAuth:
    insecure: {}
  size: 1
  storageConfig:
    cassandraDataVolumeClaimSpec:
      storageClassName: persistent-storage
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
  podTemplateSpec:
    metadata:
      labels:
        foo: bar

This will result in the label foo=bar being added to the pods in the StatefulSet.

The podTemplateSpec property is really powerful and flexible. It is powerful in that it allows you to override or custom define quite a bit.

It is flexible because it has merge behavior. In other words, you can add something for the cassandra container and cass-operator will merge that into the StatefulSet as opposed to just overwriting it.

I hope that helps :)

Cheers

John

5 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks for the response

I have tried adding labels under podTemplateSpec in CassandraDatacenter but no luck, labels are not being added to the pods in statefulset. am i missing something? can you please help me.

0 Likes 0 ·
  storageConfig:
    cassandraDataVolumeClaimSpec:
      storageClassName: {
  { .Values.cr.storageConfig.storageClassName }}
      accessModes:
        - {
  { .Values.cr.storageConfig.accessMode }}
      resources:
        requests:
          storage: {
  { .Values.cr.storageConfig.storage }}
  podTemplateSpec:
    metadata:
      labels:
        foo: bar



By describing pod result as follow:

1618215519283.png
By describing sts result as follow:
1618215599560.png


Thanks,
Phani

0 Likes 0 ·
1618215519283.png (31.6 KiB)
1618215599560.png (21.1 KiB)

Hi @phaniharsha

Is the code that you shared from a Helm chart template (or something similar)? Maybe it is not generating the CassandraDatacenter spec as expected. Let's see what it looks like. Can you please share the output of `kubectl get cassandradatacenter dc1 -o yaml`.

0 Likes 0 ·
Show more comments
Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez edited

Yes, you can add custom labels.

For example:

metadata:
  name: dc1
  labels:
    label_1: value_1
    label_2: value_2

Is this what you're after? If not, please let us know what outcome you're after or what problem you're trying to solve so we can provide a better answer. Cheers!

3 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Hi Eric, Thanks for the response.

I am trying to add some extra labels/custom labels in statefulset through Cassandradatacenter

I tried adding labels under metadata object in cassandradatacenter but same custom labels are not being taken by statefulset instead i am only seeing pre-defined labels or pods, my goal is, statefulset or pods should also take custom labels along with predefined labels.


Cassandradatacenter:

dc1:
1617883666114.png

1617883927596.png

Statefulset:


1617883647476.png

0 Likes 0 ·
1617883647476.png (30.8 KiB)
1617883666114.png (14.3 KiB)
1617883927596.png (131.5 KiB)

[Duplicate entry deleted]

0 Likes 0 ·

[Duplicate entry deleted]

0 Likes 0 ·