Skip to content

Commit 12bc620

Browse files
authored
Merge pull request #1920 from kube-logging/fix/output-flow-status
fix(validation-reconciler): correct output and flow status report
2 parents a241108 + 8bcae9e commit 12bc620

File tree

7 files changed

+61
-19
lines changed

7 files changed

+61
-19
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ spec:
6969
properties:
7070
allowClusterResourcesFromAllNamespaces:
7171
type: boolean
72+
x-kubernetes-validations:
73+
- message: Value is immutable, please recreate the resource
74+
rule: self == oldSelf
7275
clusterDomain:
7376
type: string
7477
configCheck:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ spec:
6666
properties:
6767
allowClusterResourcesFromAllNamespaces:
6868
type: boolean
69+
x-kubernetes-validations:
70+
- message: Value is immutable, please recreate the resource
71+
rule: self == oldSelf
6972
clusterDomain:
7073
type: string
7174
configCheck:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ spec:
6666
properties:
6767
allowClusterResourcesFromAllNamespaces:
6868
type: boolean
69+
x-kubernetes-validations:
70+
- message: Value is immutable, please recreate the resource
71+
rule: self == oldSelf
6972
clusterDomain:
7073
type: string
7174
configCheck:

docs/configuration/crds/v1beta1/logging_types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LoggingSpec defines the desired state of Logging
1010

1111
### allowClusterResourcesFromAllNamespaces (bool, optional) {#loggingspec-allowclusterresourcesfromallnamespaces}
1212

13-
Allow configuration of cluster resources from any namespace. Mutually exclusive with ControlNamespace restriction of Cluster resources
13+
Allow configuration of cluster resources from any namespace. Mutually exclusive with ControlNamespace restriction of Cluster resources WARNING: Becareful when turning this on and off as it can result in some resources being orphaned.
1414

1515

1616
### clusterDomain (*string, optional) {#loggingspec-clusterdomain}

pkg/resources/model/reconciler.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,19 @@ func NewValidationReconciler(
120120
}
121121

122122
for _, ref := range flow.Spec.GlobalOutputRefs {
123-
if output := resources.Fluentd.ClusterOutputs.FindByName(ref); output != nil {
123+
switch output := resources.Fluentd.ClusterOutputs.FindByName(ref); {
124+
case output == nil:
125+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling global output reference: %s", ref))
126+
127+
case output.Status.ProblemsCount > 0:
128+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("global output reference: %s has problems", output.Name))
129+
130+
default:
124131
flow.Status.Active = utils.BoolPointer(true)
125132
output.Status.Active = utils.BoolPointer(true)
126-
} else {
127-
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling global output reference: %s", ref))
128133
}
129134
}
135+
130136
flow.Status.ProblemsCount = len(flow.Status.Problems)
131137
}
132138

@@ -146,11 +152,12 @@ func NewValidationReconciler(
146152
switch output := resources.Fluentd.ClusterOutputs.FindByName(ref); {
147153
case output == nil:
148154
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling global output reference: %s", ref))
149-
continue
150155

151156
case output.Spec.Protected:
152157
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("global output reference is protected: %s", ref))
153-
continue
158+
159+
case output.Status.ProblemsCount > 0:
160+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("global output reference: %s has problems", output.Name))
154161

155162
default:
156163
output.Status.Active = utils.BoolPointer(true)
@@ -159,11 +166,16 @@ func NewValidationReconciler(
159166
}
160167

161168
for _, ref := range flow.Spec.LocalOutputRefs {
162-
if output := resources.Fluentd.Outputs.FindByNamespacedName(flow.Namespace, ref); output != nil {
169+
switch output := resources.Fluentd.Outputs.FindByNamespacedName(flow.Namespace, ref); {
170+
case output == nil:
171+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling local output reference: %s", ref))
172+
173+
case output.Status.ProblemsCount > 0:
174+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("local output reference: %s has problems", output.Name))
175+
176+
default:
163177
output.Status.Active = utils.BoolPointer(true)
164178
hasValidOutput = true
165-
} else {
166-
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling local output reference: %s", ref))
167179
}
168180
}
169181

@@ -185,13 +197,19 @@ func NewValidationReconciler(
185197
flow.Status.Problems = nil
186198

187199
for _, ref := range flow.Spec.GlobalOutputRefs {
188-
if output := resources.SyslogNG.ClusterOutputs.FindByName(ref); output != nil {
200+
switch output := resources.SyslogNG.ClusterOutputs.FindByName(ref); {
201+
case output == nil:
202+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling global output reference: %s", ref))
203+
204+
case output.Status.ProblemsCount > 0:
205+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("global output reference: %s has problems", output.Name))
206+
207+
default:
189208
flow.Status.Active = utils.BoolPointer(true)
190209
output.Status.Active = utils.BoolPointer(true)
191-
} else {
192-
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling global output reference: %s", ref))
193210
}
194211
}
212+
195213
flow.Status.ProblemsCount = len(flow.Status.Problems)
196214
}
197215

@@ -207,11 +225,12 @@ func NewValidationReconciler(
207225
switch output := resources.SyslogNG.ClusterOutputs.FindByName(ref); {
208226
case output == nil:
209227
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling global output reference: %s", ref))
210-
continue
211228

212229
case output.Spec.Protected:
213230
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("global output reference is protected: %s", ref))
214-
continue
231+
232+
case output.Status.ProblemsCount > 0:
233+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("global output reference: %s has problems", output.Name))
215234

216235
default:
217236
output.Status.Active = utils.BoolPointer(true)
@@ -220,11 +239,16 @@ func NewValidationReconciler(
220239
}
221240

222241
for _, ref := range flow.Spec.LocalOutputRefs {
223-
if output := resources.SyslogNG.Outputs.FindByNamespacedName(flow.Namespace, ref); output != nil {
242+
switch output := resources.SyslogNG.Outputs.FindByNamespacedName(flow.Namespace, ref); {
243+
case output == nil:
244+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling local output reference: %s", ref))
245+
246+
case output.Status.ProblemsCount > 0:
247+
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("local output reference: %s has problems", output.Name))
248+
249+
default:
224250
output.Status.Active = utils.BoolPointer(true)
225251
hasValidOutput = true
226-
} else {
227-
flow.Status.Problems = append(flow.Status.Problems, fmt.Sprintf("dangling local output reference: %s", ref))
228252
}
229253
}
230254

@@ -313,6 +337,8 @@ func NewValidationReconciler(
313337

314338
if !resources.Logging.WatchAllNamespaces() {
315339
resources.Logging.Status.WatchNamespaces = resources.WatchNamespaces
340+
} else {
341+
resources.Logging.Status.WatchNamespaces = []string{"*"}
316342
}
317343

318344
if resources.Logging.Spec.WatchNamespaceSelector != nil &&

pkg/resources/model/repository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ func (r LoggingResourceRepository) LoggingResourcesFor(ctx context.Context, logg
113113
return
114114
}
115115

116+
// UniqueWatchNamespaces returns the unique list of namespaces to watch for a logging resource.
117+
// if both watchNamespaces and watchNamespaceSelector are empty, it returns all namespaces.
116118
func UniqueWatchNamespaces(ctx context.Context, reader client.Reader, logging *v1beta1.Logging) ([]string, error) {
117119
watchNamespaces := logging.Spec.WatchNamespaces
118120
nsLabelSelector := logging.Spec.WatchNamespaceSelector

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import (
1919
"fmt"
2020

2121
util "github.com/cisco-open/operator-tools/pkg/utils"
22-
"github.com/kube-logging/logging-operator/pkg/resources/kubetool"
2322
corev1 "k8s.io/api/core/v1"
2423
v1 "k8s.io/api/core/v1"
2524
"k8s.io/apimachinery/pkg/api/resource"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/util/intstr"
27+
28+
"github.com/kube-logging/logging-operator/pkg/resources/kubetool"
2829
)
2930

3031
// +name:"LoggingSpec"
@@ -80,7 +81,11 @@ type LoggingSpec struct {
8081
// This should be a protected namespace from regular users.
8182
// Resources like fluentbit and fluentd will run in this namespace as well.
8283
ControlNamespace string `json:"controlNamespace"`
84+
85+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable, please recreate the resource"
86+
8387
// Allow configuration of cluster resources from any namespace. Mutually exclusive with ControlNamespace restriction of Cluster resources
88+
// WARNING: Becareful when turning this on and off as it can result in some resources being orphaned.
8489
AllowClusterResourcesFromAllNamespaces bool `json:"allowClusterResourcesFromAllNamespaces,omitempty"`
8590
// InlineNodeAgent Configuration
8691
// Deprecated, will be removed with next major version
@@ -202,7 +207,7 @@ const (
202207
DefaultFluentbitConfigReloaderImageRepository = "ghcr.io/kube-logging/config-reloader"
203208
DefaultFluentbitConfigReloaderImageTag = "v0.0.6"
204209
DefaultFluentdImageRepository = "ghcr.io/kube-logging/logging-operator/fluentd"
205-
DefaultFluentdImageTag = "latest"
210+
DefaultFluentdImageTag = "latest-full"
206211
DefaultFluentdBufferStorageVolumeName = "fluentd-buffer"
207212
DefaultFluentdDrainWatchImageRepository = "ghcr.io/kube-logging/fluentd-drain-watch"
208213
DefaultFluentdDrainWatchImageTag = "v0.2.3"

0 commit comments

Comments
 (0)