Skip to content

Conversation

@osmman
Copy link
Collaborator

@osmman osmman commented Nov 18, 2025

Summary by Sourcery

Remove the Segment Backup Job feature and associated metrics support, cleaning up related resources and configurations throughout the operator.

Enhancements:

  • Eliminate Segment Backup Job and nightly CronJob creation logic and Action from the controller.
  • Refactor RBACAction to delete existing ServiceAccount, Role, RoleBinding, ClusterRole, and ClusterRoleBinding instead of creating them.
  • Remove metrics annotation parsing, documentation, and support code from controller, actions, and samples.
  • Drop the RELATED_IMAGE_SEGMENT_REPORTING image, CLI flag, and sample configuration entries.
  • Clean up RBAC role YAML to remove metrics-related permissions for monitoring and console resources.

CI:

  • Remove workflow step that toggled the metrics annotation in CI.

Documentation:

  • Update sample CR to omit the metrics annotation.

Tests:

  • Remove metrics annotation references from end-to-end and benchmark tests.

@osmman osmman requested review from JasonPowr and bouskaJ November 18, 2025 16:57
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 18, 2025

Reviewer's Guide

This PR removes the legacy Segment Backup Job and its metrics collection path from the operator, refactors the RBAC action into a deletion-only workflow, and cleans up all related constants, flags, tests, annotations, and sample manifests.

Sequence diagram for Segment Backup CronJob deletion process

sequenceDiagram
    participant Operator
    participant KubernetesAPI
    participant "Securesign Instance"
    Operator->>KubernetesAPI: Delete segment-backup-nightly-metrics CronJob
    KubernetesAPI-->>Operator: Success or NotFound
    Operator->>"Securesign Instance": Update status condition (Removed)
    "Securesign Instance"-->>Operator: Status updated
Loading

ER diagram for removal of Segment Backup Job related resources

erDiagram
    SECURESIGN ||--o{ SEGMENT_BACKUP_CRONJOB : removes
    %% SEGMENT_BACKUP_JOB entity removed
    SECURESIGN {
        string name
        string namespace
        %% annotation 'rhtas.redhat.com/metrics' removed
    }
    SEGMENT_BACKUP_CRONJOB {
        string name
        string namespace
    }
Loading

Class diagram for removal of Segment Backup Job and related actions

classDiagram
    class rbacAction {
        +Name() string
        +CanHandle(ctx, instance) bool
        +Handle(ctx, instance) *action.Result
        +cleanupResource(ctx, instance, object) *action.Result
    }
    class segmentBackupCronJob {
        +Name() string
        +CanHandle(ctx, instance) bool
        +Handle(ctx, instance) *action.Result
    }
    %% Removed class: segmentBackupJob (was previously present)
    %% Removed methods and attributes related to SegmentBackupJob
    rbacAction --|> action.Action
    segmentBackupCronJob --|> action.Action
Loading

File-Level Changes

Change Details Files
Refactor metrics RBAC action to one-step cleanup
  • Replaced multiple CreateOrUpdate calls with cleanupResource and action.IsContinue checks
  • Introduced cleanupResource helper and removed kubernetes.CreateOrUpdate/ensure imports
  • Cleaned up status condition handling to use i.Error and i.Continue directly
internal/controller/securesign/actions/segment_rbac.go
Convert CronJob action to delete existing resource
  • Dropped createOrUpdate and spec-building logic for the metrics CronJob
  • Replaced Handle implementation to delete the CronJob object and update status
  • Removed ensureSegmentBackupCronJob helper and related imports
internal/controller/securesign/actions/segment_backup_cronjob.go
Remove SegmentBackupJob action and file
  • Deleted segment_backup_job.go completely
  • Removed registration of NewSegmentBackupJobAction in controller actions slice
  • Cleaned up finalizer and deletion logic for SBJ from reconciler
internal/controller/securesign/actions/segment_backup_job.go
internal/controller/securesign/securesign_controller.go
Eliminate metrics annotation and related references
  • Removed Metrics constant and documentation in annotations.go
  • Stripped metrics annotations from e2e tests, sample CRs, and benchmark install
  • Deleted logic reading or parsing the rhtas.redhat.com/metrics annotation
internal/annotations/annotations.go
test/e2e/support/tas/securesign/securesign.go
test/e2e/benchmark/install_test.go
config/samples/rhtas_v1alpha1_securesign.yaml
Drop SegmentBackup image flag and constant
  • Removed SegmentBackup from internal/images/images.go and images.env
  • Deleted --segment-backup-job-image flag in cmd/main.go
internal/images/images.go
cmd/main.go
config/default/images.env
Clean up generated RBAC Role rules
  • Removed unneeded rules for monitoring.coreos.com/prometheuses/api
  • Dropped consoles and routes resources from role.yaml
config/rbac/role.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-merge-pro
Copy link

qodo-merge-pro bot commented Nov 18, 2025

PR Compliance Guide 🔍

(Compliance updated until commit cb455d2)

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

Previous compliance checks

Compliance check up to commit 2c2860d
Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Action Logging: New deletion path for the segment backup CronJob does not emit any structured audit log of
the critical delete action beyond status conditions, making it unclear if this action is
captured in audit trails.

Referred Code
err := i.Client.Delete(ctx, segmentBackupCronJob)
if err != nil {
	if errors.IsNotFound(err) {
		return i.Continue()
	} else {
		return i.Error(ctx, fmt.Errorf("could not delete segment backup cron job: %w", err), instance, metav1.Condition{
			Type:    MetricsCondition,
			Status:  metav1.ConditionFalse,
			Reason:  constants.Failure,
			Message: err.Error(),
		})
	}
}

meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
	Type:    MetricsCondition,
	Status:  metav1.ConditionTrue,
	Reason:  "Removed",
	Message: "Segment backup Cron Job removed",
})
return i.StatusUpdate(ctx, instance)

Learn more about managing compliance generic rules or creating your own custom rules

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@qodo-merge-pro
Copy link

qodo-merge-pro bot commented Nov 18, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Add finalizer logic to clean up cluster-scoped resources

Add logic to the deletion finalizer in securesign_controller.go to clean up the
cluster-scoped ClusterRole and ClusterRoleBinding resources associated with the
removed Segment backup job.

internal/controller/securesign/securesign_controller.go [86-89]

 	if instance.DeletionTimestamp != nil {
+		// The segment backup job and its RBAC resources are removed.
+		// The following cleanup is for older versions that might still have these resources.
+		// This can be removed in a future version.
+		if err := r.Delete(ctx, &v1.ClusterRoleBinding{ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf(actions.ClusterWideNamePattern, instance.Namespace, "clusterMonitoringRoleBinding")}}); err != nil && !errors.IsNotFound(err) {
+			log.Error(err, "problem with removing clusterMonitoringRoleBinding resource")
+		}
+		if err := r.Delete(ctx, &v1.ClusterRole{ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf(actions.ClusterWideNamePattern, instance.Namespace, "clusterRole")}}); err != nil && !errors.IsNotFound(err) {
+			log.Error(err, "problem with removing clusterRole resource")
+		}
+		if err := r.Delete(ctx, &v1.ClusterRoleBinding{ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf(actions.ClusterWideNamePattern, instance.Namespace, "clusterRoleBinding")}}); err != nil && !errors.IsNotFound(err) {
+			log.Error(err, "problem with removing clusterRoleBinding resource")
+		}
+
 		controllerutil.RemoveFinalizer(target, finalizer)
 		return ctrl.Result{}, r.Update(ctx, target)
 	}

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that the PR removes the finalizer logic for cleaning up RBAC resources, which would lead to orphaned cluster-scoped resources when a Securesign instance is deleted.

Medium
High-level
Refactor cleanup actions for efficiency

The cleanup actions for Segment Backup resources are inefficient as they run on
every reconciliation. Refactor them to execute only once by using a status
condition to track completion.

Examples:

internal/controller/securesign/actions/segment_rbac.go [34-36]
func (i rbacAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.Securesign) bool {
	return true
}
internal/controller/securesign/actions/segment_backup_cronjob.go [28-30]
func (i segmentBackupCronJob) CanHandle(_ context.Context, instance *rhtasv1alpha1.Securesign) bool {
	return true
}

Solution Walkthrough:

Before:

// In segment_rbac.go and segment_backup_cronjob.go

func (i action) CanHandle(...) bool {
    // Action always runs
    return true
}

func (i action) Handle(...) *action.Result {
    // Delete a resource (e.g., CronJob, Role, ServiceAccount)
    err := client.Delete(ctx, resource)
    if client.IgnoreNotFound(err) != nil {
        // ... error handling
    }

    // The action might update a status condition, but `CanHandle`
    // does not check it, leading to repeated execution.
    // The RBAC action does not update status at all.
    return Continue()
}

After:

// In segment_rbac.go and segment_backup_cronjob.go

func (i action) CanHandle(...) bool {
    // Check if cleanup is already done
    c := meta.FindStatusCondition(instance.Status.Conditions, CleanupCondition)
    if c != nil && c.Status == metav1.ConditionTrue {
        return false
    }
    return true
}

func (i action) Handle(...) *action.Result {
    // Delete a resource...
    err := client.Delete(ctx, resource)
    // ...

    // After all resources for this action are deleted, update status
    meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
        Type:    CleanupCondition,
        Status:  metav1.ConditionTrue,
        Reason:  "Removed",
    })
    return StatusUpdate(ctx, instance)
}
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies an inefficiency where cleanup actions in segment_rbac.go and segment_backup_cronjob.go run on every reconciliation, but it's a moderate performance issue, not a critical bug.

Low
  • Update

Signed-off-by: Tomas Turek <tturek@redhat.com>
@osmman osmman merged commit 0354430 into main Nov 19, 2025
21 checks passed
@osmman osmman deleted the tturek/remove-sbj branch November 19, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants