forked from banzaicloud/koperator
-
Notifications
You must be signed in to change notification settings - Fork 17
feat/Broker status - version/image extraction improvements #243
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
Open
azun
wants to merge
6
commits into
master
Choose a base branch
from
feature/reconcile-improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+72
−18
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6493987
feat/Broker version extraction improvements
azun 8f25bec
Added PodMonitor for Prometheus metrics
azun 8b3ad25
Update charts/kafka-operator/templates/podmonitor.yaml
azun 32c6bd2
Update charts/kafka-operator/templates/podmonitor.yaml
azun 3317ccc
label cleanup
7cac66e
Added 30s timeout to JMX extractor
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| {{- if .Values.prometheusMetrics.podMonitor.enabled }} | ||
| kind: PodMonitor | ||
| apiVersion: monitoring.coreos.com/v1 | ||
| metadata: | ||
| name: {{ include "kafka-operator.fullname" . }} | ||
| namespace: {{ .Release.Namespace | quote }} | ||
| labels: | ||
| helm.sh/chart: {{ include "kafka-operator.chart" . }} | ||
| app.kubernetes.io/name: {{ include "kafka-operator.name" . }} | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
| app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
| app.kubernetes.io/component: operator | ||
| {{- with .Values.operator.annotations }} | ||
| annotations: | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| spec: | ||
| namespaceSelector: | ||
| matchNames: | ||
| - {{ .Release.Namespace }} | ||
| selector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: {{ include "kafka-operator.name" . }} | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| app.kubernetes.io/component: operator | ||
| endpoints: | ||
| - interval: {{ .Values.prometheusMetrics.podMonitor.interval }} | ||
| port: metrics | ||
| path: /metrics | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -409,6 +409,7 @@ func (r *Reconciler) Reconcile(log logr.Logger) error { | |
| reorderedBrokers := reorderBrokers(runningBrokers, boundPersistentVolumeClaims, r.KafkaCluster.Spec.Brokers, r.KafkaCluster.Status.BrokersState, controllerID, log) | ||
|
|
||
| allBrokerDynamicConfigSucceeded := true | ||
| brokerStatus := make(map[int32]*banzaiv1beta1.BrokerConfig) | ||
| for _, broker := range reorderedBrokers { | ||
| brokerConfig, err := broker.GetBrokerConfig(r.KafkaCluster.Spec) | ||
| if err != nil { | ||
|
|
@@ -449,9 +450,8 @@ func (r *Reconciler) Reconcile(log logr.Logger) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| if err = r.updateStatusWithDockerImageAndVersion(broker.Id, brokerConfig, log); err != nil { | ||
| return err | ||
| } | ||
| brokerStatus[broker.Id] = brokerConfig | ||
|
|
||
| // If dynamic configs can not be set then let the loop continue to the next broker, | ||
| // after the loop we return error. This solves that case when other brokers could get healthy, | ||
| // but the loop exits too soon because dynamic configs can not be set. | ||
|
|
@@ -474,6 +474,10 @@ func (r *Reconciler) Reconcile(log logr.Logger) error { | |
| return err | ||
| } | ||
|
|
||
| if err := r.updateStatusWithDockerImageAndVersion(brokerStatus, log); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // in case HeadlessServiceEnabled is changed, delete the service that was created by the previous | ||
| // reconcile flow. The services must be deleted at the end of the reconcile flow after the new services | ||
| // were created and broker configurations reflecting the new services otherwise the Kafka brokers | ||
|
|
@@ -917,21 +921,36 @@ func (r *Reconciler) reconcileKafkaPod(log logr.Logger, desiredPod *corev1.Pod, | |
| return nil | ||
| } | ||
|
|
||
| func (r *Reconciler) updateStatusWithDockerImageAndVersion(brokerId int32, brokerConfig *banzaiv1beta1.BrokerConfig, | ||
| log logr.Logger) error { | ||
| jmxExp := jmxextractor.NewJMXExtractor(r.KafkaCluster.GetNamespace(), | ||
| r.KafkaCluster.Spec.GetKubernetesClusterDomain(), r.KafkaCluster.GetName(), log) | ||
| type brokerVersionResult struct { | ||
| brokerID int32 | ||
| kafkaVersion *banzaiv1beta1.KafkaVersion | ||
| err error | ||
| } | ||
|
|
||
| kafkaVersion, err := jmxExp.ExtractDockerImageAndVersion(brokerId, brokerConfig, | ||
| r.KafkaCluster.Spec.GetClusterImage(), r.KafkaCluster.Spec.HeadlessServiceEnabled) | ||
| if err != nil { | ||
| return err | ||
| func (r *Reconciler) updateStatusWithDockerImageAndVersion(brokers map[int32]*banzaiv1beta1.BrokerConfig, log logr.Logger) error { | ||
| ch := make(chan brokerVersionResult, len(brokers)) | ||
| for brokerID, brokerConfig := range brokers { | ||
| go func(id int32, cfg *banzaiv1beta1.BrokerConfig) { | ||
| jmxExp := jmxextractor.NewJMXExtractor(r.KafkaCluster.GetNamespace(), r.KafkaCluster.Spec.GetKubernetesClusterDomain(), r.KafkaCluster.GetName(), log) | ||
| kv, err := jmxExp.ExtractDockerImageAndVersion(id, cfg, r.KafkaCluster.Spec.GetClusterImage(), r.KafkaCluster.Spec.HeadlessServiceEnabled) | ||
| if err != nil { | ||
| ch <- brokerVersionResult{brokerID: id, err: err} | ||
| return | ||
| } | ||
| ch <- brokerVersionResult{brokerID: id, kafkaVersion: kv} | ||
| }(brokerID, brokerConfig) | ||
| } | ||
| err = k8sutil.UpdateBrokerStatus(r.Client, []string{strconv.Itoa(int(brokerId))}, r.KafkaCluster, | ||
| *kafkaVersion, log) | ||
| if err != nil { | ||
| return err | ||
|
|
||
| for range brokers { | ||
| result := <-ch | ||
| if result.err != nil { | ||
| return result.err | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drain the hole channel first then update the broker status so all or none are updated. |
||
| if err := k8sutil.UpdateBrokerStatus(r.Client, []string{strconv.Itoa(int(result.brokerID))}, r.KafkaCluster, *result.kafkaVersion, log); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goroutines have no cancellation path. If the controller shuts down mid-reconcile, these goroutines run to completion (or until JMX times out). Worth passing a context.Context from the reconcile call if JMX extraction can be long-running.