Skip to content

Fix canary target group settings copy#194

Merged
YoungJinJung merged 6 commits into
mainfrom
feature/copy-canary-target-group-settings
Jul 1, 2026
Merged

Fix canary target group settings copy#194
YoungJinJung merged 6 commits into
mainfrom
feature/copy-canary-target-group-settings

Conversation

@YoungJinJung

@YoungJinJung YoungJinJung commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Copy target group creation settings when creating a canary target group
  • Copy target group attributes after canary target group creation
  • Set the Makefile release version to 2.2.1

Root cause

The canary target group was created with only name, port, protocol, and VPC ID. Health check settings, target type, protocol version, IP address type, matcher, and target group attributes could fall back to AWS defaults instead of matching the original target group.

Validation

  • /opt/homebrew/bin/go test ./...

Summary by CodeRabbit

  • Bug Fixes

    • Improved target group creation to carry over more settings and attributes when cloning configuration.
    • Added a safeguard so deployment fails cleanly if no target groups are returned.
    • Skips the deployment summary step for complete canary runs, matching expected behavior.
  • Chores

    • Updated the app version shown in build outputs and version commands.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6a95c6ac-d54f-410e-97bb-30e108bddd39

📥 Commits

Reviewing files that changed from the base of the PR and between c57cdb4 and fe94646.

📒 Files selected for processing (1)
  • pkg/runner/runner.go

📝 Walkthrough

Walkthrough

The Makefile VERSION variable was downgraded from 3.0.0 to 2.2.1. ELBV2 target group creation was reworked to copy configuration and attributes from a source target group via new helper functions and client methods, with an accompanying unit test. Runner.Deploy now conditionally skips summary printing when CompleteCanary is set.

Changes

Target Group Attribute Copy

Layer / File(s) Summary
Target group input builder and creation flow
pkg/aws/elbv2.go
BuildCreateTargetGroupInput copies configuration fields from a source TargetGroup; CreateTargetGroup uses it, validates the create response, and conditionally copies attributes from the source ARN to the new ARN.
Attribute get/set client methods
pkg/aws/elbv2.go
New DescribeTargetGroupAttributes and ModifyTargetGroupAttributes methods wrap the corresponding AWS SDK calls.
Tests for input builder
pkg/aws/elbv2_test.go
New test TestBuildCreateTargetGroupInputCopiesSettings verifies field copying, with an added AWS SDK import for pointer value construction.

Canary Summary Print Gating

Layer / File(s) Summary
Guarded summary print
pkg/runner/runner.go
Runner.Deploy now skips PrintSummary when CompleteCanary is true, running it otherwise.

Makefile Version Bump

Layer / File(s) Summary
Version variable update
Makefile
VERSION changed from 3.0.0 to 2.2.1, affecting the ldflags-injected build version.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ELBV2Client
  participant AWSELBV2API

  Caller->>ELBV2Client: CreateTargetGroup(tg, tgName)
  ELBV2Client->>ELBV2Client: BuildCreateTargetGroupInput(tg, tgName)
  ELBV2Client->>AWSELBV2API: CreateTargetGroup(input)
  AWSELBV2API-->>ELBV2Client: new TargetGroupArn
  alt source and new ARN present
    ELBV2Client->>AWSELBV2API: DescribeTargetGroupAttributes(sourceArn)
    AWSELBV2API-->>ELBV2Client: attributes
    alt attributes not empty
      ELBV2Client->>AWSELBV2API: ModifyTargetGroupAttributes(newArn, attributes)
    end
  end
  ELBV2Client-->>Caller: created target group
Loading

Related issues: None found in the provided context.

Related PRs: None found in the provided context.

Suggested labels: enhancement, aws, tests

Suggested reviewers: None found in the provided context.

🐰 hop, hop, through the ELBV2 code,
attributes copied down the road,
a version dips from three to two,
and canary print skips its cue.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing canary target group settings copying.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/copy-canary-target-group-settings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@YoungJinJung
YoungJinJung marked this pull request as ready for review July 1, 2026 02:52

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The changes properly implement comprehensive target group settings replication for canary deployments. The refactored CreateTargetGroup function now copies all health check settings, target type, protocol version, IP address type, matcher, and custom attributes from the original target group to the canary target group, addressing the root cause where these settings previously fell back to AWS defaults. The implementation includes appropriate error handling and comprehensive test coverage.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/aws/elbv2_test.go (1)

50-125: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add coverage for the attribute-copy flow.

This test covers the input builder, but the PR’s main regression also depends on CreateTargetGroup calling describe/modify attributes after creation. Add a test that verifies source attributes are applied to the new target group ARN.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/aws/elbv2_test.go` around lines 50 - 125, Add a test that covers the
attribute-copy flow in CreateTargetGroup, not just BuildCreateTargetGroupInput.
Verify that after the target group is created, CreateTargetGroup uses the
returned target group ARN to call the describe/modify attributes path and
applies the source attributes to the new group. Use the existing
CreateTargetGroup flow and its attribute-handling helpers to locate the code,
and assert the new ARN receives the copied attributes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/aws/elbv2.go`:
- Line 141: The create-target-group response is indexed directly in the ELBv2
flow, which can panic if no target groups are returned. Update the target group
creation logic around the create response in elbv2.go to check that
result.TargetGroups has at least one entry before taking the first element, and
return a typed error from the same path instead of assuming success. Keep the
fix localized to the code that assigns newTargetGroup so the canary flow fails
safely when the SDK response is empty.
- Around line 146-156: `CreateTargetGroup` currently returns immediately if
`ModifyTargetGroupAttributes` fails, which can leave the newly created target
group orphaned. Update the error path in `CreateTargetGroup` in
`pkg/aws/elbv2.go` to call `DeleteTargetGroup` on
`newTargetGroup.TargetGroupArn` before returning the error, and make sure any
rollback failure is handled/logged without hiding the original attribute-copy
error. Keep the fix localized around the `DescribeTargetGroupAttributes` and
`ModifyTargetGroupAttributes` flow.

---

Nitpick comments:
In `@pkg/aws/elbv2_test.go`:
- Around line 50-125: Add a test that covers the attribute-copy flow in
CreateTargetGroup, not just BuildCreateTargetGroupInput. Verify that after the
target group is created, CreateTargetGroup uses the returned target group ARN to
call the describe/modify attributes path and applies the source attributes to
the new group. Use the existing CreateTargetGroup flow and its
attribute-handling helpers to locate the code, and assert the new ARN receives
the copied attributes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 120f1c73-9dd8-4606-a124-05ce385aa746

📥 Commits

Reviewing files that changed from the base of the PR and between dda3d7f and f42189c.

📒 Files selected for processing (3)
  • Makefile
  • pkg/aws/elbv2.go
  • pkg/aws/elbv2_test.go

Comment thread pkg/aws/elbv2.go
Comment thread pkg/aws/elbv2.go
Comment on lines +146 to +156
attributes, err := e.DescribeTargetGroupAttributes(tg.TargetGroupArn)
if err != nil {
return nil, err
}

return &result.TargetGroups[0], nil
if len(attributes) == 0 {
return newTargetGroup, nil
}

if err := e.ModifyTargetGroupAttributes(newTargetGroup.TargetGroupArn, attributes); err != nil {
return nil, err

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether a target-group delete helper already exists for rollback.
rg -nP 'DeleteTargetGroup\s*\(|func \(e ELBV2Client\) DeleteTargetGroup' pkg/aws pkg/deployer

Repository: DevopsArtFactory/goployer

Length of output: 576


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target-group creation flow around the reported lines.
sed -n '110,190p' pkg/aws/elbv2.go

# Inspect the delete helper implementation.
sed -n '210,240p' pkg/aws/elbv2.go

# Inspect the caller to see whether it already cleans up on create/copy failures.
sed -n '780,930p' pkg/deployer/canary.go

Repository: DevopsArtFactory/goployer

Length of output: 8481


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target-group copy path for cleanup on failures.
rg -n "func \(c \*Canary\) CopyTargetGroups|CopyTargetGroups\(" pkg/deployer/canary.go
sed -n '640,760p' pkg/deployer/canary.go

# Check whether canary target-group names are reused across retries.
rg -n "GenerateCanaryTargetGroupName|canaryVersion" pkg/deployer/canary.go

Repository: DevopsArtFactory/goployer

Length of output: 5410


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the full target-group copy implementation and nearby helpers.
sed -n '428,520p' pkg/deployer/canary.go

# Inspect the call site around the copy/deploy flow for retry/error handling.
sed -n '100,150p' pkg/deployer/canary.go

Repository: DevopsArtFactory/goployer

Length of output: 4550


Rollback the new target group if attribute copy fails.
CreateTargetGroup can succeed before the attribute copy step, so returning the error here leaves an orphaned AWS target group behind and makes a retry hit a name conflict. Call DeleteTargetGroup on the newly created ARN before returning.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/aws/elbv2.go` around lines 146 - 156, `CreateTargetGroup` currently
returns immediately if `ModifyTargetGroupAttributes` fails, which can leave the
newly created target group orphaned. Update the error path in
`CreateTargetGroup` in `pkg/aws/elbv2.go` to call `DeleteTargetGroup` on
`newTargetGroup.TargetGroupArn` before returning the error, and make sure any
rollback failure is handled/logged without hiding the original attribute-copy
error. Keep the fix localized around the `DescribeTargetGroupAttributes` and
`ModifyTargetGroupAttributes` flow.

@YoungJinJung

Copy link
Copy Markdown
Contributor Author

/coderabbit review

@YoungJinJung
YoungJinJung merged commit 3cb2cc1 into main Jul 1, 2026
2 checks passed
@YoungJinJung
YoungJinJung deleted the feature/copy-canary-target-group-settings branch July 1, 2026 07:05
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.

1 participant