Skip to content

Commit

Permalink
Merge pull request #164 from gzimin/dev
Browse files Browse the repository at this point in the history
Fix issues with JMX configuration
  • Loading branch information
cscetbon authored Feb 4, 2025
2 parents 0747760 + 09921a6 commit e3587af
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 23 deletions.
18 changes: 10 additions & 8 deletions api/v2/cassandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,16 @@ 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 *bool `json:"jmxRemoteEnable,omitempty"`
// JMXRemotePort defines port that the JMX agent will use to listen for incoming JMX connections
JMXRemotePort int `json:"jmxRemotePort,omitempty"`
// JXMRemoteRmiPort defines Remote Method Invocation port for the JMX connection
JMXRemoteRmiPort int `json:"jmxRemoteRmiPort,omitempty"`
// JXMRemoteSSL defines is SSL for JMX connections enabled or not
JXMRemoteSSL *bool `json:"jmxRemoteSSL,omitempty"`
// JMXRemoteAuthenticate defines authentication for JMX remote connections
JMXRemoteAuthenticate *bool `json:"jmxRemoteAuthenticate,omitempty"`
}

// StorageConfig defines additional storage configurations
Expand Down
17 changes: 16 additions & 1 deletion api/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions charts/casskop/crds/db.orange.com_cassandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,25 @@ 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: boolean
jmxRemoteEnable:
description: JMXRemote defines is JMX remote enabled
type: boolean
jmxRemotePort:
description: JMXRemotePort defines port that the JMX agent will use to listen for incoming JMX connections
type: integer
jmxRemoteRmiPort:
description: JXMRemoteRmiPort defines Remote Method Invocation port for the JMX connection
type: integer
jmxRemoteSSL:
description: JXMRemoteSSL defines is SSL for JMX connections enabled or not
type: boolean
keyspaceCleanupThreads:
description: |-
Number of jobs (threads) for keyspace cleanup command.
Expand Down
19 changes: 19 additions & 0 deletions charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,25 @@ 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: boolean
jmxRemoteEnable:
description: JMXRemote defines is JMX remote enabled
type: boolean
jmxRemotePort:
description: JMXRemotePort defines port that the JMX agent will use to listen for incoming JMX connections
type: integer
jmxRemoteRmiPort:
description: JXMRemoteRmiPort defines Remote Method Invocation port for the JMX connection
type: integer
jmxRemoteSSL:
description: JXMRemoteSSL defines is SSL for JMX connections enabled or not
type: boolean
keyspaceCleanupThreads:
description: |-
Number of jobs (threads) for keyspace cleanup command.
Expand Down
11 changes: 7 additions & 4 deletions config/crd/bases/db.orange.com_cassandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,19 @@ spec:
type: object
properties:
jmxRemoteAuthenticate:
description: JMXRemoteAuthenticate defines authentication for JMX remote connections
type: boolean
jmxRemoteEnable:
description: Flag to tell that JMX remote is enabled
description: JMXRemote defines is JMX remote enabled
type: boolean
default: false
jmxRemotePort:
description: JMX Remote port number
description: JMXRemotePort defines port that the JMX agent will use to listen for incoming JMX connections
type: integer
jmxRemoteRmiPort:
description: JXMRemoteRmiPort defines Remote Method Invocation port for the JMX connection
type: integer
default: 7199
jmxRemoteSSL:
description: JXMRemoteSSL defines is SSL for JMX connections enabled or not
type: boolean
keyspaceCleanupThreads:
description: |-
Expand Down
28 changes: 18 additions & 10 deletions controllers/cassandracluster/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package cassandracluster
import (
"encoding/json"
"fmt"
"reflect"

"github.com/Jeffail/gabs"
"github.com/banzaicloud/k8s-objectmatcher/patch"

Expand Down Expand Up @@ -83,6 +81,7 @@ const (
var JMXConfigurationMap = map[string]string{
"JMXRemote": "-Dcom.sun.management.jmxremote=",
"JMXRemotePort": "-Dcom.sun.management.jmxremote.port=",
"JMXRemoteRmiPort": "-Dcom.sun.management.jmxremote.rmi.port=",
"JXMRemoteSSL": "-Dcom.sun.management.jmxremote.ssl=",
"JMXRemoteAuthenticate": "-Dcom.sun.management.jmxremote.authenticate=",
}
Expand Down Expand Up @@ -307,13 +306,20 @@ func generateVolumeClaimTemplate(cc *api.CassandraCluster, labels map[string]str
func generateJMXConfiguration(jmxConf api.JMXConfiguration) v1.EnvVar {
var jmxEnvVar v1.EnvVar
var jmxParam string
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
if jmxConf.JMXRemote != nil {
jmxParam += JMXConfigurationMap["JMXRemote"] + strconv.FormatBool(*jmxConf.JMXRemote) + " "
}
if jmxConf.JXMRemoteSSL != nil {
jmxParam += JMXConfigurationMap["JXMRemoteSSL"] + strconv.FormatBool(*jmxConf.JXMRemoteSSL) + " "
}
if jmxConf.JMXRemoteAuthenticate != nil {
jmxParam += JMXConfigurationMap["JMXRemoteAuthenticate"] + strconv.FormatBool(*jmxConf.JMXRemoteAuthenticate) + " "
}
if jmxConf.JMXRemotePort != 0 {
jmxParam += JMXConfigurationMap["JMXRemotePort"] + strconv.Itoa(jmxConf.JMXRemotePort) + " "
}
if jmxConf.JMXRemoteRmiPort != 0 {
jmxParam += JMXConfigurationMap["JMXRemoteRmiPort"] + strconv.Itoa(jmxConf.JMXRemoteRmiPort) + " "
}
jmxEnvVar = v1.EnvVar{Name: jvmOptsName, Value: jmxParam}
return jmxEnvVar
Expand Down Expand Up @@ -960,7 +966,9 @@ func createCassandraContainer(cc *api.CassandraCluster, status *api.CassandraClu

if cc.Spec.JMXConfiguration != nil {
jmxEnvVariable := generateJMXConfiguration(*cc.Spec.JMXConfiguration)
cassandraEnv = append(cassandraEnv, jmxEnvVariable)
if jmxEnvVariable.Value != "" {
cassandraEnv = append(cassandraEnv, jmxEnvVariable)
}
}
cassandraContainer := v1.Container{
Name: cassandraContainerName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:
jmxConfiguration:
jmxRemoteEnable: false
jmxRemotePort: 7199
jmxRemoteRmiPort: 7199
jmxRemoteSSL: false
jmxRemoteAuthenticate: false
imagePullSecret:
Expand Down

0 comments on commit e3587af

Please sign in to comment.