Skip to content

Commit b58c6fc

Browse files
committed
Add additional labels to brokers for backward compatibility while performing migration
1 parent 9446f00 commit b58c6fc

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

api/v1beta1/kafkacluster_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,13 +1102,18 @@ func (bConfig *BrokerConfig) GetBrokerAnnotations() map[string]string {
11021102

11031103
// GetBrokerLabels returns the labels that are applied to broker pods
11041104
func (bConfig *BrokerConfig) GetBrokerLabels(kafkaClusterName string, brokerId int32, kRaftMode bool) map[string]string {
1105-
kraftLabels := make(map[string]string, 0)
1105+
var kraftLabels map[string]string
11061106
if kRaftMode {
11071107
kraftLabels = map[string]string{
11081108
ProcessRolesKey: strings.Join(bConfig.Roles, "_"),
11091109
IsControllerNodeKey: fmt.Sprintf("%t", bConfig.IsControllerNode()),
11101110
IsBrokerNodeKey: fmt.Sprintf("%t", bConfig.IsBrokerNode()),
11111111
}
1112+
} else { // in ZK mode -> new labels for backward compatibility for the headless service when going from ZK to KRaft
1113+
kraftLabels = map[string]string{
1114+
IsControllerNodeKey: fmt.Sprintf("%t", false),
1115+
IsBrokerNodeKey: fmt.Sprintf("%t", true),
1116+
}
11121117
}
11131118
return util.MergeLabels(
11141119
bConfig.BrokerLabels,

api/v1beta1/kafkacluster_types_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,12 @@ func TestGetBrokerLabels(t *testing.T) {
445445
{
446446
testName: "Labels in zookeeper mode",
447447
expectedLabels: map[string]string{
448-
AppLabelKey: expectedDefaultLabelApp,
449-
BrokerIdLabelKey: strconv.Itoa(expectedBrokerId),
450-
KafkaCRLabelKey: expectedKafkaCRName,
451-
"test_label_key": "test_label_value",
448+
AppLabelKey: expectedDefaultLabelApp,
449+
BrokerIdLabelKey: strconv.Itoa(expectedBrokerId),
450+
KafkaCRLabelKey: expectedKafkaCRName,
451+
IsBrokerNodeKey: "true",
452+
IsControllerNodeKey: "false",
453+
"test_label_key": "test_label_value",
452454
},
453455
brokerConfig: &BrokerConfig{
454456
Roles: nil,

pkg/resources/kafka/configmap_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ process.roles=broker,controller
10041004
`},
10051005
},
10061006
{
1007-
testName: "a Kafka cluster with a mix of broker-only, controller-only, and combined roles; controller nodes with multiple mount paths, and various migration configs set on each brokers",
1007+
testName: "a Kafka cluster with a mix of broker-only, controller-only, and combined roles; and various migration configs set on each brokers",
10081008
brokers: []v1beta1.Broker{
10091009
{
10101010
Id: 0,
@@ -1173,7 +1173,6 @@ process.roles=controller
11731173
`,
11741174
`advertised.listeners=INTERNAL://kafka-100.kafka.svc.cluster.local:9092
11751175
broker.id=100
1176-
control.plane.listener.name=CONTROLLER
11771176
cruise.control.metrics.reporter.bootstrap.servers=kafka-all-broker.kafka.svc.cluster.local:9092
11781177
cruise.control.metrics.reporter.kubernetes.mode=true
11791178
inter.broker.listener.name=INTERNAL
@@ -1185,7 +1184,6 @@ zookeeper.connect=example.zk:2181/kafka
11851184
`,
11861185
`advertised.listeners=INTERNAL://kafka-200.kafka.svc.cluster.local:9092
11871186
broker.id=200
1188-
control.plane.listener.name=CONTROLLER
11891187
controller.listener.names=CONTROLLER
11901188
11911189
cruise.control.metrics.reporter.bootstrap.servers=kafka-all-broker.kafka.svc.cluster.local:9092

0 commit comments

Comments
 (0)