Skip to content

Commit

Permalink
Remove initContainer in case of RackAwareness because it is not neces…
Browse files Browse the repository at this point in the history
…sary
  • Loading branch information
baluchicken committed Jun 27, 2019
1 parent 398652a commit 734822c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
30 changes: 23 additions & 7 deletions pkg/resources/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,29 @@ func (r *Reconciler) Reconcile(log logr.Logger) error {
}
}
}
for _, res := range []resources.ResourceWithBrokerAndString{
r.configMapPod,
} {
o := res(broker, lBIp, log)
err := k8sutil.Reconcile(log, r.Client, o, r.KafkaCluster)
if err != nil {
return emperror.WrapWith(err, "failed to reconcile resource", "resource", o.GetObjectKind().GroupVersionKind())
if r.KafkaCluster.Spec.RackAwareness == nil {
for _, res := range []resources.ResourceWithBrokerAndString{
r.configMapPod,
} {
o := res(broker, lBIp, log)
err := k8sutil.Reconcile(log, r.Client, o, r.KafkaCluster)
if err != nil {
return emperror.WrapWith(err, "failed to reconcile resource", "resource", o.GetObjectKind().GroupVersionKind())
}
}
} else {
if brokerState, ok := r.KafkaCluster.Status.BrokersState[broker.Id]; ok {
if brokerState.RackAwarenessState == banzaicloudv1alpha1.Configured {
for _, res := range []resources.ResourceWithBrokerAndString{
r.configMapPod,
} {
o := res(broker, lBIp, log)
err := k8sutil.Reconcile(log, r.Client, o, r.KafkaCluster)
if err != nil {
return emperror.WrapWith(err, "failed to reconcile resource", "resource", o.GetObjectKind().GroupVersionKind())
}
}
}
}
}

Expand Down
20 changes: 0 additions & 20 deletions pkg/resources/kafka/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ func (r *Reconciler) pod(broker banzaicloudv1alpha1.BrokerConfig, pvcs []corev1.
command = append(command, "/opt/kafka/bin/kafka-server-start.sh /config/broker-config")
}

if r.KafkaCluster.Spec.RackAwareness != nil {
initContainers = append(initContainers, *generateRackAwarenessConfig(broker.Image))
}

pod := &corev1.Pod{
ObjectMeta: templates.ObjectMetaWithGeneratedNameAndAnnotations(r.KafkaCluster.Name, util.MergeLabels(labelsForKafka(r.KafkaCluster.Name), map[string]string{"brokerId": fmt.Sprintf("%d", broker.Id)}), util.MonitoringAnnotations(), r.KafkaCluster),
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -200,22 +196,6 @@ func (r *Reconciler) pod(broker banzaicloudv1alpha1.BrokerConfig, pvcs []corev1.
return pod
}

func generateRackAwarenessConfig(image string) *corev1.Container {
return &corev1.Container{
Name: "gen-rack-aware-config",
Image: image,
Command: []string{
"/bin/bash", "-c", `until grep -q broker.rack /config/broker-config; do echo waiting for configuration; sleep 3; done;`,
},
VolumeMounts: []corev1.VolumeMount{
{
Name: brokerConfigMapVolumeMount,
MountPath: "/config",
},
},
}
}

func generatePodAntiAffinity(clusterName string, hardRuleEnabled bool) *corev1.PodAntiAffinity {
podAntiAffinity := corev1.PodAntiAffinity{}
if hardRuleEnabled {
Expand Down

0 comments on commit 734822c

Please sign in to comment.