Skip to content

Commit cb59b0b

Browse files
authored
Merge pull request #1959 from DinaGamalMahmoud/feat/varlibcontainers-optional
feat: add varlibcontainers volume as optional
2 parents e067070 + 184e86e commit cb59b0b

File tree

11 files changed

+46
-11
lines changed

11 files changed

+46
-11
lines changed

charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_fluentbitagents.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,8 @@ spec:
11401140
type: object
11411141
disableKubernetesFilter:
11421142
type: boolean
1143+
disableVarLibDockerContainers:
1144+
type: boolean
11431145
dnsConfig:
11441146
properties:
11451147
nameservers:

charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_loggings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,8 @@ spec:
19881988
type: object
19891989
disableKubernetesFilter:
19901990
type: boolean
1991+
disableVarLibDockerContainers:
1992+
type: boolean
19911993
dnsConfig:
19921994
properties:
19931995
nameservers:

charts/logging-operator/crds/logging.banzaicloud.io_fluentbitagents.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,8 @@ spec:
11371137
type: object
11381138
disableKubernetesFilter:
11391139
type: boolean
1140+
disableVarLibDockerContainers:
1141+
type: boolean
11401142
dnsConfig:
11411143
properties:
11421144
nameservers:

charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,8 @@ spec:
19851985
type: object
19861986
disableKubernetesFilter:
19871987
type: boolean
1988+
disableVarLibDockerContainers:
1989+
type: boolean
19881990
dnsConfig:
19891991
properties:
19901992
nameservers:

config/crd/bases/logging.banzaicloud.io_fluentbitagents.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,8 @@ spec:
11371137
type: object
11381138
disableKubernetesFilter:
11391139
type: boolean
1140+
disableVarLibDockerContainers:
1141+
type: boolean
11401142
dnsConfig:
11411143
properties:
11421144
nameservers:

config/crd/bases/logging.banzaicloud.io_loggings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,8 @@ spec:
19851985
type: object
19861986
disableKubernetesFilter:
19871987
type: boolean
1988+
disableVarLibDockerContainers:
1989+
type: boolean
19881990
dnsConfig:
19891991
properties:
19901992
nameservers:

docs/configuration/crds/v1beta1/fluentbit_types.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ Available in Logging operator version 4.2 and later. Specify a custom parser fil
9999
Disable Kubernetes metadata filter
100100

101101

102+
### disableVarLibDockerContainers (*bool, optional) {#fluentbitspec-disablevarlibdockercontainers}
103+
104+
DisableVarLibDockerContainers controls whether the /var/lib/docker/containers volume is mounted. If true, the volume is NOT mounted. If false (default), the volume is mounted.
105+
106+
102107
### enableUpstream (bool, optional) {#fluentbitspec-enableupstream}
103108

104109

pkg/resources/fluentbit/daemonset.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,6 @@ func newConfigMapReloader(spec *v1beta1.FluentbitSpec) corev1.Container {
176176

177177
func (r *Reconciler) generateVolumeMounts() (v []corev1.VolumeMount) {
178178
v = []corev1.VolumeMount{
179-
{
180-
Name: "varlibcontainers",
181-
ReadOnly: true,
182-
MountPath: "/var/lib/docker/containers",
183-
},
184179
{
185180
Name: "varlogs",
186181
ReadOnly: true,
@@ -192,6 +187,14 @@ func (r *Reconciler) generateVolumeMounts() (v []corev1.VolumeMount) {
192187
},
193188
}
194189

190+
if !*r.fluentbitSpec.DisableVarLibDockerContainers {
191+
v = append(v, corev1.VolumeMount{
192+
Name: "varlibcontainers",
193+
ReadOnly: true,
194+
MountPath: "/var/lib/docker/containers",
195+
})
196+
}
197+
195198
for vCount, vMnt := range r.fluentbitSpec.ExtraVolumeMounts {
196199
v = append(v, corev1.VolumeMount{
197200
Name: "extravolumemount" + strconv.Itoa(vCount),
@@ -215,21 +218,24 @@ func (r *Reconciler) generateVolumeMounts() (v []corev1.VolumeMount) {
215218
func (r *Reconciler) generateVolume() (v []corev1.Volume) {
216219
v = []corev1.Volume{
217220
{
218-
Name: "varlibcontainers",
221+
Name: "varlogs",
219222
VolumeSource: corev1.VolumeSource{
220223
HostPath: &corev1.HostPathVolumeSource{
221-
Path: r.fluentbitSpec.MountPath,
224+
Path: "/var/log",
222225
},
223226
},
224227
},
225-
{
226-
Name: "varlogs",
228+
}
229+
230+
if !*r.fluentbitSpec.DisableVarLibDockerContainers {
231+
v = append(v, corev1.Volume{
232+
Name: "varlibcontainers",
227233
VolumeSource: corev1.VolumeSource{
228234
HostPath: &corev1.HostPathVolumeSource{
229-
Path: "/var/log",
235+
Path: r.fluentbitSpec.MountPath,
230236
},
231237
},
232-
},
238+
})
233239
}
234240

235241
for vCount, vMnt := range r.fluentbitSpec.ExtraVolumeMounts {

pkg/sdk/logging/api/v1beta1/fluentbit_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type FluentbitSpec struct {
7777
Flush int32 `json:"flush,omitempty" plugin:"default:1"`
7878
// Set the grace time in seconds as Integer value. The engine loop uses a Grace timeout to define wait time on exit.
7979
Grace int32 `json:"grace,omitempty" plugin:"default:5"`
80+
// DisableVarLibDockerContainers controls whether the /var/lib/docker/containers volume is mounted.
81+
// If true, the volume is NOT mounted. If false (default), the volume is mounted.
82+
DisableVarLibDockerContainers *bool `json:"disableVarLibDockerContainers,omitempty"`
8083
// HotReload pauses all inputs and waits until they finish. In certain situations this is unacceptable, for example if an output is down for a longer time.
8184
// An undocumented option called "Hot_Reload.Ensure_Thread_Safety Off" can be used at the [SERVICE] config to force hotreload after the grace period.
8285
// Please note that it might result in a SIGSEGV, but worst case kubelet will restart the container.

pkg/sdk/logging/api/v1beta1/logging_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ func (logging *Logging) WatchAllNamespaces() bool {
267267

268268
func FluentBitDefaults(fluentbitSpec *FluentbitSpec) error {
269269
if fluentbitSpec != nil { // nolint:nestif
270+
// Set default value for DisableVarLibDockerContainers to false (meaning volume is mounted by default)
271+
if fluentbitSpec.DisableVarLibDockerContainers == nil {
272+
fluentbitSpec.DisableVarLibDockerContainers = util.BoolPointer(false)
273+
}
270274
if fluentbitSpec.PosisionDBLegacy != nil {
271275
return errors.New("`position_db` field is deprecated, use `positiondb`")
272276
}

0 commit comments

Comments
 (0)