Skip to content

Commit

Permalink
Bug #1616: Ensured that the custom PVC source details specified in th…
Browse files Browse the repository at this point in the history
…e fluentd.extraVolumes.volume.pvc.source.claimName of the fluentd definition are honoured, instead of always attempting to create a new PVC.
  • Loading branch information
bbyreddy committed Dec 12, 2023
1 parent 2c4ff95 commit 9f6e53c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/resources/fluentd/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package fluentd

import (
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -49,13 +50,17 @@ func (r *Reconciler) statefulset() (runtime.Object, reconciler.DesiredState, err
}
}
for _, n := range r.fluentdSpec.ExtraVolumes {
if n.Volume != nil && n.Volume.PersistentVolumeClaim != nil {
if n.Volume == nil || n.Volume.PersistentVolumeClaim == nil {
continue
}

if !isPersistentVolumeClaimSpecEmpty(n.Volume.PersistentVolumeClaim.PersistentVolumeClaimSpec) {
if err := n.Volume.ApplyPVCForStatefulSet(n.ContainerName, n.Path, spec, func(name string) metav1.ObjectMeta {
return r.FluentdObjectMeta(name, ComponentFluentd)
}); err != nil {
return nil, reconciler.StatePresent, err
}
} else {
} else if !isPersistentVolumeSourceEmpty(n.Volume.PersistentVolumeClaim.PersistentVolumeSource) {
if err := n.ApplyVolumeForPodSpec(&spec.Template.Spec); err != nil {
return nil, reconciler.StatePresent, err
}
Expand All @@ -72,6 +77,16 @@ func (r *Reconciler) statefulset() (runtime.Object, reconciler.DesiredState, err
return desired, reconciler.StatePresent, nil
}

func isPersistentVolumeClaimSpecEmpty(pvcSpec corev1.PersistentVolumeClaimSpec) bool {
searilizedPvcSpec, _ := json.Marshal(pvcSpec)
return string(searilizedPvcSpec) == `{"resources":{}}`
}

func isPersistentVolumeSourceEmpty(pvcSource corev1.PersistentVolumeClaimVolumeSource) bool {
searilizedPvcSource, _ := json.Marshal(pvcSource)
return string(searilizedPvcSource) == `{}`
}

func (r *Reconciler) statefulsetSpec() *appsv1.StatefulSetSpec {
var initContainers []corev1.Container

Expand Down

0 comments on commit 9f6e53c

Please sign in to comment.