From e44d959cc1fcb384e97f71c8ea543336170feb38 Mon Sep 17 00:00:00 2001 From: Youssef Omar Bouden Date: Tue, 13 Oct 2026 11:05:19 +0100 Subject: [PATCH 1/3] fix(listener): stop perpetual diff on server-filled default actions DescribeListeners returns default actions with members the spec never declared: an Order for every action, a ForwardConfig with weight 1 and stickiness disabled for a bare targetGroupARN, the #{...} keywords for unset redirect components and the authentication defaults, while the k8s-only targetGroupRef and the OIDC client secret never come back. The generated DeepEqual on Spec.DefaultActions therefore reported a diff on every reconcile and drove a no-op ModifyListener each time. Skip the generated comparison and compare DefaultActions in a delta_pre_compare hook on copies with those members removed, the same shape #63 uses for Rule actions. Signed-off-by: Youssef Omar Bouden --- apis/v1alpha1/ack-generate-metadata.yaml | 2 +- apis/v1alpha1/generator.yaml | 5 + generator.yaml | 5 + pkg/resource/listener/delta.go | 8 +- pkg/resource/listener/hooks.go | 134 ++++++++++++ pkg/resource/listener/hooks_test.go | 248 +++++++++++++++++++++++ 6 files changed, 394 insertions(+), 8 deletions(-) create mode 100644 pkg/resource/listener/hooks_test.go diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index 36f2908..3379211 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -7,7 +7,7 @@ api_directory_checksum: b90448fd5950eedbe16b579f98dc6b6b01781430 api_version: v1alpha1 aws_sdk_go_version: v1.32.6 generator_config_info: - file_checksum: ce1168f649f03d9652bc8e82f8322d6dd2d909f0 + file_checksum: 151e913bf0da745085d1dc4606cb0a36f227e9fc original_file_name: generator.yaml last_modification: reason: API generation diff --git a/apis/v1alpha1/generator.yaml b/apis/v1alpha1/generator.yaml index 0a32afd..654c6a1 100644 --- a/apis/v1alpha1/generator.yaml +++ b/apis/v1alpha1/generator.yaml @@ -132,6 +132,9 @@ resources: Listener: is_arn_primary_key: true fields: + DefaultActions: + compare: + is_ignored: true DefaultActions.TargetGroupARN: references: resource: TargetGroup @@ -165,6 +168,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: diff --git a/generator.yaml b/generator.yaml index 0a32afd..654c6a1 100644 --- a/generator.yaml +++ b/generator.yaml @@ -132,6 +132,9 @@ resources: Listener: is_arn_primary_key: true fields: + DefaultActions: + compare: + is_ignored: true DefaultActions.TargetGroupARN: references: resource: TargetGroup @@ -165,6 +168,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: diff --git a/pkg/resource/listener/delta.go b/pkg/resource/listener/delta.go index c306edb..121a8c4 100644 --- a/pkg/resource/listener/delta.go +++ b/pkg/resource/listener/delta.go @@ -41,6 +41,7 @@ func newResourceDelta( delta.Add("", a, b) return delta } + customPreCompare(delta, a, b) if len(a.ko.Spec.AlpnPolicy) != len(b.ko.Spec.AlpnPolicy) { delta.Add("Spec.AlpnPolicy", a.ko.Spec.AlpnPolicy, b.ko.Spec.AlpnPolicy) @@ -56,13 +57,6 @@ func newResourceDelta( delta.Add("Spec.Certificates", a.ko.Spec.Certificates, b.ko.Spec.Certificates) } } - if len(a.ko.Spec.DefaultActions) != len(b.ko.Spec.DefaultActions) { - delta.Add("Spec.DefaultActions", a.ko.Spec.DefaultActions, b.ko.Spec.DefaultActions) - } else if len(a.ko.Spec.DefaultActions) > 0 { - if !equality.Semantic.Equalities.DeepEqual(a.ko.Spec.DefaultActions, b.ko.Spec.DefaultActions) { - delta.Add("Spec.DefaultActions", a.ko.Spec.DefaultActions, b.ko.Spec.DefaultActions) - } - } if ackcompare.HasNilDifference(a.ko.Spec.LoadBalancerARN, b.ko.Spec.LoadBalancerARN) { delta.Add("Spec.LoadBalancerARN", a.ko.Spec.LoadBalancerARN, b.ko.Spec.LoadBalancerARN) } else if a.ko.Spec.LoadBalancerARN != nil && b.ko.Spec.LoadBalancerARN != nil { diff --git a/pkg/resource/listener/hooks.go b/pkg/resource/listener/hooks.go index 2be33ef..5508d74 100644 --- a/pkg/resource/listener/hooks.go +++ b/pkg/resource/listener/hooks.go @@ -1,5 +1,11 @@ package listener +import ( + svcapitypes "github.com/aws-controllers-k8s/elbv2-controller/apis/v1alpha1" + ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" + "k8s.io/apimachinery/pkg/api/equality" +) + // 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. @@ -8,3 +14,131 @@ func (rm *resourceManager) customCheckRequiredFieldsMissingMethod( ) bool { return r.Identifiers().ARN() == nil } + +func customPreCompare( + delta *ackcompare.Delta, + a *resource, + b *resource, +) { + customCompareDefaultActions(delta, a, b) +} + +// customCompareDefaultActions compares DefaultActions on copies without the +// k8s-only TargetGroupRef, the write-only OIDC client secret and the members +// DescribeListeners fills in when the spec leaves them unset. +func customCompareDefaultActions( + delta *ackcompare.Delta, + a *resource, + b *resource, +) { + if a == nil || b == nil { + return + } + desired := a.ko.Spec.DefaultActions + observed := b.ko.Spec.DefaultActions + if len(desired) != len(observed) { + delta.Add("Spec.DefaultActions", desired, observed) + return + } + for i := range desired { + if !defaultActionEqual(desired[i], observed[i]) { + delta.Add("Spec.DefaultActions", desired, observed) + return + } + } +} + +func defaultActionEqual(desired, observed *svcapitypes.Action) bool { + if desired == nil || observed == nil { + return desired == observed + } + d := desired.DeepCopy() + o := observed.DeepCopy() + d.TargetGroupRef, o.TargetGroupRef = nil, nil + if d.Order == nil { + o.Order = nil + } + if d.TargetGroupARN == nil { + o.TargetGroupARN = nil + } + if d.ForwardConfig == nil { + o.ForwardConfig = nil + } else if o.ForwardConfig != nil { + normalizeForwardConfig(d.ForwardConfig, o.ForwardConfig) + } + if d.RedirectConfig != nil && o.RedirectConfig != nil { + normalizeRedirectConfig(d.RedirectConfig, o.RedirectConfig) + } + if d.AuthenticateOIDCConfig != nil && o.AuthenticateOIDCConfig != nil { + normalizeOIDCConfig(d.AuthenticateOIDCConfig, o.AuthenticateOIDCConfig) + } + if d.AuthenticateCognitoConfig != nil && o.AuthenticateCognitoConfig != nil { + normalizeCognitoConfig(d.AuthenticateCognitoConfig, o.AuthenticateCognitoConfig) + } + return equality.Semantic.Equalities.DeepEqual(d, o) +} + +func normalizeForwardConfig(d, o *svcapitypes.ForwardActionConfig) { + if d.TargetGroupStickinessConfig == nil { + o.TargetGroupStickinessConfig = nil + } + for i, tg := range d.TargetGroups { + if tg == nil || i >= len(o.TargetGroups) || o.TargetGroups[i] == nil { + continue + } + tg.TargetGroupRef, o.TargetGroups[i].TargetGroupRef = nil, nil + if tg.Weight == nil { + o.TargetGroups[i].Weight = nil + } + } +} + +func normalizeRedirectConfig(d, o *svcapitypes.RedirectActionConfig) { + if d.Host == nil { + o.Host = nil + } + if d.Path == nil { + o.Path = nil + } + if d.Port == nil { + o.Port = nil + } + if d.Protocol == nil { + o.Protocol = nil + } + if d.Query == nil { + o.Query = nil + } +} + +func normalizeOIDCConfig(d, o *svcapitypes.AuthenticateOIDCActionConfig) { + d.ClientSecret, o.ClientSecret = nil, nil + d.UseExistingClientSecret, o.UseExistingClientSecret = nil, nil + if d.OnUnauthenticatedRequest == nil { + o.OnUnauthenticatedRequest = nil + } + if d.Scope == nil { + o.Scope = nil + } + if d.SessionCookieName == nil { + o.SessionCookieName = nil + } + if d.SessionTimeout == nil { + o.SessionTimeout = nil + } +} + +func normalizeCognitoConfig(d, o *svcapitypes.AuthenticateCognitoActionConfig) { + if d.OnUnauthenticatedRequest == nil { + o.OnUnauthenticatedRequest = nil + } + if d.Scope == nil { + o.Scope = nil + } + if d.SessionCookieName == nil { + o.SessionCookieName = nil + } + if d.SessionTimeout == nil { + o.SessionTimeout = nil + } +} diff --git a/pkg/resource/listener/hooks_test.go b/pkg/resource/listener/hooks_test.go new file mode 100644 index 0000000..7d319bd --- /dev/null +++ b/pkg/resource/listener/hooks_test.go @@ -0,0 +1,248 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package listener + +import ( + "testing" + + ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/stretchr/testify/assert" + + svcapitypes "github.com/aws-controllers-k8s/elbv2-controller/apis/v1alpha1" +) + +func tgRef(name string) *ackv1alpha1.AWSResourceReferenceWrapper { + return &ackv1alpha1.AWSResourceReferenceWrapper{ + From: &ackv1alpha1.AWSResourceReference{Name: aws.String(name)}, + } +} + +// forwardAsReturned is the shape DescribeListeners returns for a forward +// action that was created with a single target group. +func forwardAsReturned(order int64, arn string) *svcapitypes.Action { + return &svcapitypes.Action{ + Type: aws.String("forward"), + Order: aws.Int64(order), + TargetGroupARN: aws.String(arn), + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + {TargetGroupARN: aws.String(arn), Weight: aws.Int64(1)}, + }, + TargetGroupStickinessConfig: &svcapitypes.TargetGroupStickinessConfig{ + Enabled: aws.Bool(false), + }, + }, + } +} + +func weightedForward(order *int64, weightA, weightB int64) *svcapitypes.Action { + return &svcapitypes.Action{ + Type: aws.String("forward"), + Order: order, + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + {TargetGroupARN: aws.String("arn:tg/a"), Weight: aws.Int64(weightA)}, + {TargetGroupARN: aws.String("arn:tg/b"), Weight: aws.Int64(weightB)}, + }, + TargetGroupStickinessConfig: &svcapitypes.TargetGroupStickinessConfig{ + Enabled: aws.Bool(true), + DurationSeconds: aws.Int64(3600), + }, + }, + } +} + +func redirect(path *string) *svcapitypes.RedirectActionConfig { + return &svcapitypes.RedirectActionConfig{ + Protocol: aws.String("HTTPS"), + Port: aws.String("#{port}"), + Host: aws.String("#{host}"), + Path: path, + Query: aws.String("#{query}"), + StatusCode: aws.String("HTTP_301"), + } +} + +func oidc(secret *string, defaults bool) *svcapitypes.AuthenticateOIDCActionConfig { + cfg := &svcapitypes.AuthenticateOIDCActionConfig{ + Issuer: aws.String("https://idp.example.com"), + AuthorizationEndpoint: aws.String("https://idp.example.com/auth"), + TokenEndpoint: aws.String("https://idp.example.com/token"), + UserInfoEndpoint: aws.String("https://idp.example.com/userinfo"), + ClientID: aws.String("client-id"), + ClientSecret: secret, + } + if defaults { + cfg.OnUnauthenticatedRequest = aws.String("authenticate") + cfg.Scope = aws.String("openid") + cfg.SessionCookieName = aws.String("AWSELBAuthSessionCookie") + cfg.SessionTimeout = aws.Int64(604800) + } + return cfg +} + +func TestNewResourceDelta_DefaultActions(t *testing.T) { + tests := []struct { + name string + desired []*svcapitypes.Action + observed []*svcapitypes.Action + expectDelta bool + }{ + { + name: "targetGroupARN only, service adds order and forward config", + desired: []*svcapitypes.Action{ + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{forwardAsReturned(1, "arn:tg/a")}, + expectDelta: false, + }, + { + name: "targetGroupRef only, resolved ARN matches", + desired: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + TargetGroupRef: tgRef("my-tg"), + TargetGroupARN: aws.String("arn:tg/a"), + }, + }, + observed: []*svcapitypes.Action{forwardAsReturned(1, "arn:tg/a")}, + expectDelta: false, + }, + { + name: "forwardConfig with ref and no weight, service adds targetGroupARN weight and stickiness", + desired: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + {TargetGroupRef: tgRef("my-tg"), TargetGroupARN: aws.String("arn:tg/a")}, + }, + }, + }, + }, + observed: []*svcapitypes.Action{forwardAsReturned(1, "arn:tg/a")}, + expectDelta: false, + }, + { + name: "weighted forward config unchanged", + desired: []*svcapitypes.Action{weightedForward(nil, 90, 10)}, + observed: []*svcapitypes.Action{weightedForward(aws.Int64(1), 90, 10)}, + expectDelta: false, + }, + { + name: "weights changed on the load balancer", + desired: []*svcapitypes.Action{weightedForward(nil, 90, 10)}, + observed: []*svcapitypes.Action{weightedForward(aws.Int64(1), 50, 50)}, + expectDelta: true, + }, + { + name: "target group changed", + desired: []*svcapitypes.Action{ + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/b")}, + }, + observed: []*svcapitypes.Action{forwardAsReturned(1, "arn:tg/a")}, + expectDelta: true, + }, + { + name: "explicit order differs", + desired: []*svcapitypes.Action{ + {Type: aws.String("forward"), Order: aws.Int64(2), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{forwardAsReturned(1, "arn:tg/a")}, + expectDelta: true, + }, + { + name: "redirect with service keyword defaults", + desired: []*svcapitypes.Action{ + { + Type: aws.String("redirect"), + RedirectConfig: &svcapitypes.RedirectActionConfig{ + Protocol: aws.String("HTTPS"), + StatusCode: aws.String("HTTP_301"), + }, + }, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("redirect"), Order: aws.Int64(1), RedirectConfig: redirect(aws.String("/#{path}"))}, + }, + expectDelta: false, + }, + { + name: "redirect path changed", + desired: []*svcapitypes.Action{ + {Type: aws.String("redirect"), RedirectConfig: redirect(aws.String("/new/#{path}"))}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("redirect"), Order: aws.Int64(1), RedirectConfig: redirect(aws.String("/#{path}"))}, + }, + expectDelta: true, + }, + { + name: "authenticate-oidc then forward, secret not returned and defaults filled", + desired: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), AuthenticateOIDCConfig: oidc(aws.String("s3cret"), false)}, + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), Order: aws.Int64(1), AuthenticateOIDCConfig: oidc(nil, true)}, + forwardAsReturned(2, "arn:tg/a"), + }, + expectDelta: false, + }, + { + name: "action type changed", + desired: []*svcapitypes.Action{ + { + Type: aws.String("fixed-response"), + FixedResponseConfig: &svcapitypes.FixedResponseActionConfig{StatusCode: aws.String("503")}, + }, + }, + observed: []*svcapitypes.Action{forwardAsReturned(1, "arn:tg/a")}, + expectDelta: true, + }, + { + name: "action count differs", + desired: []*svcapitypes.Action{ + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), Order: aws.Int64(1), AuthenticateOIDCConfig: oidc(nil, true)}, + forwardAsReturned(2, "arn:tg/a"), + }, + expectDelta: true, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + desired := &resource{ + ko: &svcapitypes.Listener{ + Spec: svcapitypes.ListenerSpec{DefaultActions: tc.desired}, + }, + } + observed := &resource{ + ko: &svcapitypes.Listener{ + Spec: svcapitypes.ListenerSpec{DefaultActions: tc.observed}, + }, + } + + delta := newResourceDelta(desired, observed) + assert.Equal(t, tc.expectDelta, delta.DifferentAt("Spec.DefaultActions"), + "Spec.DefaultActions delta mismatch") + assert.Equal(t, tc.expectDelta, delta.DifferentAt("Spec"), + "unexpected delta outside Spec.DefaultActions: %v", delta.Differences) + }) + } +} From 25acd16714374884e82e675dd20009189d360a7a Mon Sep 17 00:00:00 2001 From: Youssef Omar Bouden Date: Wed, 4 Nov 2026 11:16:16 +0100 Subject: [PATCH 2/3] fix(listener): compare default actions in the service's form and keep the declared form in the spec The comparator now fills both sides with the members DescribeListeners returns for unset ones (order, the one-entry forwardConfig and action-level targetGroupARN, weight 1, stickiness disabled, the redirect keywords, text/plain, the OIDC and Cognito session defaults), sorts target groups by ARN, and leaves out only the k8s-only references and the OIDC client secret, so a member removed from the spec reaches ModifyListener and a reordered weighted forward does not. DefaultActions is no longer written back from the Create and Update responses, so an HTTPS listener keeps its declared form while ReadOne still fills latest. Regenerated with code-generator v0.67.0 after merging main. Signed-off-by: Youssef Omar Bouden --- apis/v1alpha1/ack-generate-metadata.yaml | 2 +- apis/v1alpha1/generator.yaml | 6 + generator.yaml | 6 + pkg/resource/listener/hooks.go | 201 +++++++++------ pkg/resource/listener/hooks_test.go | 124 +++++++++ pkg/resource/listener/sdk.go | 306 ----------------------- 6 files changed, 264 insertions(+), 381 deletions(-) diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index b2a05a4..c76e70b 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -7,7 +7,7 @@ api_directory_checksum: b90448fd5950eedbe16b579f98dc6b6b01781430 api_version: v1alpha1 aws_sdk_go_version: v1.32.6 generator_config_info: - file_checksum: 151e913bf0da745085d1dc4606cb0a36f227e9fc + file_checksum: 7d389c6806d2b7836e782bcdbad062dad7aca952 original_file_name: generator.yaml last_modification: reason: API generation diff --git a/apis/v1alpha1/generator.yaml b/apis/v1alpha1/generator.yaml index 654c6a1..d99bd00 100644 --- a/apis/v1alpha1/generator.yaml +++ b/apis/v1alpha1/generator.yaml @@ -135,6 +135,12 @@ resources: DefaultActions: compare: is_ignored: true + # keep the declared form in the spec; ReadOne still fills latest + set: + - method: Create + ignore: from + - method: Update + ignore: from DefaultActions.TargetGroupARN: references: resource: TargetGroup diff --git a/generator.yaml b/generator.yaml index 654c6a1..d99bd00 100644 --- a/generator.yaml +++ b/generator.yaml @@ -135,6 +135,12 @@ resources: DefaultActions: compare: is_ignored: true + # keep the declared form in the spec; ReadOne still fills latest + set: + - method: Create + ignore: from + - method: Update + ignore: from DefaultActions.TargetGroupARN: references: resource: TargetGroup diff --git a/pkg/resource/listener/hooks.go b/pkg/resource/listener/hooks.go index 5508d74..23c2f22 100644 --- a/pkg/resource/listener/hooks.go +++ b/pkg/resource/listener/hooks.go @@ -1,8 +1,11 @@ package listener import ( + "sort" + svcapitypes "github.com/aws-controllers-k8s/elbv2-controller/apis/v1alpha1" ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" + "github.com/aws/aws-sdk-go-v2/aws" "k8s.io/apimachinery/pkg/api/equality" ) @@ -23,9 +26,13 @@ func customPreCompare( customCompareDefaultActions(delta, a, b) } -// customCompareDefaultActions compares DefaultActions on copies without the -// k8s-only TargetGroupRef, the write-only OIDC client secret and the members -// DescribeListeners fills in when the spec leaves them unset. +// customCompareDefaultActions compares DefaultActions in the form +// DescribeListeners reports them: both sides get the members the service +// fills in when the spec leaves them unset, target groups are sorted by ARN, +// and the members the service never returns (the k8s-only references and the +// OIDC client secret) are left out. A member removed from the spec then +// differs from the value still on the load balancer and reaches +// ModifyListener. func customCompareDefaultActions( delta *ackcompare.Delta, a *resource, @@ -36,109 +43,155 @@ func customCompareDefaultActions( } desired := a.ko.Spec.DefaultActions observed := b.ko.Spec.DefaultActions - if len(desired) != len(observed) { + if !equality.Semantic.DeepEqual(normalizeActions(desired), normalizeActions(observed)) { delta.Add("Spec.DefaultActions", desired, observed) - return } - for i := range desired { - if !defaultActionEqual(desired[i], observed[i]) { - delta.Add("Spec.DefaultActions", desired, observed) - return +} + +// normalizeActions returns copies of actions in the form DescribeListeners +// returns them. +func normalizeActions(actions []*svcapitypes.Action) []*svcapitypes.Action { + out := make([]*svcapitypes.Action, len(actions)) + for i, action := range actions { + if action == nil { + continue } - } + c := action.DeepCopy() + c.TargetGroupRef = nil + if c.Order == nil { + c.Order = aws.Int64(int64(i + 1)) + } + normalizeForward(c) + normalizeRedirect(c.RedirectConfig) + normalizeFixedResponse(c.FixedResponseConfig) + normalizeOIDC(c.AuthenticateOIDCConfig) + normalizeCognito(c.AuthenticateCognitoConfig) + out[i] = c + } + return out } -func defaultActionEqual(desired, observed *svcapitypes.Action) bool { - if desired == nil || observed == nil { - return desired == observed - } - d := desired.DeepCopy() - o := observed.DeepCopy() - d.TargetGroupRef, o.TargetGroupRef = nil, nil - if d.Order == nil { - o.Order = nil - } - if d.TargetGroupARN == nil { - o.TargetGroupARN = nil +// normalizeForward fills the forward members the service returns: a forward +// with only targetGroupARN comes back with a one-entry forwardConfig, a +// one-entry forwardConfig comes back with the action-level targetGroupARN, +// an unset weight is 1 and unset stickiness is disabled. Target groups are +// returned in ARN order, not declared order. +func normalizeForward(c *svcapitypes.Action) { + if c.ForwardConfig == nil && c.TargetGroupARN != nil { + c.ForwardConfig = &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{{TargetGroupARN: c.TargetGroupARN}}, + } } - if d.ForwardConfig == nil { - o.ForwardConfig = nil - } else if o.ForwardConfig != nil { - normalizeForwardConfig(d.ForwardConfig, o.ForwardConfig) + fc := c.ForwardConfig + if fc == nil { + return } - if d.RedirectConfig != nil && o.RedirectConfig != nil { - normalizeRedirectConfig(d.RedirectConfig, o.RedirectConfig) + if fc.TargetGroupStickinessConfig == nil { + fc.TargetGroupStickinessConfig = &svcapitypes.TargetGroupStickinessConfig{} } - if d.AuthenticateOIDCConfig != nil && o.AuthenticateOIDCConfig != nil { - normalizeOIDCConfig(d.AuthenticateOIDCConfig, o.AuthenticateOIDCConfig) + if fc.TargetGroupStickinessConfig.Enabled == nil { + fc.TargetGroupStickinessConfig.Enabled = aws.Bool(false) } - if d.AuthenticateCognitoConfig != nil && o.AuthenticateCognitoConfig != nil { - normalizeCognitoConfig(d.AuthenticateCognitoConfig, o.AuthenticateCognitoConfig) + if !*fc.TargetGroupStickinessConfig.Enabled { + fc.TargetGroupStickinessConfig.DurationSeconds = nil } - return equality.Semantic.Equalities.DeepEqual(d, o) -} - -func normalizeForwardConfig(d, o *svcapitypes.ForwardActionConfig) { - if d.TargetGroupStickinessConfig == nil { - o.TargetGroupStickinessConfig = nil - } - for i, tg := range d.TargetGroups { - if tg == nil || i >= len(o.TargetGroups) || o.TargetGroups[i] == nil { + for _, tg := range fc.TargetGroups { + if tg == nil { continue } - tg.TargetGroupRef, o.TargetGroups[i].TargetGroupRef = nil, nil + tg.TargetGroupRef = nil if tg.Weight == nil { - o.TargetGroups[i].Weight = nil + tg.Weight = aws.Int64(1) } } + sort.SliceStable(fc.TargetGroups, func(i, j int) bool { + return targetGroupARN(fc.TargetGroups[i]) < targetGroupARN(fc.TargetGroups[j]) + }) + if c.TargetGroupARN == nil && len(fc.TargetGroups) == 1 && fc.TargetGroups[0] != nil { + c.TargetGroupARN = fc.TargetGroups[0].TargetGroupARN + } } -func normalizeRedirectConfig(d, o *svcapitypes.RedirectActionConfig) { - if d.Host == nil { - o.Host = nil +func targetGroupARN(tg *svcapitypes.TargetGroupTuple) string { + if tg == nil { + return "" } - if d.Path == nil { - o.Path = nil + return aws.ToString(tg.TargetGroupARN) +} + +// normalizeRedirect fills the keyword the service returns for each unset +// redirect component. +func normalizeRedirect(r *svcapitypes.RedirectActionConfig) { + if r == nil { + return + } + if r.Protocol == nil { + r.Protocol = aws.String("#{protocol}") + } + if r.Port == nil { + r.Port = aws.String("#{port}") + } + if r.Host == nil { + r.Host = aws.String("#{host}") + } + if r.Path == nil { + r.Path = aws.String("/#{path}") } - if d.Port == nil { - o.Port = nil + if r.Query == nil { + r.Query = aws.String("#{query}") } - if d.Protocol == nil { - o.Protocol = nil +} + +func normalizeFixedResponse(f *svcapitypes.FixedResponseActionConfig) { + if f == nil { + return } - if d.Query == nil { - o.Query = nil + if f.ContentType == nil { + f.ContentType = aws.String("text/plain") } } -func normalizeOIDCConfig(d, o *svcapitypes.AuthenticateOIDCActionConfig) { - d.ClientSecret, o.ClientSecret = nil, nil - d.UseExistingClientSecret, o.UseExistingClientSecret = nil, nil - if d.OnUnauthenticatedRequest == nil { - o.OnUnauthenticatedRequest = nil +// normalizeOIDC fills the session defaults and drops the client secret, which +// the service never returns: a spec that changes only the secret produces no +// delta and the new secret only reaches AWS with another change. +func normalizeOIDC(o *svcapitypes.AuthenticateOIDCActionConfig) { + if o == nil { + return } - if d.Scope == nil { - o.Scope = nil + o.ClientSecret = nil + o.UseExistingClientSecret = nil + if len(o.AuthenticationRequestExtraParams) == 0 { + o.AuthenticationRequestExtraParams = nil } - if d.SessionCookieName == nil { - o.SessionCookieName = nil + o.OnUnauthenticatedRequest, o.Scope, o.SessionCookieName, o.SessionTimeout = authDefaults( + o.OnUnauthenticatedRequest, o.Scope, o.SessionCookieName, o.SessionTimeout) +} + +func normalizeCognito(c *svcapitypes.AuthenticateCognitoActionConfig) { + if c == nil { + return } - if d.SessionTimeout == nil { - o.SessionTimeout = nil + if len(c.AuthenticationRequestExtraParams) == 0 { + c.AuthenticationRequestExtraParams = nil } + c.OnUnauthenticatedRequest, c.Scope, c.SessionCookieName, c.SessionTimeout = authDefaults( + c.OnUnauthenticatedRequest, c.Scope, c.SessionCookieName, c.SessionTimeout) } -func normalizeCognitoConfig(d, o *svcapitypes.AuthenticateCognitoActionConfig) { - if d.OnUnauthenticatedRequest == nil { - o.OnUnauthenticatedRequest = nil +// authDefaults returns the authenticate-oidc and authenticate-cognito session +// members with the service defaults filled in. +func authDefaults(onUnauthenticated, scope, cookie *string, timeout *int64) (*string, *string, *string, *int64) { + if onUnauthenticated == nil { + onUnauthenticated = aws.String("authenticate") } - if d.Scope == nil { - o.Scope = nil + if scope == nil { + scope = aws.String("openid") } - if d.SessionCookieName == nil { - o.SessionCookieName = nil + if cookie == nil { + cookie = aws.String("AWSELBAuthSessionCookie") } - if d.SessionTimeout == nil { - o.SessionTimeout = nil + if timeout == nil { + timeout = aws.Int64(604800) } + return onUnauthenticated, scope, cookie, timeout } diff --git a/pkg/resource/listener/hooks_test.go b/pkg/resource/listener/hooks_test.go index 7d319bd..d1c4b6d 100644 --- a/pkg/resource/listener/hooks_test.go +++ b/pkg/resource/listener/hooks_test.go @@ -93,6 +93,12 @@ func oidc(secret *string, defaults bool) *svcapitypes.AuthenticateOIDCActionConf return cfg } +func oidcWithScope(scope string) *svcapitypes.AuthenticateOIDCActionConfig { + cfg := oidc(nil, true) + cfg.Scope = aws.String(scope) + return cfg +} + func TestNewResourceDelta_DefaultActions(t *testing.T) { tests := []struct { name string @@ -212,6 +218,124 @@ func TestNewResourceDelta_DefaultActions(t *testing.T) { observed: []*svcapitypes.Action{forwardAsReturned(1, "arn:tg/a")}, expectDelta: true, }, + { + name: "stickiness removed from the spec must reach the load balancer", + desired: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + {TargetGroupARN: aws.String("arn:tg/a"), Weight: aws.Int64(90)}, + {TargetGroupARN: aws.String("arn:tg/b"), Weight: aws.Int64(10)}, + }, + }, + }, + }, + observed: []*svcapitypes.Action{weightedForward(aws.Int64(1), 90, 10)}, + expectDelta: true, + }, + { + name: "weight removed from the spec must reach the load balancer", + desired: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + {TargetGroupARN: aws.String("arn:tg/a")}, + {TargetGroupARN: aws.String("arn:tg/b"), Weight: aws.Int64(10)}, + }, + TargetGroupStickinessConfig: &svcapitypes.TargetGroupStickinessConfig{ + Enabled: aws.Bool(true), DurationSeconds: aws.Int64(3600), + }, + }, + }, + }, + observed: []*svcapitypes.Action{weightedForward(aws.Int64(1), 90, 10)}, + expectDelta: true, + }, + { + name: "target groups declared in another order than the service returns", + desired: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + {TargetGroupARN: aws.String("arn:tg/b"), Weight: aws.Int64(10)}, + {TargetGroupARN: aws.String("arn:tg/a"), Weight: aws.Int64(90)}, + }, + TargetGroupStickinessConfig: &svcapitypes.TargetGroupStickinessConfig{ + Enabled: aws.Bool(true), DurationSeconds: aws.Int64(3600), + }, + }, + }, + }, + observed: []*svcapitypes.Action{weightedForward(aws.Int64(1), 90, 10)}, + expectDelta: false, + }, + { + name: "redirect host removed from the spec must reach the load balancer", + desired: []*svcapitypes.Action{ + {Type: aws.String("redirect"), RedirectConfig: &svcapitypes.RedirectActionConfig{ + Protocol: aws.String("HTTPS"), StatusCode: aws.String("HTTP_301"), + }}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("redirect"), Order: aws.Int64(1), RedirectConfig: &svcapitypes.RedirectActionConfig{ + Protocol: aws.String("HTTPS"), Port: aws.String("#{port}"), Host: aws.String("www.example.com"), + Path: aws.String("/#{path}"), Query: aws.String("#{query}"), StatusCode: aws.String("HTTP_301"), + }}, + }, + expectDelta: true, + }, + { + name: "fixed response without contentType, service fills text/plain", + desired: []*svcapitypes.Action{ + {Type: aws.String("fixed-response"), FixedResponseConfig: &svcapitypes.FixedResponseActionConfig{StatusCode: aws.String("503")}}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("fixed-response"), Order: aws.Int64(1), FixedResponseConfig: &svcapitypes.FixedResponseActionConfig{ + StatusCode: aws.String("503"), ContentType: aws.String("text/plain"), + }}, + }, + expectDelta: false, + }, + { + name: "oidc scope removed from the spec must reach the load balancer", + desired: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), AuthenticateOIDCConfig: oidc(aws.String("s3cret"), false)}, + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), Order: aws.Int64(1), AuthenticateOIDCConfig: oidcWithScope("email openid")}, + forwardAsReturned(2, "arn:tg/a"), + }, + expectDelta: true, + }, + { + name: "oidc secret changed alone produces no delta, the service never returns it", + desired: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), AuthenticateOIDCConfig: oidc(aws.String("rotated"), false)}, + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), Order: aws.Int64(1), AuthenticateOIDCConfig: oidc(nil, true)}, + forwardAsReturned(2, "arn:tg/a"), + }, + expectDelta: false, + }, + { + name: "single action without order from the service", + desired: []*svcapitypes.Action{ + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{ + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/a"), ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{{TargetGroupARN: aws.String("arn:tg/a"), Weight: aws.Int64(1)}}, + TargetGroupStickinessConfig: &svcapitypes.TargetGroupStickinessConfig{Enabled: aws.Bool(false)}, + }}, + }, + expectDelta: false, + }, { name: "action count differs", desired: []*svcapitypes.Action{ diff --git a/pkg/resource/listener/sdk.go b/pkg/resource/listener/sdk.go index eee185f..34bd24c 100644 --- a/pkg/resource/listener/sdk.go +++ b/pkg/resource/listener/sdk.go @@ -399,159 +399,6 @@ func (rm *resourceManager) sdkCreate( } else { ko.Spec.Certificates = nil } - if elem.DefaultActions != nil { - f2 := []*svcapitypes.Action{} - for _, f2iter := range elem.DefaultActions { - f2elem := &svcapitypes.Action{} - if f2iter.AuthenticateCognitoConfig != nil { - f2elemf0 := &svcapitypes.AuthenticateCognitoActionConfig{} - if f2iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams != nil { - f2elemf0.AuthenticationRequestExtraParams = aws.StringMap(f2iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams) - } - if f2iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest != "" { - f2elemf0.OnUnauthenticatedRequest = aws.String(string(f2iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest)) - } - if f2iter.AuthenticateCognitoConfig.Scope != nil { - f2elemf0.Scope = f2iter.AuthenticateCognitoConfig.Scope - } - if f2iter.AuthenticateCognitoConfig.SessionCookieName != nil { - f2elemf0.SessionCookieName = f2iter.AuthenticateCognitoConfig.SessionCookieName - } - if f2iter.AuthenticateCognitoConfig.SessionTimeout != nil { - f2elemf0.SessionTimeout = f2iter.AuthenticateCognitoConfig.SessionTimeout - } - if f2iter.AuthenticateCognitoConfig.UserPoolArn != nil { - f2elemf0.UserPoolARN = f2iter.AuthenticateCognitoConfig.UserPoolArn - } - if f2iter.AuthenticateCognitoConfig.UserPoolClientId != nil { - f2elemf0.UserPoolClientID = f2iter.AuthenticateCognitoConfig.UserPoolClientId - } - if f2iter.AuthenticateCognitoConfig.UserPoolDomain != nil { - f2elemf0.UserPoolDomain = f2iter.AuthenticateCognitoConfig.UserPoolDomain - } - f2elem.AuthenticateCognitoConfig = f2elemf0 - } - if f2iter.AuthenticateOidcConfig != nil { - f2elemf1 := &svcapitypes.AuthenticateOIDCActionConfig{} - if f2iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams != nil { - f2elemf1.AuthenticationRequestExtraParams = aws.StringMap(f2iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams) - } - if f2iter.AuthenticateOidcConfig.AuthorizationEndpoint != nil { - f2elemf1.AuthorizationEndpoint = f2iter.AuthenticateOidcConfig.AuthorizationEndpoint - } - if f2iter.AuthenticateOidcConfig.ClientId != nil { - f2elemf1.ClientID = f2iter.AuthenticateOidcConfig.ClientId - } - if f2iter.AuthenticateOidcConfig.ClientSecret != nil { - f2elemf1.ClientSecret = f2iter.AuthenticateOidcConfig.ClientSecret - } - if f2iter.AuthenticateOidcConfig.Issuer != nil { - f2elemf1.Issuer = f2iter.AuthenticateOidcConfig.Issuer - } - if f2iter.AuthenticateOidcConfig.OnUnauthenticatedRequest != "" { - f2elemf1.OnUnauthenticatedRequest = aws.String(string(f2iter.AuthenticateOidcConfig.OnUnauthenticatedRequest)) - } - if f2iter.AuthenticateOidcConfig.Scope != nil { - f2elemf1.Scope = f2iter.AuthenticateOidcConfig.Scope - } - if f2iter.AuthenticateOidcConfig.SessionCookieName != nil { - f2elemf1.SessionCookieName = f2iter.AuthenticateOidcConfig.SessionCookieName - } - if f2iter.AuthenticateOidcConfig.SessionTimeout != nil { - f2elemf1.SessionTimeout = f2iter.AuthenticateOidcConfig.SessionTimeout - } - if f2iter.AuthenticateOidcConfig.TokenEndpoint != nil { - f2elemf1.TokenEndpoint = f2iter.AuthenticateOidcConfig.TokenEndpoint - } - if f2iter.AuthenticateOidcConfig.UseExistingClientSecret != nil { - f2elemf1.UseExistingClientSecret = f2iter.AuthenticateOidcConfig.UseExistingClientSecret - } - if f2iter.AuthenticateOidcConfig.UserInfoEndpoint != nil { - f2elemf1.UserInfoEndpoint = f2iter.AuthenticateOidcConfig.UserInfoEndpoint - } - f2elem.AuthenticateOIDCConfig = f2elemf1 - } - if f2iter.FixedResponseConfig != nil { - f2elemf2 := &svcapitypes.FixedResponseActionConfig{} - if f2iter.FixedResponseConfig.ContentType != nil { - f2elemf2.ContentType = f2iter.FixedResponseConfig.ContentType - } - if f2iter.FixedResponseConfig.MessageBody != nil { - f2elemf2.MessageBody = f2iter.FixedResponseConfig.MessageBody - } - if f2iter.FixedResponseConfig.StatusCode != nil { - f2elemf2.StatusCode = f2iter.FixedResponseConfig.StatusCode - } - f2elem.FixedResponseConfig = f2elemf2 - } - if f2iter.ForwardConfig != nil { - f2elemf3 := &svcapitypes.ForwardActionConfig{} - if f2iter.ForwardConfig.TargetGroupStickinessConfig != nil { - f2elemf3f0 := &svcapitypes.TargetGroupStickinessConfig{} - if f2iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds != nil { - durationSecondsCopy := int64(*f2iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds) - f2elemf3f0.DurationSeconds = &durationSecondsCopy - } - if f2iter.ForwardConfig.TargetGroupStickinessConfig.Enabled != nil { - f2elemf3f0.Enabled = f2iter.ForwardConfig.TargetGroupStickinessConfig.Enabled - } - f2elemf3.TargetGroupStickinessConfig = f2elemf3f0 - } - if f2iter.ForwardConfig.TargetGroups != nil { - f2elemf3f1 := []*svcapitypes.TargetGroupTuple{} - for _, f2elemf3f1iter := range f2iter.ForwardConfig.TargetGroups { - f2elemf3f1elem := &svcapitypes.TargetGroupTuple{} - if f2elemf3f1iter.TargetGroupArn != nil { - f2elemf3f1elem.TargetGroupARN = f2elemf3f1iter.TargetGroupArn - } - if f2elemf3f1iter.Weight != nil { - weightCopy := int64(*f2elemf3f1iter.Weight) - f2elemf3f1elem.Weight = &weightCopy - } - f2elemf3f1 = append(f2elemf3f1, f2elemf3f1elem) - } - f2elemf3.TargetGroups = f2elemf3f1 - } - f2elem.ForwardConfig = f2elemf3 - } - if f2iter.Order != nil { - orderCopy := int64(*f2iter.Order) - f2elem.Order = &orderCopy - } - if f2iter.RedirectConfig != nil { - f2elemf5 := &svcapitypes.RedirectActionConfig{} - if f2iter.RedirectConfig.Host != nil { - f2elemf5.Host = f2iter.RedirectConfig.Host - } - if f2iter.RedirectConfig.Path != nil { - f2elemf5.Path = f2iter.RedirectConfig.Path - } - if f2iter.RedirectConfig.Port != nil { - f2elemf5.Port = f2iter.RedirectConfig.Port - } - if f2iter.RedirectConfig.Protocol != nil { - f2elemf5.Protocol = f2iter.RedirectConfig.Protocol - } - if f2iter.RedirectConfig.Query != nil { - f2elemf5.Query = f2iter.RedirectConfig.Query - } - if f2iter.RedirectConfig.StatusCode != "" { - f2elemf5.StatusCode = aws.String(string(f2iter.RedirectConfig.StatusCode)) - } - f2elem.RedirectConfig = f2elemf5 - } - if f2iter.TargetGroupArn != nil { - f2elem.TargetGroupARN = f2iter.TargetGroupArn - } - if f2iter.Type != "" { - f2elem.Type = aws.String(string(f2iter.Type)) - } - f2 = append(f2, f2elem) - } - ko.Spec.DefaultActions = f2 - } else { - ko.Spec.DefaultActions = nil - } if elem.ListenerArn != nil { if ko.Status.ACKResourceMetadata == nil { ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{} @@ -907,159 +754,6 @@ func (rm *resourceManager) sdkUpdate( } else { ko.Spec.Certificates = nil } - if elem.DefaultActions != nil { - f2 := []*svcapitypes.Action{} - for _, f2iter := range elem.DefaultActions { - f2elem := &svcapitypes.Action{} - if f2iter.AuthenticateCognitoConfig != nil { - f2elemf0 := &svcapitypes.AuthenticateCognitoActionConfig{} - if f2iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams != nil { - f2elemf0.AuthenticationRequestExtraParams = aws.StringMap(f2iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams) - } - if f2iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest != "" { - f2elemf0.OnUnauthenticatedRequest = aws.String(string(f2iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest)) - } - if f2iter.AuthenticateCognitoConfig.Scope != nil { - f2elemf0.Scope = f2iter.AuthenticateCognitoConfig.Scope - } - if f2iter.AuthenticateCognitoConfig.SessionCookieName != nil { - f2elemf0.SessionCookieName = f2iter.AuthenticateCognitoConfig.SessionCookieName - } - if f2iter.AuthenticateCognitoConfig.SessionTimeout != nil { - f2elemf0.SessionTimeout = f2iter.AuthenticateCognitoConfig.SessionTimeout - } - if f2iter.AuthenticateCognitoConfig.UserPoolArn != nil { - f2elemf0.UserPoolARN = f2iter.AuthenticateCognitoConfig.UserPoolArn - } - if f2iter.AuthenticateCognitoConfig.UserPoolClientId != nil { - f2elemf0.UserPoolClientID = f2iter.AuthenticateCognitoConfig.UserPoolClientId - } - if f2iter.AuthenticateCognitoConfig.UserPoolDomain != nil { - f2elemf0.UserPoolDomain = f2iter.AuthenticateCognitoConfig.UserPoolDomain - } - f2elem.AuthenticateCognitoConfig = f2elemf0 - } - if f2iter.AuthenticateOidcConfig != nil { - f2elemf1 := &svcapitypes.AuthenticateOIDCActionConfig{} - if f2iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams != nil { - f2elemf1.AuthenticationRequestExtraParams = aws.StringMap(f2iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams) - } - if f2iter.AuthenticateOidcConfig.AuthorizationEndpoint != nil { - f2elemf1.AuthorizationEndpoint = f2iter.AuthenticateOidcConfig.AuthorizationEndpoint - } - if f2iter.AuthenticateOidcConfig.ClientId != nil { - f2elemf1.ClientID = f2iter.AuthenticateOidcConfig.ClientId - } - if f2iter.AuthenticateOidcConfig.ClientSecret != nil { - f2elemf1.ClientSecret = f2iter.AuthenticateOidcConfig.ClientSecret - } - if f2iter.AuthenticateOidcConfig.Issuer != nil { - f2elemf1.Issuer = f2iter.AuthenticateOidcConfig.Issuer - } - if f2iter.AuthenticateOidcConfig.OnUnauthenticatedRequest != "" { - f2elemf1.OnUnauthenticatedRequest = aws.String(string(f2iter.AuthenticateOidcConfig.OnUnauthenticatedRequest)) - } - if f2iter.AuthenticateOidcConfig.Scope != nil { - f2elemf1.Scope = f2iter.AuthenticateOidcConfig.Scope - } - if f2iter.AuthenticateOidcConfig.SessionCookieName != nil { - f2elemf1.SessionCookieName = f2iter.AuthenticateOidcConfig.SessionCookieName - } - if f2iter.AuthenticateOidcConfig.SessionTimeout != nil { - f2elemf1.SessionTimeout = f2iter.AuthenticateOidcConfig.SessionTimeout - } - if f2iter.AuthenticateOidcConfig.TokenEndpoint != nil { - f2elemf1.TokenEndpoint = f2iter.AuthenticateOidcConfig.TokenEndpoint - } - if f2iter.AuthenticateOidcConfig.UseExistingClientSecret != nil { - f2elemf1.UseExistingClientSecret = f2iter.AuthenticateOidcConfig.UseExistingClientSecret - } - if f2iter.AuthenticateOidcConfig.UserInfoEndpoint != nil { - f2elemf1.UserInfoEndpoint = f2iter.AuthenticateOidcConfig.UserInfoEndpoint - } - f2elem.AuthenticateOIDCConfig = f2elemf1 - } - if f2iter.FixedResponseConfig != nil { - f2elemf2 := &svcapitypes.FixedResponseActionConfig{} - if f2iter.FixedResponseConfig.ContentType != nil { - f2elemf2.ContentType = f2iter.FixedResponseConfig.ContentType - } - if f2iter.FixedResponseConfig.MessageBody != nil { - f2elemf2.MessageBody = f2iter.FixedResponseConfig.MessageBody - } - if f2iter.FixedResponseConfig.StatusCode != nil { - f2elemf2.StatusCode = f2iter.FixedResponseConfig.StatusCode - } - f2elem.FixedResponseConfig = f2elemf2 - } - if f2iter.ForwardConfig != nil { - f2elemf3 := &svcapitypes.ForwardActionConfig{} - if f2iter.ForwardConfig.TargetGroupStickinessConfig != nil { - f2elemf3f0 := &svcapitypes.TargetGroupStickinessConfig{} - if f2iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds != nil { - durationSecondsCopy := int64(*f2iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds) - f2elemf3f0.DurationSeconds = &durationSecondsCopy - } - if f2iter.ForwardConfig.TargetGroupStickinessConfig.Enabled != nil { - f2elemf3f0.Enabled = f2iter.ForwardConfig.TargetGroupStickinessConfig.Enabled - } - f2elemf3.TargetGroupStickinessConfig = f2elemf3f0 - } - if f2iter.ForwardConfig.TargetGroups != nil { - f2elemf3f1 := []*svcapitypes.TargetGroupTuple{} - for _, f2elemf3f1iter := range f2iter.ForwardConfig.TargetGroups { - f2elemf3f1elem := &svcapitypes.TargetGroupTuple{} - if f2elemf3f1iter.TargetGroupArn != nil { - f2elemf3f1elem.TargetGroupARN = f2elemf3f1iter.TargetGroupArn - } - if f2elemf3f1iter.Weight != nil { - weightCopy := int64(*f2elemf3f1iter.Weight) - f2elemf3f1elem.Weight = &weightCopy - } - f2elemf3f1 = append(f2elemf3f1, f2elemf3f1elem) - } - f2elemf3.TargetGroups = f2elemf3f1 - } - f2elem.ForwardConfig = f2elemf3 - } - if f2iter.Order != nil { - orderCopy := int64(*f2iter.Order) - f2elem.Order = &orderCopy - } - if f2iter.RedirectConfig != nil { - f2elemf5 := &svcapitypes.RedirectActionConfig{} - if f2iter.RedirectConfig.Host != nil { - f2elemf5.Host = f2iter.RedirectConfig.Host - } - if f2iter.RedirectConfig.Path != nil { - f2elemf5.Path = f2iter.RedirectConfig.Path - } - if f2iter.RedirectConfig.Port != nil { - f2elemf5.Port = f2iter.RedirectConfig.Port - } - if f2iter.RedirectConfig.Protocol != nil { - f2elemf5.Protocol = f2iter.RedirectConfig.Protocol - } - if f2iter.RedirectConfig.Query != nil { - f2elemf5.Query = f2iter.RedirectConfig.Query - } - if f2iter.RedirectConfig.StatusCode != "" { - f2elemf5.StatusCode = aws.String(string(f2iter.RedirectConfig.StatusCode)) - } - f2elem.RedirectConfig = f2elemf5 - } - if f2iter.TargetGroupArn != nil { - f2elem.TargetGroupARN = f2iter.TargetGroupArn - } - if f2iter.Type != "" { - f2elem.Type = aws.String(string(f2iter.Type)) - } - f2 = append(f2, f2elem) - } - ko.Spec.DefaultActions = f2 - } else { - ko.Spec.DefaultActions = nil - } if elem.ListenerArn != nil { if ko.Status.ACKResourceMetadata == nil { ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{} From 2c7a404615a4a528a9a8b978e26f5c0b54639126 Mon Sep 17 00:00:00 2001 From: Youssef Omar Bouden Date: Wed, 11 Nov 2026 15:53:19 +0100 Subject: [PATCH 3/3] fix(listener): compare default actions sorted by Order DescribeListeners returns multiple actions in an order of its own, neither declared nor by Order, so a two-action listener compared by position made a no-op ModifyListener on every reconcile. Both sides are sorted by Order before the comparison; the new test case fails without the sort. Merged main (v0.68.0) and regenerated with code-generator v0.68.0, no generated change. Signed-off-by: Youssef Omar Bouden --- pkg/resource/listener/hooks.go | 12 ++++++++++++ pkg/resource/listener/hooks_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/resource/listener/hooks.go b/pkg/resource/listener/hooks.go index 23c2f22..9696876 100644 --- a/pkg/resource/listener/hooks.go +++ b/pkg/resource/listener/hooks.go @@ -68,6 +68,18 @@ func normalizeActions(actions []*svcapitypes.Action) []*svcapitypes.Action { normalizeCognito(c.AuthenticateCognitoConfig) out[i] = c } + // DescribeListeners returns multiple actions in an order of its own, + // neither declared nor by Order, so compare them sorted by Order. + sort.SliceStable(out, func(i, j int) bool { + var oi, oj int64 + if out[i] != nil { + oi = aws.ToInt64(out[i].Order) + } + if out[j] != nil { + oj = aws.ToInt64(out[j].Order) + } + return oi < oj + }) return out } diff --git a/pkg/resource/listener/hooks_test.go b/pkg/resource/listener/hooks_test.go index d1c4b6d..843b25b 100644 --- a/pkg/resource/listener/hooks_test.go +++ b/pkg/resource/listener/hooks_test.go @@ -336,6 +336,18 @@ func TestNewResourceDelta_DefaultActions(t *testing.T) { }, expectDelta: false, }, + { + name: "multiple actions returned in another order than declared", + desired: []*svcapitypes.Action{ + {Type: aws.String("authenticate-oidc"), Order: aws.Int64(1), AuthenticateOIDCConfig: oidc(aws.String("s3cret"), false)}, + {Type: aws.String("forward"), Order: aws.Int64(2), TargetGroupARN: aws.String("arn:tg/a")}, + }, + observed: []*svcapitypes.Action{ + forwardAsReturned(2, "arn:tg/a"), + {Type: aws.String("authenticate-oidc"), Order: aws.Int64(1), AuthenticateOIDCConfig: oidc(nil, true)}, + }, + expectDelta: false, + }, { name: "action count differs", desired: []*svcapitypes.Action{