Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
59 changes: 58 additions & 1 deletion pkg/k8sutil/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"embed"
"strings"

"github.com/cisco-open/k8s-objectmatcher/patch"
"github.com/marklogic/marklogic-operator-kubernetes/pkg/result"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -44,6 +45,32 @@ func (oc *OperatorContext) ReconcileConfigMap() result.ReconcileResult {
logger.Error(err, "MarkLogic scripts configmap creation is failed")
return result.Error(err)
}
} else {
// ConfigMap exists, check if it needs to be updated
desiredConfigMap := oc.generateConfigMapDef(objectMeta, marklogicServerAsOwner(cr))

patchDiff, err := patch.DefaultPatchMaker.Calculate(configmap, desiredConfigMap,
patch.IgnoreStatusFields(),
patch.IgnoreVolumeClaimTemplateTypeMetaAndStatus(),
patch.IgnoreField("kind"))
if err != nil {
logger.Error(err, "Error calculating patch for MarkLogic ConfigMap")
return result.Error(err)
}

if !patchDiff.IsEmpty() {
logger.Info("MarkLogic ConfigMap data has changed, updating it")
configmap.Data = desiredConfigMap.Data
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Patch-based update logic here is duplicated in ReconcileFluentBitConfigMap; consider extracting a shared helper to reduce repetition and ensure consistent handling of annotations and future changes.

Copilot uses AI. Check for mistakes.
if err := patch.DefaultAnnotator.SetLastAppliedAnnotation(configmap); err != nil {
logger.Error(err, "Failed to set last applied annotation for MarkLogic ConfigMap")
}
err = client.Update(oc.Ctx, configmap)
if err != nil {
logger.Error(err, "MarkLogic ConfigMap update failed")
return result.Error(err)
}
logger.Info("MarkLogic ConfigMap update is successful")
}
}

return result.Continue()
Expand Down Expand Up @@ -78,6 +105,32 @@ func (oc *OperatorContext) ReconcileFluentBitConfigMap() result.ReconcileResult
logger.Error(err, "Fluent Bit configmap creation is failed")
return result.Error(err)
}
} else {
// ConfigMap exists, check if it needs to be updated
desiredConfigMap := oc.generateFluentBitDef(objectMeta, marklogicServerAsOwner(cr))

patchDiff, err := patch.DefaultPatchMaker.Calculate(configmap, desiredConfigMap,
patch.IgnoreStatusFields(),
patch.IgnoreVolumeClaimTemplateTypeMetaAndStatus(),
patch.IgnoreField("kind"))
if err != nil {
logger.Error(err, "Error calculating patch for Fluent Bit ConfigMap")
return result.Error(err)
}

if !patchDiff.IsEmpty() {
logger.Info("Fluent Bit ConfigMap data has changed, updating it")
configmap.Data = desiredConfigMap.Data
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Same patch/update pattern as earlier; refactoring into a generic ConfigMap reconcile helper would simplify maintenance and reduce risk of divergence.

Copilot uses AI. Check for mistakes.
if err := patch.DefaultAnnotator.SetLastAppliedAnnotation(configmap); err != nil {
logger.Error(err, "Failed to set last applied annotation for Fluent Bit ConfigMap")
}
err = client.Update(oc.Ctx, configmap)
if err != nil {
logger.Error(err, "Fluent Bit ConfigMap update failed")
return result.Error(err)
}
logger.Info("Fluent Bit ConfigMap update is successful")
}
}

return result.Continue()
Expand Down Expand Up @@ -165,10 +218,14 @@ func (oc *OperatorContext) getFluentBitData() map[string]string {
log_level: info
daemon: off
parsers_file: parsers.yaml
http_server: on
http_listen: 0.0.0.0
http_port: 2020
hot_reload: on
storage.metrics: on

pipeline:
inputs:`
// Add INPUT sections based on enabled log types
if strings.TrimSpace(oc.MarklogicGroup.Spec.LogCollection.Inputs) != "" {
fluentBitData["fluent-bit.yaml"] += "\n" + normalizeYAMLIndentation(oc.MarklogicGroup.Spec.LogCollection.Inputs, 4, 6)
} else {
Expand Down
1 change: 1 addition & 0 deletions pkg/k8sutil/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ func getFluentBitVolumeMount(containerParams containerParameters) []corev1.Volum
logsMount := corev1.VolumeMount{
Name: "datadir",
MountPath: markLogicLogsPath,
SubPath: "Logs",
}

if containerParams.AdditionalVolumeMounts != nil {
Expand Down
Loading