WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4eeb258

Browse files
committed
Add ability to specify JMX variables
By default JMX security is disabled and accesible only from localhost. Add ability so specify JMX env variables. Change-Id: I209afc50406d83651b034b42ec3c5709b631ee0e
1 parent d287b4a commit 4eeb258

File tree

6 files changed

+88
-2
lines changed

6 files changed

+88
-2
lines changed

api/v2/cassandracluster_types.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,21 @@ type CassandraClusterSpec struct {
815815
// +optional
816816
ShareProcessNamespace *bool `json:"shareProcessNamespace,omitempty" protobuf:"varint,27,opt,name=shareProcessNamespace"`
817817

818-
BackRestSidecar *BackRestSidecar `json:"backRestSidecar,omitempty"`
819-
ServiceAccountName string `json:"serviceAccountName,omitempty"`
818+
BackRestSidecar *BackRestSidecar `json:"backRestSidecar,omitempty"`
819+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
820+
JMXConfiguration *JMXConfiguration `json:"jmxConfiguration,omitempty"`
821+
}
822+
823+
// JMXConfiguration defines Cassandra JMX variables configuration
824+
type JMXConfiguration struct {
825+
// Flag to tell that JMX remote is enabled
826+
// +kubebuilder:default:=false
827+
JMXRemote bool `json:"jmxRemoteEnable,omitempty"`
828+
// JMX Remote port number
829+
// +kubebuilder:default:=7199
830+
JMXRemotePort int `json:"jmxRemotePort,omitempty"`
831+
JXMRemoteSSL bool `json:"jmxRemoteSSL,omitempty"`
832+
JMXRemoteAuthenticate bool `json:"jmxRemoteAuthenticate,omitempty"`
820833
}
821834

822835
// StorageConfig defines additional storage configurations

api/v2/zz_generated.deepcopy.go

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

config/crd/bases/db.orange.com_cassandraclusters.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ spec:
236236
imagepullpolicy:
237237
description: ImagePullPolicy define the pull policy for C* docker image
238238
type: string
239+
jmxConfiguration:
240+
description: JMXConfiguration defines Cassandra JMX variables configuration
241+
type: object
242+
properties:
243+
jmxRemoteAuthenticate:
244+
type: boolean
245+
jmxRemoteEnable:
246+
description: Flag to tell that JMX remote is enabled
247+
type: boolean
248+
default: false
249+
jmxRemotePort:
250+
description: JMX Remote port number
251+
type: integer
252+
default: 7199
253+
jmxRemoteSSL:
254+
type: boolean
239255
keyspaceCleanupThreads:
240256
description: |-
241257
Number of jobs (threads) for keyspace cleanup command.

controllers/cassandracluster/generator.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cassandracluster
1717
import (
1818
"encoding/json"
1919
"fmt"
20+
"reflect"
2021

2122
"github.com/Jeffail/gabs"
2223
"github.com/banzaicloud/k8s-objectmatcher/patch"
@@ -65,6 +66,7 @@ const (
6566

6667
cassandraConfigMapName = "cassandra-config"
6768
defaultBackRestPort = 4567
69+
jvmOptsName = "JVM_OPTS"
6870
)
6971

7072
type containerType int
@@ -76,6 +78,15 @@ const (
7678
backrestContainer
7779
)
7880

81+
// JMXConfigurationMap
82+
// Create a JMX Configuration map to convert values from CR to how they look like as env vars
83+
var JMXConfigurationMap = map[string]string{
84+
"JMXRemote": "-Dcom.sun.management.jmxremote=",
85+
"JMXRemotePort": "-Dcom.sun.management.jmxremote.port=",
86+
"JXMRemoteSSL": "-Dcom.sun.management.jmxremote.ssl=",
87+
"JMXRemoteAuthenticate": "-Dcom.sun.management.jmxremote.authenticate=",
88+
}
89+
7990
type NodeConfig map[string]map[string]interface{}
8091

8192
func generateCassandraService(cc *api.CassandraCluster, labels map[string]string,
@@ -293,6 +304,21 @@ func generateVolumeClaimTemplate(cc *api.CassandraCluster, labels map[string]str
293304
return pvc, nil
294305
}
295306

307+
func generateJMXConfiguration(jmxConf api.JMXConfiguration) v1.EnvVar {
308+
var jmxEnvVar v1.EnvVar
309+
var jmxParam string
310+
values := reflect.ValueOf(jmxConf)
311+
types := reflect.TypeOf(jmxConf)
312+
for i := 0; i < values.NumField(); i++ {
313+
fieldName := types.Field(i).Name
314+
fieldValue := values.Field(i).Interface()
315+
param := JMXConfigurationMap[fieldName] + fmt.Sprintf("%v", fieldValue) + " "
316+
jmxParam += param
317+
}
318+
jmxEnvVar = v1.EnvVar{Name: jvmOptsName, Value: jmxParam}
319+
return jmxEnvVar
320+
}
321+
296322
func generateCassandraStatefulSet(cc *api.CassandraCluster, status *api.CassandraClusterStatus,
297323
dcName string, dcRackName string, labels map[string]string, nodeSelector map[string]string,
298324
ownerRefs []metav1.OwnerReference) (*appsv1.StatefulSet, error) {
@@ -932,6 +958,10 @@ func createCassandraContainer(cc *api.CassandraCluster, status *api.CassandraClu
932958
Value: "-Dcom.sun.jndi.rmiURLParsing=legacy",
933959
})
934960

961+
if cc.Spec.JMXConfiguration != nil {
962+
jmxEnvVariable := generateJMXConfiguration(*cc.Spec.JMXConfiguration)
963+
cassandraEnv = append(cassandraEnv, jmxEnvVariable)
964+
}
935965
cassandraContainer := v1.Container{
936966
Name: cassandraContainerName,
937967
Image: cc.Spec.CassandraImage,

controllers/cassandracluster/generator_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ func checkVarEnv(t *testing.T, containers []v1.Container, cc *api.CassandraClust
691691
cassieResources := cc.Spec.Resources
692692
initContainerEnvVar := initContainerEnvVar(cc, &cc.Status, cassieResources, dcRackName)
693693
bootstrapContainerEnvVar := bootstrapContainerEnvVar(cc, &cc.Status)
694+
jmxEnvVar := generateJMXConfiguration(*cc.Spec.JMXConfiguration)
694695

695696
assert := assert.New(t)
696697

@@ -755,6 +756,7 @@ func checkVarEnv(t *testing.T, containers []v1.Container, cc *api.CassandraClust
755756
},
756757
}
757758
assert.Contains(container.Env, podIP)
759+
assert.Contains(container.Env, jmxEnvVar)
758760

759761
checkInitContainerVarEnv(t, initContainerEnvVar, vars)
760762
}

controllers/cassandracluster/testdata/cassandracluster-2DC.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ spec:
3131
nodesPerRacks: 1
3232
cassandraImage: cassandra:3.11.7
3333
restartCountBeforePodDeletion: 3
34+
jmxConfiguration:
35+
jmxRemoteEnable: false
36+
jmxRemotePort: 7199
37+
jmxRemoteSSL: false
38+
jmxRemoteAuthenticate: false
3439
imagePullSecret:
3540
name: advisedev # To authenticate on docker registry
3641
rollingPartition: 0

0 commit comments

Comments
 (0)