Skip to content

refactor(e2e): add internal/fixture with the CR and tenancy builders - #2299

Merged
csatib02 merged 8 commits into
kube-logging:masterfrom
vyncint:refactor-e2e-internal-fixture
Jul 30, 2026
Merged

refactor(e2e): add internal/fixture with the CR and tenancy builders#2299
csatib02 merged 8 commits into
kube-logging:masterfrom
vyncint:refactor-e2e-internal-fixture

Conversation

@vyncint

@vyncint vyncint commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Adds e2e/internal/fixture, builders for the CR literals the suites repeat. Nothing imports it yet, so no existing behaviour changes.

  • Logging, FluentdSpec, Buffer, HTTPOutput and Flow, with functional options.
  • LoggingInfra, LoggingTenant and LoggingRoute ported from common/helpers.go as pure builders returning the objects in creation order, so the caller creates them and the package needs no client, context or testing.T.
  • Each default is the value most call sites already use. Anything that diverges passes an option.
  • Tenancy keeps its own aggregator spec: it disables the PVC and requests less than the single-tenant suites.
  • The package does not import common. The image constants are duplicated while both exist and a test pins them equal, so they cannot drift the way the syslog-ng reloader name did.

13 tests, no cluster. make check passes.

vyncint added 2 commits July 29, 2026 22:03
Wave B of kube-logging#2291: a new package, no suite touched yet.

Builders for Logging, FluentdSpec, Buffer, HTTPOutput and Flow, with the
defaults counted across the suites rather than chosen. Workers 2 (four sites
against three using 1), Timekey 1s (eight against three and one), TimekeyWait
0s (nine against three), and the 500m/200M + 250m/50M resources used by twelve
of the CR call sites. Anything that diverges passes an option.

The package does not import common. The image constants are duplicated for as
long as both exist, and a test asserts they stay equal so the two cannot drift
the way setup.defaultImages and common did over the syslog-ng reloader name.

TestBuilderReproducesTheMultiWorkerLiteral asserts the builder produces exactly
the Logging fluentd-aggregator writes by hand today, which is the §6 safety net
against a default quietly absorbing a divergence.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
Ports common.LoggingInfra, LoggingTenant and LoggingRoute as pure builders
returning the objects in creation order, so the caller does the creating and
the package needs no client, context or testing.T.

tenancyFluentdSpec is deliberately separate from FluentdSpec: both tenancy
aggregators disable the PVC and request 50m/50M with no limits, where the
twelve single-tenant call sites use 500m/200M and 250m/50M. Folding them into
one default is the drift §6 warns about, and a test fails if it happens.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 15:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

e2e/internal/fixture/tenancy_test.go:78

  • This assertion currently expects WatchNamespaces to be ["tenant"] even though the builder is called with nsTenant = "tenant-ns". If LoggingTenant is corrected to watch the passed tenant namespace, this expectation should match the argument value.
	lg := objs[2].(*v1beta1.Logging)
	require.Equal(t, TenantRef, lg.Spec.LoggingRef)
	require.Equal(t, "tenant-ns", lg.Spec.ControlNamespace)
	require.Equal(t, []string{TenantRef}, lg.Spec.WatchNamespaces)
}

e2e/internal/fixture/tenancy.go:125

  • LoggingTenant takes nsTenant but hard-codes WatchNamespaces to TenantRef ("tenant"). If a suite uses a tenant namespace name other than "tenant", the tenant Logging will stop watching the namespace where the Flow/Output are created (it will watch "tenant" instead), breaking routing/aggregation.
		Spec: v1beta1.LoggingSpec{
			LoggingRef:       TenantRef,
			ControlNamespace: nsTenant,
			WatchNamespaces:  []string{TenantRef},
			FluentdSpec:      tenancyFluentdSpec(),

Review feedback on kube-logging#2299. LoggingTenant took nsTenant but set WatchNamespaces
to TenantRef, so the aggregator watched a namespace named after the loggingRef
instead of the one its Flow and Output are created in. It came over that way
from common/helpers.go, which hard-codes "tenant" there and gets away with it
only because both multi-tenant suites happen to name the namespace "tenant"
too; any other name leaves the Flow never picked up.

Nothing imports the package yet and the suites pass "tenant", so the objects
built for them are identical either way.

The shape test now asserts WatchNamespaces against the Flow's own namespace,
and guards that the fixture namespace differs from TenantRef so the assertion
cannot go vacuous if the two are ever aligned. Reverting the builder to
TenantRef fails it.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
@vyncint

vyncint commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Both suppressed comments on the last review were right. Fixed in 96b3131.

LoggingTenant took nsTenant but set WatchNamespaces to TenantRef, so the aggregator watched a namespace named after the loggingRef rather than the one its Flow and Output are created in. It came over that way from common/helpers.go:231, which hard-codes the literal "tenant". Both call sites — fluentbit-multitenant and fluentbit-hotreload — pass nsTenant := "tenant", so the two strings coincide there and the bug never fires. Nothing in common needs changing, and since the suites pass "tenant", the objects the builder produces for them are unchanged by this.

The second comment was the more useful half: the test passed "tenant-ns" and asserted []string{TenantRef}, so it pinned the trap rather than catching it. It now asserts against the Flow's own namespace, plus a guard that the fixture namespace differs from TenantRef — without that guard, anyone later aligning the two would silently make the assertion vacuous.

Both directions have a negative control:

  • reverting the builder to TenantRef fails with expected ["tenant-ns"], actual ["tenant"]
  • renaming the fixture namespace to "tenant" fails the guard with Should not be: "tenant"

make check passes, golangci-lint run --max-same-issues=0 --max-issues-per-linter=0 in e2e/ reports 0 issues, and the 13 tests still run in 0.01s with no cluster. All three commits build on their own.

@csatib02 csatib02 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sweep the code and clean it up as much as you can, there is a lot of unnecessary commenting going on.

Comment thread e2e/internal/fixture/fixture_test.go Outdated
Comment thread e2e/internal/fixture/fixture_test.go Outdated
Comment thread e2e/internal/fixture/images.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

e2e/internal/fixture/fixture_test.go:146

  • This literal includes ObjectMeta.Namespace, but Logging is cluster-scoped. Keeping a namespace here makes the struct-equality safety net assert an invalid object shape (and would fail against a corrected Logging() builder).
	want := &v1beta1.Logging{
		ObjectMeta: metav1.ObjectMeta{
			Name:      "fluentd-aggregator-multiworker-test",
			Namespace: ns,
		},
		Spec: v1beta1.LoggingSpec{

e2e/internal/fixture/fixture_test.go:60

  • Logging() should not populate .Namespace (Logging is cluster-scoped), so this assertion bakes in an invalid shape and will start failing once Logging() is fixed to match the CRD scope.

This issue also appears on line 141 of the same file.

func TestLoggingDefaults(t *testing.T) {
	l := Logging("ns", "lg")

	require.Equal(t, "lg", l.Name)
	require.Equal(t, "ns", l.Namespace)
	require.Equal(t, "ns", l.Spec.ControlNamespace)
	require.True(t, l.Spec.EnableRecreateWorkloadOnImmutableFieldChange)

Comment thread e2e/internal/fixture/logging.go Outdated
vyncint added 3 commits July 30, 2026 17:17
Review feedback on kube-logging#2299. Logging is scope: Cluster, so ObjectMeta.Namespace is
meaningless on it: the API server clears the field for cluster-scoped kinds,
which is why the suites have always set it without anything failing. The tenancy
builders here already omitted it, so the base builder now matches, and its first
parameter is named controlNamespace to say what it actually sets.

The literal test drops the same field from its expected object, leaving that the
only intended difference from what fluentd-aggregator writes by hand.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
Review feedback on kube-logging#2299. The comments narrated the restructuring plan the
package came from: section numbers, per-suite counts, the history of an earlier
drift. None of that means anything to someone reading the code on its own, so it
is gone. 78 non-header comment lines down to 46, and what is left is mostly doc
comments on exported identifiers.

Assertion messages that only restated the expected value are gone with them;
require prints the value on failure anyway.

The copyright year said 2025 on all six files, which were written in 2026.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
Second sweep. 46 non-header comment lines to 11.

What went was doc comments restating the signature they sat above, on
identifiers whose names already say it: LoggingOption, WithFluentbit,
WithFluentd, Workers, Drain, Buffer, BufferOption, Timekey, TimekeyWait,
ReceiverURL, HTTPOutput, Flow, LoggingRoute and the two tenancy builders.
The package matches the rest of e2e now, where exported identifiers carry
no doc comment.

What stayed is four points the code cannot state: Logging being
cluster-scoped, why FluentdOption is exported, why the image constants are
duplicated, and why WatchNamespaces takes a namespace rather than the ref.
Three in the tests explain an assertion that would otherwise look arbitrary.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
@csatib02

Copy link
Copy Markdown
Member

Seems like the ci is failing :/

vyncint added 2 commits July 30, 2026 20:20
test-e2e-nodeps selects every package in the module and filters the helpers
back out, but the filter names common. A package under internal/ is therefore
out of its reach, so the e2e job also builds and runs internal/kind and
internal/wait today, and internal/fixture from this branch.

Harmless in itself, those tests are hermetic and take about a second between
them, but it re-runs under a 20 minute cluster job what make test already
covers, and every later internal/ package joins them.

Matching the directory rather than the prefix, so a suite whose name merely
starts with those words is not dropped.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
@csatib02
csatib02 merged commit 04e6f77 into kube-logging:master Jul 30, 2026
29 checks passed
@csatib02 csatib02 added the enhancement New feature or request label Jul 31, 2026
vyncint added a commit to vyncint/logging-operator that referenced this pull request Aug 3, 2026
The builders landed in kube-logging#2299 with tests that assert the shape this package
chose, not that the choice matches what common creates. A suite moving onto
them could stop testing what it used to and still pass.This records what common.LoggingInfra, LoggingTenant and LoggingRoute hand to
Create and requires the builders to equal it, object for object and in order.
It passes as written, so the builders are a faithful stand-in today.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants