Skip to content

Commit

Permalink
test(e2e): refine detached fluentd test case
Browse files Browse the repository at this point in the history
Signed-off-by: Szilard Parrag <[email protected]>
  • Loading branch information
OverOrion committed Nov 23, 2023
1 parent 64301ac commit b1be341
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/configuration/crds/v1beta1/logging_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Result of the config check. Under normal conditions there is a single item in th

Default: -

### fluentdConfigName (string, optional) {#loggingstatus-fluentdconfigname}
### fluentdConfigName (*string, optional) {#loggingstatus-fluentdconfigname}

Name of the matched detached fluentd configuration object

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestFluentdAggregator_detached_multiple_MultiWorker(t *testing.T) {
t.Log("second fluentd instance should have it's problems field filled")
return false
}
if logging.Status.FluentdConfigName != fluentd.Name {
if logging.Status.FluentdConfigName != nil && *logging.Status.FluentdConfigName != fluentd.Name {
t.Logf("logging should use the detached fluentd configuration (name=%s), found: %v", fluentd.Name, logging.Status.FluentdConfigName)
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func TestFluentdAggregator_detached_MultiWorker(t *testing.T) {
Keepalive: utils.BoolPointer(false),
},
},
FluentdRef: "detached-fluentd",
},
}
common.RequireNoError(t, c.GetClient().Create(ctx, &logging))
Expand Down Expand Up @@ -191,6 +190,10 @@ func TestFluentdAggregator_detached_MultiWorker(t *testing.T) {
t.Log("waiting for the aggregator")
return false
}
if logging.Status.FluentdConfigName != nil && *logging.Status.FluentdConfigName != fluentd.Name {
t.Logf("logging should use the detached fluentd configuration (name=%s), found: %v", fluentd.Name, logging.Status.FluentdConfigName)
return false
}

cmd := common.CmdEnv(exec.Command("kubectl",
"logs",
Expand Down
24 changes: 12 additions & 12 deletions pkg/resources/model/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,6 @@ func NewValidationReconciler(
flow.Status.ProblemsCount = len(flow.Status.Problems)
}

if resources.Fluentd.Configuration != nil {
registerForPatching(resources.Fluentd.Configuration)

if resources.Logging.Spec.FluentdSpec != nil {
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, fmt.Sprintf("Fluentd configuration reference set (name=%s), but inline fluentd configuration is set as well, clearing inline", resources.Fluentd.Configuration.Name))
resources.Logging.Spec.FluentdSpec = nil
}
resources.Logging.Status.FluentdConfigName = resources.Fluentd.Configuration.Name
resources.Fluentd.Configuration.Status.Active = utils.BoolPointer(true)
resources.Fluentd.Configuration.Status.Logging = resources.Logging.Name
}

for i := range resources.SyslogNG.ClusterFlows {
flow := &resources.SyslogNG.ClusterFlows[i]
registerForPatching(flow)
Expand Down Expand Up @@ -219,6 +207,18 @@ func NewValidationReconciler(
resources.Logging.Status.Problems = nil
resources.Logging.Status.WatchNamespaces = nil

if resources.Fluentd.Configuration != nil {
registerForPatching(resources.Fluentd.Configuration)

if resources.Logging.Spec.FluentdSpec != nil {
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, fmt.Sprintf("Fluentd configuration reference set (name=%s), but inline fluentd configuration is set as well, clearing inline", resources.Fluentd.Configuration.Name))
resources.Logging.Spec.FluentdSpec = nil
}
resources.Logging.Status.FluentdConfigName = &resources.Fluentd.Configuration.Name
resources.Fluentd.Configuration.Status.Active = utils.BoolPointer(true)
resources.Fluentd.Configuration.Status.Logging = resources.Logging.Name
}

if !resources.Logging.WatchAllNamespaces() {
resources.Logging.Status.WatchNamespaces = resources.WatchNamespaces
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ func (r LoggingResourceRepository) FluentbitsFor(ctx context.Context, logging v1
}
func (r LoggingResourceRepository) handleMultipleDetachedFluentdObjects(list *[]v1beta1.Fluentd, logging *v1beta1.Logging) (*v1beta1.Fluentd, error) {
for _, i := range *list {
if logging.Status.FluentdConfigName != "" {
if i.Name != logging.Status.FluentdConfigName {
if logging.Status.FluentdConfigName != nil {
if i.Name != *logging.Status.FluentdConfigName {
i.Status.Problems = []string{}
i.Status.Problems = append(i.Status.Problems, "Logging already has a detached fluentd configuration, remove excess configuration objects")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/sdk/logging/api/v1beta1/logging_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type LoggingStatus struct {
// Result of the config check. Under normal conditions there is a single item in the map with a bool value.
ConfigCheckResults map[string]bool `json:"configCheckResults,omitempty"`
// Name of the matched detached fluentd configuration object
FluentdConfigName string `json:"fluentdConfigName,omitempty"`
FluentdConfigName *string `json:"fluentdConfigName,omitempty"`

// Problems with the logging resource
Problems []string `json:"problems,omitempty"`
Expand Down Expand Up @@ -189,7 +189,7 @@ func (l *Logging) SetDefaults() error {
if !l.Spec.FlowConfigCheckDisabled && l.Status.ConfigCheckResults == nil {
l.Status.ConfigCheckResults = make(map[string]bool)
}
if len(l.Status.FluentdConfigName) == 0 {
if l.Status.FluentdConfigName == nil {
if err := l.Spec.FluentdSpec.SetDefaults(); err != nil {
return err
}
Expand Down Expand Up @@ -525,5 +525,5 @@ func GenerateLoggingRefLabels(loggingRef string) map[string]string {
}

func (l *Logging) AreMultipleAggregatorsSet() bool {
return l.Spec.SyslogNGSpec != nil && (l.Spec.FluentdSpec != nil || len(l.Status.FluentdConfigName) != 0)
return l.Spec.SyslogNGSpec != nil && (l.Spec.FluentdSpec != nil || l.Status.FluentdConfigName != nil)
}
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 b1be341

Please sign in to comment.