Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with JMX configuration #164

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions api/v2/cassandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
if len(cc.Status.Phase) == 0 {
cc.Status.Phase = ClusterPhaseInitial.Name
if cc.InitCassandraRackList() < 1 {
logrus.Errorf("[%s]: We should have at list One Rack, Please correct the Error", cc.Name)

Check failure on line 175 in api/v2/cassandracluster_types.go

View workflow job for this annotation

GitHub Actions / lint

cc.Name undefined (type *CassandraCluster has no field or method Name) (typecheck)
}
if cc.Status.SeedList == nil {
cc.Status.SeedList = cc.InitSeedList()
Expand Down Expand Up @@ -822,14 +822,16 @@

// 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
Loading