Skip to content

Comments

Fix deduped volume mounts and env vars#66

Merged
galt-tr merged 5 commits intobsv-blockchain:masterfrom
galt-tr:dedupStuff
Feb 4, 2026
Merged

Fix deduped volume mounts and env vars#66
galt-tr merged 5 commits intobsv-blockchain:masterfrom
galt-tr:dedupStuff

Conversation

@galt-tr
Copy link
Contributor

@galt-tr galt-tr commented Jan 28, 2026

This pull request introduces deduplication logic for several Kubernetes deployment configuration fields to prevent duplicate entries when applying overrides, and adds corresponding unit tests to ensure correctness. It also updates dependencies and slightly adjusts the reconciliation requeue timing.

Deduplication improvements:

  • Added utility functions in internal/utils/deployment.go to deduplicate environment variables, environment sources, image pull secrets, volumes, and volume mounts, always keeping the last occurrence of each unique item.
  • Updated SetDeploymentOverridesWithContext and SetClusterOverrides to use these deduplication functions when merging user overrides, ensuring no duplicate entries are introduced in the deployment spec. [1] [2] [3]

Testing:

  • Added comprehensive unit tests in internal/utils/deployment_test.go to verify deduplication behavior for all new utility functions.

Dependency updates:

  • Added github.com/stretchr/testify for improved testing assertions and gopkg.in/yaml.v3 as an indirect dependency. [1] [2]

Controller behavior:

  • Increased the requeue interval for replica status monitoring in PropagationReconciler from 1 second to 5 seconds to reduce unnecessary reconciliation frequency.

@galt-tr galt-tr requested a review from mrz1836 as a code owner January 28, 2026 02:59
@github-actions github-actions bot added fork-pr PR originated from a forked repository requires-manual-review PR or issue requires manual review by a maintainer or security team labels Jan 28, 2026
@github-actions
Copy link

👋 Thanks, @galt-tr!

This pull request comes from a fork. For security, our CI runs in a restricted mode.
A maintainer will triage this shortly and run any additional checks as needed.

  • 🏷️ Labeled: fork-pr, requires-manual-review
  • 👀 We'll review and follow up here if anything else is needed.

Thanks for contributing to bsv-blockchain/teranode-operator! 🚀

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds deduplication logic for Kubernetes deployment configuration fields to prevent duplicate entries when applying overrides from custom resources. The changes include new utility functions for deduplicating environment variables, environment sources, image pull secrets, volumes, and volume mounts, along with comprehensive unit tests. The PR also updates dependencies to include testify for better test assertions and adjusts the replica status monitoring requeue interval in the PropagationReconciler.

Changes:

  • Added five deduplication utility functions that keep the last occurrence of duplicate entries based on unique identifiers (env var names, configmap/secret references, volume names, etc.)
  • Updated SetDeploymentOverridesWithContext and SetClusterOverrides to apply deduplication when merging user-provided overrides with default deployment configurations
  • Increased the PropagationReconciler's replica status monitoring requeue interval from 1 second to 5 seconds

Reviewed changes

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

File Description
internal/utils/deployment.go Added five deduplication functions and integrated them into the deployment override logic to prevent duplicate entries in environment variables, volumes, and secrets
internal/utils/deployment_test.go Added comprehensive unit tests for all deduplication functions covering various scenarios including duplicates, empty slices, and order preservation
internal/controller/propagation_controller.go Changed replica status monitoring requeue interval from 1 second to 5 seconds to reduce reconciliation frequency
go.mod Added stretchr/testify dependency for improved test assertions and gopkg.in/yaml.v3 as indirect dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +83
// Keep only the last occurrence
for i, ef := range envFrom {
if key := getEnvFromKey(ef); key != "" && seen[key] == i {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The deduplicateEnvFrom function silently drops EnvFromSource entries that have neither ConfigMapRef nor SecretRef (when getEnvFromKey returns empty string). This could lead to unexpected behavior if such entries exist. Consider either documenting this behavior in the function comment, or handling entries with empty keys by keeping them without deduplication.

Suggested change
// Keep only the last occurrence
for i, ef := range envFrom {
if key := getEnvFromKey(ef); key != "" && seen[key] == i {
// Keep only the last occurrence; keep entries without a key as-is
for i, ef := range envFrom {
if key := getEnvFromKey(ef); key == "" || seen[key] == i {

Copilot uses AI. Check for mistakes.
@galt-tr galt-tr assigned galt-tr and unassigned mrz1836 Jan 28, 2026
@mrz1836 mrz1836 removed their request for review January 29, 2026 19:36
galt-tr and others added 5 commits February 4, 2026 08:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

@galt-tr galt-tr merged commit 1514602 into bsv-blockchain:master Feb 4, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork-pr PR originated from a forked repository requires-manual-review PR or issue requires manual review by a maintainer or security team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants