Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ack_generate_info:
build_date: "2026-05-30T22:41:57Z"
build_hash: a307e8ebd9503616baf5915c744a30dc3aa227c5
go_version: go1.26.3
version: v0.59.1-4-ga307e8e
build_date: "2026-06-12T02:08:23Z"
build_hash: 2970ca9b3789515150e27ab80630175a8c77cba4
go_version: go1.26.4
version: v0.59.1-7-g2970ca9
api_directory_checksum: 060554dd6962e2466013922cf96fb4cf92a23706
api_version: v1alpha1
aws_sdk_go_version: v1.32.6
generator_config_info:
file_checksum: ce1168f649f03d9652bc8e82f8322d6dd2d909f0
file_checksum: bac271c7c08e6fc537c9665c20dbf2e37270ddd3
original_file_name: generator.yaml
last_modification:
reason: API generation
2 changes: 2 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ resources:
tags:
ignore: true
hooks:
delta_pre_compare:
code: customPreCompare(delta, a, b)
sdk_read_many_post_build_request:
template_path: hooks/listener/sdk_read_many_post_build_request.go.tpl
TargetGroup:
Expand Down
2 changes: 2 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ resources:
tags:
ignore: true
hooks:
delta_pre_compare:
code: customPreCompare(delta, a, b)
sdk_read_many_post_build_request:
template_path: hooks/listener/sdk_read_many_post_build_request.go.tpl
TargetGroup:
Expand Down
1 change: 1 addition & 0 deletions pkg/resource/listener/delta.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions pkg/resource/listener/hooks.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package listener

import (
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
)

const (
// AnnotationWeightManagement controls how the controller manages forward
// action weights for target groups. When set to "ignore", the controller
// will not reconcile weight differences — allowing an external controller
// or deployment tool to manage blue/green traffic shifting independently.
AnnotationWeightManagement = "elbv2.services.k8s.aws/weight-management"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feels like this is a use case off ignore-deltas for specific fields? cc @michaelhtm @knottnt - if yes, i think we need a generic solution for all controllers

)

// customCheckRequiredFieldsMissingMethod returns true if there are any fields
// for the ReadOne Input shape that are required but not present in the
// resource's Spec or Status.
Expand All @@ -8,3 +20,65 @@ func (rm *resourceManager) customCheckRequiredFieldsMissingMethod(
) bool {
return r.Identifiers().ARN() == nil
}

// customPreCompare is the delta_pre_compare hook. When weight management is
// ignored, it copies the AWS-side weights into the desired spec so that the
// DeepEqual comparison on DefaultActions does not flag external weight
// changes as drift.
func customPreCompare(
delta *ackcompare.Delta,
a *resource,
b *resource,
) {
if isWeightManagementIgnored(a) {
mergeLatestWeights(a, b)
}
}

// isWeightManagementIgnored returns true if the resource has the
// AnnotationWeightManagement annotation set to "ignore", indicating that
// target group weights should be managed by an external controller.
func isWeightManagementIgnored(r *resource) bool {
if r == nil || r.ko == nil {
return false
}
annotations := r.ko.GetAnnotations()
if annotations == nil {
return false
}
return annotations[AnnotationWeightManagement] == "ignore"
}

// mergeLatestWeights copies the TargetGroup weights from the latest (AWS)
// state into the desired resource. This prevents external weight changes
// from being detected as drift and from being overwritten during updates.
func mergeLatestWeights(desired, latest *resource) {
if latest == nil || latest.ko == nil || desired == nil || desired.ko == nil {
return
}
// Build a map from TargetGroupARN to Weight from the latest (AWS) state
latestWeights := map[string]*int64{}
for _, action := range latest.ko.Spec.DefaultActions {
if action != nil && action.ForwardConfig != nil {
for _, tg := range action.ForwardConfig.TargetGroups {
if tg.TargetGroupARN != nil {
latestWeights[*tg.TargetGroupARN] = tg.Weight
}
}
}
}

// Overwrite desired weights with latest weights for any target group
// that exists in both desired and latest.
for _, action := range desired.ko.Spec.DefaultActions {
if action != nil && action.ForwardConfig != nil {
for _, tg := range action.ForwardConfig.TargetGroups {
if tg.TargetGroupARN != nil {
if w, ok := latestWeights[*tg.TargetGroupARN]; ok {
tg.Weight = w
}
}
}
}
}
}
Loading