Skip to content

Conversation

@stuggi
Copy link
Owner

@stuggi stuggi commented May 13, 2025

Summary by Sourcery

Introduce configurable leader election parameters for the operator by wiring new environment variables through the setup and deployment, and refactor application startup to leverage lib-common for manager options.

New Features:

  • Add LEASE_DURATION, RENEW_DEADLINE, and RETRY_PERIOD environment variables to configure operator leader election timeouts

Enhancements:

  • Refactor SetupEnv to use strings.SplitN and a switch statement for more robust environment variable parsing
  • Centralize manager configuration by replacing inline ctrl.Options with operator.SetManagerOptions in both main applications

Deployment:

  • Update operator deployment templates and manager config to include the new lease, renew deadline, and retry period environment variables

@sourcery-ai
Copy link

sourcery-ai bot commented May 13, 2025

Reviewer's Guide

This PR introduces configurable timing parameters for the operator by parsing new environment variables and exposing them in deployment templates, refactors environment variable parsing logic for increased robustness, and unifies controller-runtime manager options setup using the common operator library with standardized imports.

Sequence Diagram: Operator Manager Configuration with lib-common

sequenceDiagram
    participant main as "main() (operator/main.go or main.go)"
    participant libCommonOp as "lib-common/operator.SetManagerOptions"
    participant ctrlOptions as "ctrl.Options"
    participant ctrlMgr as "ctrl.NewManager"

    main->>main: Initialize ctrl.Options (options)
    note left of main: SetupEnv() has already parsed env vars like LEASE_DURATION into global variables
    main->>libCommonOp: SetManagerOptions(&options, setupLog)
    libCommonOp->>ctrlOptions: Configure leader election (LeaseDuration, RenewDeadline, RetryPeriod, etc.)
    note right of libCommonOp: Uses values from env vars (read by SetupEnv()) either directly or indirectly if SetManagerOptions accesses them or they are passed through options struct setup before this call.
    main->>ctrlMgr: NewManager(config, options)
Loading

Sequence Diagram: Refactored Environment Variable Parsing in SetupEnv

sequenceDiagram
    participant osEnviron as "os.Environ()"
    participant SetupEnv as "SetupEnv()"
    participant GlobalConfigs as "Global Config Variables"

    SetupEnv->>osEnviron: Get all environment variables
    loop For each environment variable
        SetupEnv->>SetupEnv: Parse key & value (using strings.SplitN)
        alt key is "LEASE_DURATION"
            SetupEnv->>GlobalConfigs: operatorLeaseDuration = value
        else key is "RENEW_DEADLINE"
            SetupEnv->>GlobalConfigs: operatorRenewDeadline = value
        else key is "RETRY_PERIOD"
            SetupEnv->>GlobalConfigs: operatorRetryPeriod = value
        else key matches "*_OPERATOR_MANAGER_IMAGE_URL"
            SetupEnv->>GlobalConfigs: envRelatedOperatorImages[operatorName] = value
        else key matches "RELATED_IMAGE_*"
            SetupEnv->>GlobalConfigs: envRelatedOpenStackServiceImages[key] = value
        else Other specific keys (KUBE_RBAC_PROXY, etc.)
            SetupEnv->>GlobalConfigs: (assigns to respective global var)
        end
    end
Loading

File-Level Changes

Change Details Files
Parse and propagate new timing environment variables for operator deployment
  • Add parsing logic for LEASE_DURATION, RENEW_DEADLINE, and RETRY_PERIOD in SetupEnv
  • Expose operatorLeaseDuration, operatorRenewDeadline, and operatorRetryPeriod in rendering data
  • Update operator.yaml and manager.yaml to include LEASE_DURATION, RENEW_DEADLINE, and RETRY_PERIOD env entries
controllers/operator/openstack_controller.go
bindata/operator/operator.yaml
config/manager/manager.yaml
Unify controller-runtime manager option setup using lib-common operator
  • Import common/operator module and alias operator API import path
  • Switch from inline ctrl.Options in NewManager to a shared options variable
  • Invoke operator.SetManagerOptions(&options, setupLog) and handle errors before creating the manager
cmd/operator/main.go
main.go
Refactor environment variable parsing logic for robustness
  • Replace strings.Split with strings.SplitN plus len check to handle missing values
  • Convert chained if-else into a switch on the env key for clarity
  • Consolidate image-related variable assignments using the switch cases
controllers/operator/openstack_controller.go

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

@stuggi
Copy link
Owner Author

stuggi commented May 13, 2025

@sourcery-ai review

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 @stuggi - I've reviewed your changes - here's some feedback:

  • Provide in-code default values for LEASE_DURATION, RENEW_DEADLINE, and RETRY_PERIOD to mirror your template defaults and avoid running with empty settings when those env vars aren’t set.
  • Simplify SetupEnv by using os.LookupEnv (or a map of expected env‐vars) instead of iterating over all os.Environ and splitting each entry, to make the parsing clearer and more efficient.
  • Since you renamed the CRD field frrConfigurationNamespace to nodeName, consider adding a conversion webhook or migration logic to handle existing instances that still use the old field name.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

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 @stuggi - I've reviewed your changes - here's some feedback:

  • In SetupEnv you’re taking the address of the reused loop variable value, so every map entry will point to the same memory—capture a new local variable (e.g. val := value) per case before storing its pointer.
  • The CRD change renaming frrConfigurationNamespace to nodeName is a breaking change—consider bumping the CRD version or adding conversion logic to preserve compatibility.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

@stuggi
Copy link
Owner Author

stuggi commented May 13, 2025

@sourcery-ai review

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 @stuggi - I've reviewed your changes - here's some feedback:

  • In SetupEnv, use strings.SplitN(env, "=", 2) instead of strings.Split so you correctly capture values containing “=”.
  • Add validation or fallback defaults for LEASE_DURATION, RENEW_DEADLINE, and RETRY_PERIOD to avoid starting the operator with empty or invalid timing values.
  • The manager options initialization is duplicated in cmd/operator/main.go and main.go—consider extracting it into a shared helper to reduce duplication.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

Comment on lines +47 to +51
- name: LEASE_DURATION
value: "137"
- name: RENEW_DEADLINE
value: "107"
- name: RETRY_PERIOD
Copy link

Choose a reason for hiding this comment

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

suggestion: Hardcoded defaults may drift without context

Consider centralizing the default values (137, 107, 26) or adding a comment explaining their choice to avoid them drifting out of sync.

@stuggi
Copy link
Owner Author

stuggi commented May 13, 2025

@sourcery-ai review

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 @stuggi - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

@stuggi stuggi closed this May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants