Skip to content

Commit 3dd7b51

Browse files
committed
Add an optional field in KafkaCluster resource to specify cruise control reporter image
Previously the same CruiseControl.Image field was used for both cruise-control server image version but also kafka pod metrics reporter image In the case only the cruise-control server version needs to be updated and avoid a kafka cluster rolling restart, `ClusterMetricsReporterImage` or `BrokerConfig.MetricsReporterImage` can be kept and only the CruiseControl.Image upgraded
1 parent 44d0e3b commit 3dd7b51

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

api/v1beta1/kafkacluster_types.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ type KafkaClusterSpec struct {
5656
ZKAddresses []string `json:"zkAddresses"`
5757
// ZKPath specifies the ZooKeeper chroot path as part
5858
// of its ZooKeeper connection string which puts its data under some path in the global ZooKeeper namespace.
59-
ZKPath string `json:"zkPath,omitempty"`
60-
RackAwareness *RackAwareness `json:"rackAwareness,omitempty"`
61-
ClusterImage string `json:"clusterImage,omitempty"`
62-
ReadOnlyConfig string `json:"readOnlyConfig,omitempty"`
63-
ClusterWideConfig string `json:"clusterWideConfig,omitempty"`
64-
BrokerConfigGroups map[string]BrokerConfig `json:"brokerConfigGroups,omitempty"`
65-
Brokers []Broker `json:"brokers"`
66-
DisruptionBudget DisruptionBudget `json:"disruptionBudget,omitempty"`
67-
RollingUpgradeConfig RollingUpgradeConfig `json:"rollingUpgradeConfig"`
59+
ZKPath string `json:"zkPath,omitempty"`
60+
RackAwareness *RackAwareness `json:"rackAwareness,omitempty"`
61+
ClusterImage string `json:"clusterImage,omitempty"`
62+
ClusterMetricsReporterImage string `json:"clusterMetricsReporterImage,omitempty"`
63+
ReadOnlyConfig string `json:"readOnlyConfig,omitempty"`
64+
ClusterWideConfig string `json:"clusterWideConfig,omitempty"`
65+
BrokerConfigGroups map[string]BrokerConfig `json:"brokerConfigGroups,omitempty"`
66+
Brokers []Broker `json:"brokers"`
67+
DisruptionBudget DisruptionBudget `json:"disruptionBudget,omitempty"`
68+
RollingUpgradeConfig RollingUpgradeConfig `json:"rollingUpgradeConfig"`
6869
// +kubebuilder:validation:Enum=envoy;istioingress
6970
IngressController string `json:"ingressController,omitempty"`
7071
// If true OneBrokerPerNode ensures that each kafka broker will be placed on a different node unless a custom
@@ -133,16 +134,17 @@ type Broker struct {
133134

134135
// BrokerConfig defines the broker configuration
135136
type BrokerConfig struct {
136-
Image string `json:"image,omitempty"`
137-
Config string `json:"config,omitempty"`
138-
StorageConfigs []StorageConfig `json:"storageConfigs,omitempty"`
139-
ServiceAccountName string `json:"serviceAccountName,omitempty"`
140-
Resources *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
141-
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
142-
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
143-
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
144-
KafkaHeapOpts string `json:"kafkaHeapOpts,omitempty"`
145-
KafkaJVMPerfOpts string `json:"kafkaJvmPerfOpts,omitempty"`
137+
Image string `json:"image,omitempty"`
138+
MetricsReporterImage string `json:"metricsReporterImage,omitempty"`
139+
Config string `json:"config,omitempty"`
140+
StorageConfigs []StorageConfig `json:"storageConfigs,omitempty"`
141+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
142+
Resources *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
143+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
144+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
145+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
146+
KafkaHeapOpts string `json:"kafkaHeapOpts,omitempty"`
147+
KafkaJVMPerfOpts string `json:"kafkaJvmPerfOpts,omitempty"`
146148
// Override for the default log4j configuration
147149
Log4jConfig string `json:"log4jConfig,omitempty"`
148150
// Custom annotations for the broker pods - e.g.: Prometheus scraping annotations:
@@ -586,6 +588,14 @@ func (kSpec *KafkaClusterSpec) GetClusterImage() string {
586588
return "ghcr.io/banzaicloud/kafka:2.13-2.8.1"
587589
}
588590

591+
// GetClusterMetricsReporterImage returns the default container image for Kafka Cluster
592+
func (kSpec *KafkaClusterSpec) GetClusterMetricsReporterImage() string {
593+
if kSpec.ClusterMetricsReporterImage != "" {
594+
return kSpec.ClusterMetricsReporterImage
595+
}
596+
return kSpec.CruiseControlConfig.GetCCImage()
597+
}
598+
589599
func (cTaskSpec *CruiseControlTaskSpec) GetDurationMinutes() float64 {
590600
if cTaskSpec.RetryDurationMinutes == 0 {
591601
return 5

charts/kafka-operator/templates/crds.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,6 +3520,8 @@ spec:
35203520
log4jConfig:
35213521
description: Override for the default log4j configuration
35223522
type: string
3523+
metricsReporterImage:
3524+
type: string
35233525
networkConfig:
35243526
description: Network throughput information in kB/s used by
35253527
Cruise Control to determine broker network capacity. By default
@@ -9359,6 +9361,8 @@ spec:
93599361
log4jConfig:
93609362
description: Override for the default log4j configuration
93619363
type: string
9364+
metricsReporterImage:
9365+
type: string
93629366
networkConfig:
93639367
description: Network throughput information in kB/s used
93649368
by Cruise Control to determine broker network capacity.
@@ -11690,6 +11694,8 @@ spec:
1169011694
type: array
1169111695
clusterImage:
1169211696
type: string
11697+
clusterMetricsReporterImage:
11698+
type: string
1169311699
clusterWideConfig:
1169411700
type: string
1169511701
cruiseControlConfig:

config/base/crds/kafka.banzaicloud.io_kafkaclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,6 +3519,8 @@ spec:
35193519
log4jConfig:
35203520
description: Override for the default log4j configuration
35213521
type: string
3522+
metricsReporterImage:
3523+
type: string
35223524
networkConfig:
35233525
description: Network throughput information in kB/s used by
35243526
Cruise Control to determine broker network capacity. By default
@@ -9358,6 +9360,8 @@ spec:
93589360
log4jConfig:
93599361
description: Override for the default log4j configuration
93609362
type: string
9363+
metricsReporterImage:
9364+
type: string
93619365
networkConfig:
93629366
description: Network throughput information in kB/s used
93639367
by Cruise Control to determine broker network capacity.
@@ -11689,6 +11693,8 @@ spec:
1168911693
type: array
1169011694
clusterImage:
1169111695
type: string
11696+
clusterMetricsReporterImage:
11697+
type: string
1169211698
clusterWideConfig:
1169311699
type: string
1169411700
cruiseControlConfig:

pkg/resources/kafka/pod.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ rm /var/run/wait/do-not-exit-yet`}
108108
),
109109
Spec: corev1.PodSpec{
110110
SecurityContext: brokerConfig.PodSecurityContext,
111-
InitContainers: getInitContainers(brokerConfig.InitContainers, r.KafkaCluster.Spec),
111+
InitContainers: getInitContainers(brokerConfig, r.KafkaCluster.Spec),
112112
Affinity: getAffinity(brokerConfig, r.KafkaCluster),
113113
Containers: append([]corev1.Container{
114114
{
@@ -181,14 +181,14 @@ fi`},
181181
return pod
182182
}
183183

184-
func getInitContainers(brokerConfigInitContainers []corev1.Container, kafkaClusterSpec v1beta1.KafkaClusterSpec) []corev1.Container {
185-
initContainers := make([]corev1.Container, 0, len(brokerConfigInitContainers))
186-
initContainers = append(initContainers, brokerConfigInitContainers...)
184+
func getInitContainers(brokerConfig *v1beta1.BrokerConfig, kafkaClusterSpec v1beta1.KafkaClusterSpec) []corev1.Container {
185+
initContainers := make([]corev1.Container, 0, len(brokerConfig.InitContainers))
186+
initContainers = append(initContainers, brokerConfig.InitContainers...)
187187

188188
initContainers = append(initContainers, []corev1.Container{
189189
{
190190
Name: "cruise-control-reporter",
191-
Image: kafkaClusterSpec.CruiseControlConfig.GetCCImage(),
191+
Image: util.GetBrokerMetricsReporterImage(brokerConfig, kafkaClusterSpec),
192192
Command: []string{"/bin/sh", "-cex", "cp -v /opt/cruise-control/cruise-control/build/dependant-libs/cruise-control-metrics-reporter.jar /opt/kafka/libs/extensions/cruise-control-metrics-reporter.jar"},
193193
VolumeMounts: []corev1.VolumeMount{{
194194
Name: "extensions",

pkg/util/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ func GetBrokerImage(brokerConfig *v1beta1.BrokerConfig, clusterImage string) str
326326
return clusterImage
327327
}
328328

329+
// GetBrokerMetricsReporterImage returns the image used for cruise-control metrics reporter
330+
func GetBrokerMetricsReporterImage(brokerConfig *v1beta1.BrokerConfig, kafkaClusterSpec v1beta1.KafkaClusterSpec) string {
331+
if brokerConfig.MetricsReporterImage != "" {
332+
return brokerConfig.MetricsReporterImage
333+
}
334+
return kafkaClusterSpec.GetClusterMetricsReporterImage()
335+
}
336+
329337
// getRandomString returns a random string containing uppercase, lowercase and number characters with the length given
330338
func GetRandomString(length int) (string, error) {
331339
rand.Seed(time.Now().UnixNano())

0 commit comments

Comments
 (0)