Skip to content

fix: resource labeling#2197

Merged
csatib02 merged 11 commits intomasterfrom
fix/resource-labeling
Mar 12, 2026
Merged

fix: resource labeling#2197
csatib02 merged 11 commits intomasterfrom
fix/resource-labeling

Conversation

@csatib02
Copy link
Copy Markdown
Member

@csatib02 csatib02 commented Mar 2, 2026

fixes: #2110

@csatib02 csatib02 requested review from OverOrion and pepov March 2, 2026 16:45
@csatib02 csatib02 self-assigned this Mar 2, 2026
@csatib02 csatib02 changed the base branch from master to feat/claude-initial March 2, 2026 16:45
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 2, 2026

Greptile Summary

This PR fixes inconsistent Kubernetes resource labeling across all operator-managed workloads (FluentBit DaemonSets, Fluentd StatefulSets, SyslogNG StatefulSets, HostTailer DaemonSets, and EventTailer StatefulSets) by ensuring pod templates carry the full recommended set of app.kubernetes.io/* labels, and by replacing all hardcoded label key string literals with typed constants from github.com/cisco-open/operator-tools/pkg/types.

Key changes:

  • New pod labels added: FluentBit pods get app.kubernetes.io/component: collector; Fluentd and SyslogNG pods get app.kubernetes.io/instance: <logging-name>; HostTailer and EventTailer pods get app.kubernetes.io/component: host-tailer/event-tailer. StatefulSet/DaemonSet selectors are intentionally left unchanged so immutable selector fields are not violated.
  • Import alias cleanup: Ambiguous aliases (v1, v12) in service files are replaced with descriptive names (monitoringv1, metav1).
  • Linter configuration: gci, gofmt, gofumpt, goimports formatters are enabled alongside gocyclo, but gocyclo's min-complexity is raised from 15 to 40 and two functions receive //nolint: gocyclo suppressions.
  • Broad code-style sweep: ~150 files receive import-grouping fixes, var:= simplifications, and multi-line formatting alignment driven by the newly enabled linters.

Confidence Score: 4/5

  • Safe to merge; the core labeling fix is correct and the label additions are backwards-compatible, but two style issues warrant attention before merging.
  • The label additions are strictly additive to pod templates and do not touch immutable selector fields, so no Kubernetes resource conflicts arise. The import alias and constant-refactor changes are purely cosmetic. The two concerns — an overly permissive gocyclo threshold (15→40) and misplaced //nolint: gci directives that may silently fail — are style/tooling issues that don't affect runtime behaviour but reduce the value of the newly added linters.
  • .golangci.yml (gocyclo threshold), main.go and controllers/logging/suite_test.go (misplaced nolint directives)

Important Files Changed

Filename Overview
.golangci.yml Adds gci/gofmt/gofumpt/goimports formatters and gocyclo linter, but increases gocyclo min-complexity from 15 to 40 — an overly aggressive threshold relaxation that masks code quality concerns.
pkg/sdk/logging/api/v1beta1/logging_types.go Replaces hardcoded label key strings with types.*Label constants for fluentd and syslog-ng, and updates GenerateLoggingRefLabels to use types.ManagedByLabel; functionally equivalent refactor.
pkg/resources/fluentbit/daemonset.go Adds types.ComponentLabel: "collector" to FluentBit DaemonSet pod template labels (while keeping the selector unchanged), completing the standard Kubernetes label set on collector pods.
pkg/resources/fluentd/statefulset.go Adds types.InstanceLabel: r.Logging.GetName() to Fluentd StatefulSet pod template labels (selector unchanged), providing a consistent app.kubernetes.io/instance label across all pod types.
pkg/resources/syslogng/statefulset.go Same pattern as fluentd: adds types.InstanceLabel: r.Logging.GetName() to SyslogNG StatefulSet pod template labels without touching the immutable selector.
pkg/resources/hosttailer/helpers.go Adds allLabels() helper that extends selectorLabels() with types.ComponentLabel: "host-tailer"; replaces manual loop with maps.Copy.
pkg/resources/eventtailer/helpers.go Adds allLabels() helper that extends selectorLabels() with types.ComponentLabel: "event-tailer"; replaces manual loop with maps.Copy.
main.go Replaces hardcoded app.kubernetes.io/managed-by and app.kubernetes.io/name strings in cache setup with operatortypes.*Label constants; a //nolint: gci directive is placed on the wrong line and will not suppress the intended lint warning.
pkg/resources/configcheck/configcheck.go Replaces hardcoded app.kubernetes.io/component and app.kubernetes.io/managed-by strings in ConfigCheckCleaner label selector with types.*Label constants.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph "Labels on pod templates AFTER this PR"
        FB["FluentBit DaemonSet pods\napp.kubernetes.io/name: fluentbit\napp.kubernetes.io/instance: &lt;agent-name&gt;\napp.kubernetes.io/managed-by: &lt;logging-ref&gt;\n✅ NEW: app.kubernetes.io/component: collector"]
        FD["Fluentd StatefulSet pods\napp.kubernetes.io/name: fluentd\napp.kubernetes.io/component: fluentd\napp.kubernetes.io/managed-by: &lt;logging-ref&gt;\n✅ NEW: app.kubernetes.io/instance: &lt;logging-name&gt;"]
        SNG["SyslogNG StatefulSet pods\napp.kubernetes.io/name: syslog-ng\napp.kubernetes.io/component: syslog-ng\napp.kubernetes.io/managed-by: &lt;logging-ref&gt;\n✅ NEW: app.kubernetes.io/instance: &lt;logging-name&gt;"]
        HT["HostTailer DaemonSet pods\napp.kubernetes.io/name: host-tailer\napp.kubernetes.io/instance: &lt;tailer-name&gt;\n✅ NEW: app.kubernetes.io/component: host-tailer"]
        ET["EventTailer StatefulSet pods\napp.kubernetes.io/name: event-tailer\napp.kubernetes.io/instance: &lt;tailer-name&gt;\n✅ NEW: app.kubernetes.io/component: event-tailer"]
    end

    subgraph "Selector labels (unchanged / immutable)"
        FBS["FluentBit selector\nname + instance + managed-by"]
        FDS["Fluentd selector\nname + component + managed-by"]
        SNGS["SyslogNG selector\nname + component + managed-by"]
        HTS["HostTailer selector\nname + instance"]
        ETS["EventTailer selector\nname + instance"]
    end

    FBS -->|"subset of"| FB
    FDS -->|"subset of"| FD
    SNGS -->|"subset of"| SNG
    HTS -->|"subset of"| HT
    ETS -->|"subset of"| ET
Loading

Comments Outside Diff (3)

  1. .golangci.yml, line 32 (link)

    Aggressive gocyclo threshold increase

    The min-complexity for gocyclo was raised from 15 to 40 — nearly a 3× increase. This is a wide suppression of cyclomatic complexity warnings rather than a targeted fix for the two functions that exceed the old threshold (FluentBitDefaults and NewValidationReconciler, which received //nolint: gocyclo suppressions at their definition sites).

    The previous threshold of 15 is already quite permissive; 40 means functions can have extremely convoluted branching before the linter raises a concern, effectively making the rule close to useless. Consider keeping the threshold lower (e.g., 25) and adding a narrow file/function level //nolint:gocyclo for the specific functions that legitimately exceed it.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  2. main.go, line 64-65 (link)

    Misplaced //nolint: gci directive

    The //nolint: gci comment is placed on its own line before // +kubebuilder:scaffold:imports. In golangci-lint, a nolint directive suppresses warnings for the line it is on, not for the line that follows. As written, the directive applies to the blank comment line itself rather than to the scaffold marker, so the suppression likely has no effect.

    If the gci linter is genuinely flagging // +kubebuilder:scaffold:imports, the nolint should be placed inline on the same line as the scaffold marker:

    The same pattern appears in controllers/logging/suite_test.go at the analogous location.

  3. controllers/logging/suite_test.go, line 40-41 (link)

    Misplaced //nolint: gci directive (same issue as main.go)

    Same as the main.go case: the //nolint: gci is on a separate line and will not suppress the lint warning on the // +kubebuilder:scaffold:imports marker that follows it. Move the directive inline:

Last reviewed commit: fcd2c98

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

18 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 2, 2026

Additional Comments (2)

pkg/sdk/logging/api/v1beta1/logging_types.go
Removing f.Labels from selectors is a breaking change. Existing StatefulSets have immutable selectors - when users upgrade, the operator will fail to update StatefulSets that were created with custom labels in FluentdSpec.Labels. Consider documenting the migration path or handling this transition gracefully.


pkg/resources/fluentbit/fluentbit.go
Inconsistent with Fluentd/SyslogNG approach - FluentBit selector labels still include user-defined labels (r.fluentbitSpec.Labels), while Fluentd selector labels exclude them. Consider aligning all three components to use the same pattern for selector labels.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Base automatically changed from feat/claude-initial to master March 3, 2026 09:31
@csatib02 csatib02 force-pushed the fix/resource-labeling branch from aec0c8c to 40753cc Compare March 3, 2026 09:32
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 3, 2026

Additional Comments (1)

pkg/resources/fluentbit/fluentbit.go, line 77
Inconsistent selector label pattern: getFluentBitSelectorLabels() includes r.fluentbitSpec.Labels (user-provided labels) and app.kubernetes.io/instance, but GetFluentdSelectorLabels() and GetSyslogNGSelectorLabels() exclude both. This creates inconsistency across components. Consider whether FluentBit selectors should follow the same pattern as FluentD/SyslogNG.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@csatib02 csatib02 force-pushed the fix/resource-labeling branch from 40753cc to d96cbd8 Compare March 3, 2026 11:10
@csatib02
Copy link
Copy Markdown
Member Author

csatib02 commented Mar 3, 2026

@greptile

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 3, 2026

Additional Comments (2)

.golangci.yml, line 33
Min complexity increased from 15 to 40 (2.6x increase). This significantly relaxes complexity requirements and may allow harder-to-maintain code.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


pkg/resources/fluentbit/daemonset.go, line 50
labels already contains types.InstanceLabel from getFluentBitLabels(), so line 49 redundantly overwrites it with the same value. Map capacity should be len(labels)+1 since only ComponentLabel is actually new.

@csatib02 csatib02 force-pushed the fix/resource-labeling branch from d96cbd8 to 513d67f Compare March 3, 2026 11:29
csatib02 added 11 commits March 12, 2026 09:51
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
@csatib02 csatib02 force-pushed the fix/resource-labeling branch from 513d67f to fcd2c98 Compare March 12, 2026 08:52
@csatib02 csatib02 merged commit 3029b32 into master Mar 12, 2026
43 of 44 checks passed
@csatib02 csatib02 deleted the fix/resource-labeling branch March 12, 2026 11:03
@csatib02 csatib02 added the bugfix label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent labels across resources

2 participants