Skip to content

Commit 31c2a4b

Browse files
authored
Merge pull request #1541 from kube-logging/configcheck-as-problems
Add configcheck result help into the logging resource status
2 parents 786f393 + 5676b1b commit 31c2a4b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pkg/resources/configcheck/configcheck.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ import (
2323
"sigs.k8s.io/controller-runtime/pkg/client"
2424
)
2525

26-
const hashLabel = "logging.banzaicloud.io/config-hash"
26+
const HashLabel = "logging.banzaicloud.io/config-hash"
2727

2828
func WithHashLabel(accessor v1.Object, hash string) {
2929
l := accessor.GetLabels()
3030
if l == nil {
3131
l = map[string]string{}
3232
}
33-
l[hashLabel] = hash
33+
l[HashLabel] = hash
3434
accessor.SetLabels(l)
3535
}
3636

3737
func hasHashLabel(accessor v1.Object, hash string) (has bool, match bool) {
3838
l := accessor.GetLabels()
3939
var val string
40-
val, has = l[hashLabel]
40+
val, has = l[HashLabel]
4141
return has, val == hash
4242
}
4343

pkg/resources/model/reconciler.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import (
2424
"github.com/cisco-open/operator-tools/pkg/secret"
2525
"github.com/cisco-open/operator-tools/pkg/utils"
2626
"github.com/go-logr/logr"
27+
"golang.org/x/exp/slices"
2728
"sigs.k8s.io/controller-runtime/pkg/client"
2829
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2930

31+
"github.com/kube-logging/logging-operator/pkg/resources/configcheck"
3032
loggingv1beta1 "github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
3133

3234
"github.com/kube-logging/logging-operator/pkg/mirror"
@@ -225,6 +227,18 @@ func NewValidationReconciler(
225227
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, problem)
226228
}
227229

230+
for hash, r := range resources.Logging.Status.ConfigCheckResults {
231+
if !r {
232+
problem := fmt.Sprintf("Configuration with checksum %s has failed. "+
233+
"Config secrets: `kubectl get secret -n %s -l %s=%s`. "+
234+
"Configcheck pod log: `kubectl logs -n %s -l %s=%s --tail -1`",
235+
hash,
236+
resources.Logging.Spec.ControlNamespace, configcheck.HashLabel, hash,
237+
resources.Logging.Spec.ControlNamespace, configcheck.HashLabel, hash)
238+
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, problem)
239+
}
240+
}
241+
228242
if len(resources.Logging.Spec.NodeAgents) > 0 || len(resources.NodeAgents) > 0 {
229243
// load agents from standalone NodeAgent resources and additionally with inline nodeAgents from the logging resource
230244
// for compatibility reasons
@@ -243,6 +257,7 @@ func NewValidationReconciler(
243257
}
244258
}
245259
}
260+
slices.Sort(resources.Logging.Status.Problems)
246261
resources.Logging.Status.ProblemsCount = len(resources.Logging.Status.Problems)
247262

248263
var errs error

0 commit comments

Comments
 (0)