Skip to content

Commit

Permalink
feat: add nodeagent definition conflict to logging problems
Browse files Browse the repository at this point in the history
  • Loading branch information
pepov committed Mar 22, 2023
1 parent 7e4811b commit 6b4aa7e
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_loggings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17387,6 +17387,10 @@ spec:
additionalProperties:
type: boolean
type: object
problems:
items:
type: string
type: array
type: object
type: object
served: true
Expand Down
2 changes: 2 additions & 0 deletions config/samples/logging_v1alpha2_nodeagent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ spec:
nodeAgents:
- name: fluentbit-inline
nodeAgentFluentbit: {}
- name: fluentbit-standalone
nodeAgentFluentbit: { }
---
apiVersion: logging.banzaicloud.io/v1beta1
kind: NodeAgent
Expand Down
4 changes: 2 additions & 2 deletions controllers/logging/logging_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
if _, exists := agents[a.Name]; !exists {
agents[a.Name] = a.NodeAgentConfig
} else {
log.Error(errors.New("nodeagent definition conflict"),
fmt.Sprintf("NodeAgent resource overrides inline nodeAgent definition in logging resource %s", a.Name))
problem := fmt.Sprintf("NodeAgent resource overrides inline nodeAgent definition in logging resource %s", a.Name)
log.Error(errors.New("nodeagent definition conflict"), problem)
}
}
reconcilers = append(reconcilers, nodeagent.New(r.Client, r.Log, &logging, agents, reconcilerOpts, fluentd.NewDataProvider(r.Client)).Reconcile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17387,6 +17387,10 @@ spec:
additionalProperties:
type: boolean
type: object
problems:
items:
type: string
type: array
type: object
type: object
served: true
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
k8s.io/klog/v2 v2.90.1
k8s.io/utils v0.0.0-20230202215443-34013725500c
sigs.k8s.io/controller-runtime v0.14.5
)

Expand Down Expand Up @@ -90,7 +91,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.26.2 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20230202215443-34013725500c // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
24 changes: 24 additions & 0 deletions pkg/resources/model/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"emperror.dev/errors"
"github.com/cisco-open/operator-tools/pkg/secret"
"github.com/cisco-open/operator-tools/pkg/utils"
loggingv1beta1 "github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -198,6 +199,29 @@ func NewValidationReconciler(
flow.Status.ProblemsCount = len(flow.Status.Problems)
}

registerForPatching(&resources.Logging)

resources.Logging.Status.Problems = nil

if len(resources.Logging.Spec.NodeAgents) > 0 || len(resources.NodeAgents) > 0 {
// load agents from standalone NodeAgent resources and additionally with inline nodeAgents from the logging resource
// for compatibility reasons
agents := make(map[string]loggingv1beta1.NodeAgentConfig)
for _, a := range resources.NodeAgents {
agents[a.Name] = a.Spec.NodeAgentConfig
}
for _, a := range resources.Logging.Spec.NodeAgents {
if _, exists := agents[a.Name]; !exists {
agents[a.Name] = a.NodeAgentConfig
problem := fmt.Sprintf("inline nodeAgent definition (%s) in Logging resource is deprecated, use standalone NodeAgent CRD instead!", a.Name)
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, problem)
} else {
problem := fmt.Sprintf("NodeAgent resource overrides inline nodeAgent definition (%s) in Logging resource", a.Name)
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, problem)
}
}
}

var errs error
for _, req := range patchRequests {
if req.IsEmptyPatch() {
Expand Down
1 change: 1 addition & 0 deletions pkg/sdk/logging/api/v1beta1/logging_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type LoggingSpec struct {
// LoggingStatus defines the observed state of Logging
type LoggingStatus struct {
ConfigCheckResults map[string]bool `json:"configCheckResults,omitempty"`
Problems []string `json:"problems,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
5 changes: 5 additions & 0 deletions pkg/sdk/logging/api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b4aa7e

Please sign in to comment.