From 5c9aec6f18259dd6dc186b75241de21579939e76 Mon Sep 17 00:00:00 2001 From: Gleb Zimin Date: Tue, 28 Jan 2025 19:35:56 +0100 Subject: [PATCH] Fix issues with JMX configuration * make all fields as strings, in other cases boolean values with "false" skipped as zero value. * fix configuration name for jmx remote port --- api/v2/cassandracluster_types.go | 16 ++++++++-------- .../crds/db.orange.com_cassandraclusters.yaml | 16 ++++++++++++++++ .../crds/db.orange.com_cassandraclusters.yaml | 16 ++++++++++++++++ .../bases/db.orange.com_cassandraclusters.yaml | 16 ++++++++-------- controllers/cassandracluster/generator.go | 12 +++++++----- .../testdata/cassandracluster-2DC.yaml | 8 ++++---- 6 files changed, 59 insertions(+), 25 deletions(-) diff --git a/api/v2/cassandracluster_types.go b/api/v2/cassandracluster_types.go index 7adf5830..d2de981b 100644 --- a/api/v2/cassandracluster_types.go +++ b/api/v2/cassandracluster_types.go @@ -822,14 +822,14 @@ type CassandraClusterSpec struct { // JMXConfiguration defines Cassandra JMX variables configuration type JMXConfiguration struct { - // Flag to tell that JMX remote is enabled - // +kubebuilder:default:=false - JMXRemote bool `json:"jmxRemoteEnable,omitempty"` - // JMX Remote port number - // +kubebuilder:default:=7199 - JMXRemotePort int `json:"jmxRemotePort,omitempty"` - JXMRemoteSSL bool `json:"jmxRemoteSSL,omitempty"` - JMXRemoteAuthenticate bool `json:"jmxRemoteAuthenticate,omitempty"` + // JMXRemote defines is JMX remote enabled + JMXRemote string `json:"jmxRemoteEnable,omitempty"` + // JMXRemotePort defines the Remote Method Invocation port for the JMX connection + JMXRemotePort string `json:"jmxRemotePort,omitempty"` + // JXMRemoteSSL defines is SSL for JMX connections enabled or not + JXMRemoteSSL string `json:"jmxRemoteSSL,omitempty"` + // JMXRemoteAuthenticate defines authentication for JMX remote connections + JMXRemoteAuthenticate string `json:"jmxRemoteAuthenticate,omitempty"` } // StorageConfig defines additional storage configurations diff --git a/charts/casskop/crds/db.orange.com_cassandraclusters.yaml b/charts/casskop/crds/db.orange.com_cassandraclusters.yaml index 37e62972..757c34fc 100644 --- a/charts/casskop/crds/db.orange.com_cassandraclusters.yaml +++ b/charts/casskop/crds/db.orange.com_cassandraclusters.yaml @@ -236,6 +236,22 @@ spec: imagepullpolicy: description: ImagePullPolicy define the pull policy for C* docker image type: string + jmxConfiguration: + description: JMXConfiguration defines Cassandra JMX variables configuration + type: object + properties: + jmxRemoteAuthenticate: + description: JMXRemoteAuthenticate defines authentication for JMX remote connections + type: string + jmxRemoteEnable: + description: JMXRemote defines is JMX remote enabled + type: string + jmxRemotePort: + description: JMXRemotePort defines the Remote Method Invocation port for the JMX connection + type: string + jmxRemoteSSL: + description: JXMRemoteSSL defines is SSL for JMX connections enabled or not + type: string keyspaceCleanupThreads: description: |- Number of jobs (threads) for keyspace cleanup command. diff --git a/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml b/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml index 37e62972..757c34fc 100644 --- a/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml +++ b/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml @@ -236,6 +236,22 @@ spec: imagepullpolicy: description: ImagePullPolicy define the pull policy for C* docker image type: string + jmxConfiguration: + description: JMXConfiguration defines Cassandra JMX variables configuration + type: object + properties: + jmxRemoteAuthenticate: + description: JMXRemoteAuthenticate defines authentication for JMX remote connections + type: string + jmxRemoteEnable: + description: JMXRemote defines is JMX remote enabled + type: string + jmxRemotePort: + description: JMXRemotePort defines the Remote Method Invocation port for the JMX connection + type: string + jmxRemoteSSL: + description: JXMRemoteSSL defines is SSL for JMX connections enabled or not + type: string keyspaceCleanupThreads: description: |- Number of jobs (threads) for keyspace cleanup command. diff --git a/config/crd/bases/db.orange.com_cassandraclusters.yaml b/config/crd/bases/db.orange.com_cassandraclusters.yaml index 63e31663..757c34fc 100644 --- a/config/crd/bases/db.orange.com_cassandraclusters.yaml +++ b/config/crd/bases/db.orange.com_cassandraclusters.yaml @@ -241,17 +241,17 @@ spec: type: object properties: jmxRemoteAuthenticate: - type: boolean + description: JMXRemoteAuthenticate defines authentication for JMX remote connections + type: string jmxRemoteEnable: - description: Flag to tell that JMX remote is enabled - type: boolean - default: false + description: JMXRemote defines is JMX remote enabled + type: string jmxRemotePort: - description: JMX Remote port number - type: integer - default: 7199 + description: JMXRemotePort defines the Remote Method Invocation port for the JMX connection + type: string jmxRemoteSSL: - type: boolean + description: JXMRemoteSSL defines is SSL for JMX connections enabled or not + type: string keyspaceCleanupThreads: description: |- Number of jobs (threads) for keyspace cleanup command. diff --git a/controllers/cassandracluster/generator.go b/controllers/cassandracluster/generator.go index b5e1740d..c96cb4ee 100644 --- a/controllers/cassandracluster/generator.go +++ b/controllers/cassandracluster/generator.go @@ -82,7 +82,7 @@ const ( // Create a JMX Configuration map to convert values from CR to how they look like as env vars var JMXConfigurationMap = map[string]string{ "JMXRemote": "-Dcom.sun.management.jmxremote=", - "JMXRemotePort": "-Dcom.sun.management.jmxremote.port=", + "JMXRemotePort": "-Dcom.sun.management.jmxremote.rmi.port=", "JXMRemoteSSL": "-Dcom.sun.management.jmxremote.ssl=", "JMXRemoteAuthenticate": "-Dcom.sun.management.jmxremote.authenticate=", } @@ -310,10 +310,12 @@ func generateJMXConfiguration(jmxConf api.JMXConfiguration) v1.EnvVar { values := reflect.ValueOf(jmxConf) types := reflect.TypeOf(jmxConf) for i := 0; i < values.NumField(); i++ { - fieldName := types.Field(i).Name - fieldValue := values.Field(i).Interface() - param := JMXConfigurationMap[fieldName] + fmt.Sprintf("%v", fieldValue) + " " - jmxParam += param + fieldName := types.Field(i) + fieldValue := values.Field(i) + if fieldValue.String() != "" { + param := JMXConfigurationMap[fieldName.Name] + fieldValue.String() + " " + jmxParam += param + } } jmxEnvVar = v1.EnvVar{Name: jvmOptsName, Value: jmxParam} return jmxEnvVar diff --git a/controllers/cassandracluster/testdata/cassandracluster-2DC.yaml b/controllers/cassandracluster/testdata/cassandracluster-2DC.yaml index ae4ec185..bc92276e 100644 --- a/controllers/cassandracluster/testdata/cassandracluster-2DC.yaml +++ b/controllers/cassandracluster/testdata/cassandracluster-2DC.yaml @@ -32,10 +32,10 @@ spec: cassandraImage: cassandra:3.11.7 restartCountBeforePodDeletion: 3 jmxConfiguration: - jmxRemoteEnable: false - jmxRemotePort: 7199 - jmxRemoteSSL: false - jmxRemoteAuthenticate: false + jmxRemoteEnable: "false" + jmxRemotePort: "7199" + jmxRemoteSSL: "false" + jmxRemoteAuthenticate: "false" imagePullSecret: name: advisedev # To authenticate on docker registry rollingPartition: 0