diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index 3717e93..0fc7e8e 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,5 +1,5 @@ ack_generate_info: - build_date: "2026-06-22T23:03:45Z" + build_date: "2026-06-26T19:36:08Z" build_hash: 2ae5d2cfadaa2a10b2ccb9e73a111b2a91c36642 go_version: go1.26.4 version: v0.60.0 @@ -7,7 +7,7 @@ api_directory_checksum: 060554dd6962e2466013922cf96fb4cf92a23706 api_version: v1alpha1 aws_sdk_go_version: v1.32.6 generator_config_info: - file_checksum: ce1168f649f03d9652bc8e82f8322d6dd2d909f0 + file_checksum: 25ce95e291471e0727155bed0a1a43b2c4a7ce1c original_file_name: generator.yaml last_modification: reason: API generation diff --git a/apis/v1alpha1/generator.yaml b/apis/v1alpha1/generator.yaml index 0a32afd..43bec68 100644 --- a/apis/v1alpha1/generator.yaml +++ b/apis/v1alpha1/generator.yaml @@ -220,6 +220,14 @@ resources: references: resource: Listener path: Status.ACKResourceMetadata.ARN + Actions: + compare: + is_ignored: true + set: + - ignore: true + method: Create + - ignore: true + method: Update Actions.targetGroupARN: references: resource: TargetGroup diff --git a/generator.yaml b/generator.yaml index 0a32afd..43bec68 100644 --- a/generator.yaml +++ b/generator.yaml @@ -220,6 +220,14 @@ resources: references: resource: Listener path: Status.ACKResourceMetadata.ARN + Actions: + compare: + is_ignored: true + set: + - ignore: true + method: Create + - ignore: true + method: Update Actions.targetGroupARN: references: resource: TargetGroup diff --git a/pkg/resource/rule/delta.go b/pkg/resource/rule/delta.go index ff38bbe..f46a805 100644 --- a/pkg/resource/rule/delta.go +++ b/pkg/resource/rule/delta.go @@ -43,13 +43,6 @@ func newResourceDelta( } customPreCompare(delta, a, b) - if len(a.ko.Spec.Actions) != len(b.ko.Spec.Actions) { - delta.Add("Spec.Actions", a.ko.Spec.Actions, b.ko.Spec.Actions) - } else if len(a.ko.Spec.Actions) > 0 { - if !equality.Semantic.Equalities.DeepEqual(a.ko.Spec.Actions, b.ko.Spec.Actions) { - delta.Add("Spec.Actions", a.ko.Spec.Actions, b.ko.Spec.Actions) - } - } if ackcompare.HasNilDifference(a.ko.Spec.ListenerARN, b.ko.Spec.ListenerARN) { delta.Add("Spec.ListenerARN", a.ko.Spec.ListenerARN, b.ko.Spec.ListenerARN) } else if a.ko.Spec.ListenerARN != nil && b.ko.Spec.ListenerARN != nil { diff --git a/pkg/resource/rule/hooks.go b/pkg/resource/rule/hooks.go index c561a1d..6d99437 100644 --- a/pkg/resource/rule/hooks.go +++ b/pkg/resource/rule/hooks.go @@ -91,6 +91,65 @@ func customPreCompare( b *resource, ) { customCompareConditions(delta, a, b) + customCompareActions(delta, a, b) +} + +// customCompareActions performs custom comparison for Rule actions. +// Actions is compared manually (compare.is_ignored: true) because the AWS +// ELBv2 API never returns the k8s-only TargetGroupRef fields and assigns an +// Order when the user omits one. Comparing the auto-generated way would always +// report a diff (the ref present in desired but absent in the observed state), +// triggering a redundant ModifyRule on every reconcile. We strip the ref fields +// and normalize the server-assigned Order before comparing; the resolved +// TargetGroupARN is still compared so genuine drift is detected. +func customCompareActions( + delta *ackcompare.Delta, + a *resource, + b *resource, +) { + if a == nil || b == nil { + return + } + + desired := a.ko.Spec.Actions + observed := b.ko.Spec.Actions + if len(desired) != len(observed) { + delta.Add("Spec.Actions", desired, observed) + return + } + + for i := range desired { + d := normalizeActionForCompare(desired[i]) + o := normalizeActionForCompare(observed[i]) + // AWS assigns an Order when the user does not specify one, so only + // compare Order when it was set in the desired state. + if desired[i] != nil && desired[i].Order == nil { + o.Order = nil + } + if !equality.Semantic.Equalities.DeepEqual(d, o) { + delta.Add("Spec.Actions", desired, observed) + return + } + } +} + +// normalizeActionForCompare returns a deep copy of the action with the k8s-only +// TargetGroupRef fields removed, both at the action level and within +// ForwardConfig.TargetGroups, so they do not produce spurious diffs. +func normalizeActionForCompare(action *svcapitypes.Action) *svcapitypes.Action { + if action == nil { + return nil + } + a := action.DeepCopy() + a.TargetGroupRef = nil + if a.ForwardConfig != nil { + for j := range a.ForwardConfig.TargetGroups { + if a.ForwardConfig.TargetGroups[j] != nil { + a.ForwardConfig.TargetGroups[j].TargetGroupRef = nil + } + } + } + return a } // customCompareConditions performs custom comparison for Rule conditions. diff --git a/pkg/resource/rule/hooks_test.go b/pkg/resource/rule/hooks_test.go index 62fb099..db349df 100644 --- a/pkg/resource/rule/hooks_test.go +++ b/pkg/resource/rule/hooks_test.go @@ -16,6 +16,7 @@ package rule import ( "testing" + ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" "github.com/aws/aws-sdk-go/aws" "github.com/stretchr/testify/assert" @@ -23,6 +24,12 @@ import ( 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)}, + } +} + func TestCustomCompareConditions(t *testing.T) { tests := []struct { name string @@ -693,3 +700,221 @@ func TestCustomCompareConditions(t *testing.T) { }) } } + +func TestCustomCompareActions(t *testing.T) { + tests := []struct { + name string + desired *resource + observed *resource + expectDelta bool + }{ + { + name: "action-level ref in desired, absent in observed, same ARN - no delta", + desired: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + TargetGroupRef: tgRef("my-tg"), + TargetGroupARN: aws.String("arn:tg/abc"), + }, + }, + }, + }, + }, + observed: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + TargetGroupARN: aws.String("arn:tg/abc"), + }, + }, + }, + }, + }, + expectDelta: false, + }, + { + name: "forwardConfig nested ref in desired, absent in observed, same ARN - no delta", + desired: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + { + TargetGroupRef: tgRef("my-tg"), + TargetGroupARN: aws.String("arn:tg/abc"), + Weight: aws.Int64(1), + }, + }, + }, + }, + }, + }, + }, + }, + observed: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + ForwardConfig: &svcapitypes.ForwardActionConfig{ + TargetGroups: []*svcapitypes.TargetGroupTuple{ + { + TargetGroupARN: aws.String("arn:tg/abc"), + Weight: aws.Int64(1), + }, + }, + }, + }, + }, + }, + }, + }, + expectDelta: false, + }, + { + name: "server-assigned Order, not set in desired - no delta", + desired: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + TargetGroupARN: aws.String("arn:tg/abc"), + }, + }, + }, + }, + }, + observed: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + Order: aws.Int64(1), + TargetGroupARN: aws.String("arn:tg/abc"), + }, + }, + }, + }, + }, + expectDelta: false, + }, + { + name: "different resolved ARN - delta expected", + desired: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + TargetGroupRef: tgRef("my-tg"), + TargetGroupARN: aws.String("arn:tg/new"), + }, + }, + }, + }, + }, + observed: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + TargetGroupARN: aws.String("arn:tg/old"), + }, + }, + }, + }, + }, + expectDelta: true, + }, + { + name: "different Order both set - delta expected", + desired: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + Order: aws.Int64(1), + TargetGroupARN: aws.String("arn:tg/abc"), + }, + }, + }, + }, + }, + observed: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + { + Type: aws.String("forward"), + Order: aws.Int64(2), + TargetGroupARN: aws.String("arn:tg/abc"), + }, + }, + }, + }, + }, + expectDelta: true, + }, + { + name: "different action count - delta expected", + desired: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/abc")}, + }, + }, + }, + }, + observed: &resource{ + ko: &svcapitypes.Rule{ + Spec: svcapitypes.RuleSpec{ + Actions: []*svcapitypes.Action{ + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/abc")}, + {Type: aws.String("forward"), TargetGroupARN: aws.String("arn:tg/def")}, + }, + }, + }, + }, + expectDelta: true, + }, + { + name: "nil desired resource should not panic", + desired: nil, + observed: &resource{ko: &svcapitypes.Rule{}}, + expectDelta: false, + }, + { + name: "nil observed resource should not panic", + desired: &resource{ko: &svcapitypes.Rule{}}, + observed: nil, + expectDelta: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + delta := ackcompare.NewDelta() + customCompareActions(delta, tt.desired, tt.observed) + + if tt.expectDelta { + assert.True(t, len(delta.Differences) > 0, "Expected delta but got none") + } else { + assert.Equal(t, 0, len(delta.Differences), "Expected no delta but got: %v", delta.Differences) + } + }) + } +} diff --git a/pkg/resource/rule/sdk.go b/pkg/resource/rule/sdk.go index a5475e3..ac10fff 100644 --- a/pkg/resource/rule/sdk.go +++ b/pkg/resource/rule/sdk.go @@ -400,159 +400,6 @@ func (rm *resourceManager) sdkCreate( found := false for _, elem := range resp.Rules { - if elem.Actions != nil { - f0 := []*svcapitypes.Action{} - for _, f0iter := range elem.Actions { - f0elem := &svcapitypes.Action{} - if f0iter.AuthenticateCognitoConfig != nil { - f0elemf0 := &svcapitypes.AuthenticateCognitoActionConfig{} - if f0iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams != nil { - f0elemf0.AuthenticationRequestExtraParams = aws.StringMap(f0iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams) - } - if f0iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest != "" { - f0elemf0.OnUnauthenticatedRequest = aws.String(string(f0iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest)) - } - if f0iter.AuthenticateCognitoConfig.Scope != nil { - f0elemf0.Scope = f0iter.AuthenticateCognitoConfig.Scope - } - if f0iter.AuthenticateCognitoConfig.SessionCookieName != nil { - f0elemf0.SessionCookieName = f0iter.AuthenticateCognitoConfig.SessionCookieName - } - if f0iter.AuthenticateCognitoConfig.SessionTimeout != nil { - f0elemf0.SessionTimeout = f0iter.AuthenticateCognitoConfig.SessionTimeout - } - if f0iter.AuthenticateCognitoConfig.UserPoolArn != nil { - f0elemf0.UserPoolARN = f0iter.AuthenticateCognitoConfig.UserPoolArn - } - if f0iter.AuthenticateCognitoConfig.UserPoolClientId != nil { - f0elemf0.UserPoolClientID = f0iter.AuthenticateCognitoConfig.UserPoolClientId - } - if f0iter.AuthenticateCognitoConfig.UserPoolDomain != nil { - f0elemf0.UserPoolDomain = f0iter.AuthenticateCognitoConfig.UserPoolDomain - } - f0elem.AuthenticateCognitoConfig = f0elemf0 - } - if f0iter.AuthenticateOidcConfig != nil { - f0elemf1 := &svcapitypes.AuthenticateOIDCActionConfig{} - if f0iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams != nil { - f0elemf1.AuthenticationRequestExtraParams = aws.StringMap(f0iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams) - } - if f0iter.AuthenticateOidcConfig.AuthorizationEndpoint != nil { - f0elemf1.AuthorizationEndpoint = f0iter.AuthenticateOidcConfig.AuthorizationEndpoint - } - if f0iter.AuthenticateOidcConfig.ClientId != nil { - f0elemf1.ClientID = f0iter.AuthenticateOidcConfig.ClientId - } - if f0iter.AuthenticateOidcConfig.ClientSecret != nil { - f0elemf1.ClientSecret = f0iter.AuthenticateOidcConfig.ClientSecret - } - if f0iter.AuthenticateOidcConfig.Issuer != nil { - f0elemf1.Issuer = f0iter.AuthenticateOidcConfig.Issuer - } - if f0iter.AuthenticateOidcConfig.OnUnauthenticatedRequest != "" { - f0elemf1.OnUnauthenticatedRequest = aws.String(string(f0iter.AuthenticateOidcConfig.OnUnauthenticatedRequest)) - } - if f0iter.AuthenticateOidcConfig.Scope != nil { - f0elemf1.Scope = f0iter.AuthenticateOidcConfig.Scope - } - if f0iter.AuthenticateOidcConfig.SessionCookieName != nil { - f0elemf1.SessionCookieName = f0iter.AuthenticateOidcConfig.SessionCookieName - } - if f0iter.AuthenticateOidcConfig.SessionTimeout != nil { - f0elemf1.SessionTimeout = f0iter.AuthenticateOidcConfig.SessionTimeout - } - if f0iter.AuthenticateOidcConfig.TokenEndpoint != nil { - f0elemf1.TokenEndpoint = f0iter.AuthenticateOidcConfig.TokenEndpoint - } - if f0iter.AuthenticateOidcConfig.UseExistingClientSecret != nil { - f0elemf1.UseExistingClientSecret = f0iter.AuthenticateOidcConfig.UseExistingClientSecret - } - if f0iter.AuthenticateOidcConfig.UserInfoEndpoint != nil { - f0elemf1.UserInfoEndpoint = f0iter.AuthenticateOidcConfig.UserInfoEndpoint - } - f0elem.AuthenticateOIDCConfig = f0elemf1 - } - if f0iter.FixedResponseConfig != nil { - f0elemf2 := &svcapitypes.FixedResponseActionConfig{} - if f0iter.FixedResponseConfig.ContentType != nil { - f0elemf2.ContentType = f0iter.FixedResponseConfig.ContentType - } - if f0iter.FixedResponseConfig.MessageBody != nil { - f0elemf2.MessageBody = f0iter.FixedResponseConfig.MessageBody - } - if f0iter.FixedResponseConfig.StatusCode != nil { - f0elemf2.StatusCode = f0iter.FixedResponseConfig.StatusCode - } - f0elem.FixedResponseConfig = f0elemf2 - } - if f0iter.ForwardConfig != nil { - f0elemf3 := &svcapitypes.ForwardActionConfig{} - if f0iter.ForwardConfig.TargetGroupStickinessConfig != nil { - f0elemf3f0 := &svcapitypes.TargetGroupStickinessConfig{} - if f0iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds != nil { - durationSecondsCopy := int64(*f0iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds) - f0elemf3f0.DurationSeconds = &durationSecondsCopy - } - if f0iter.ForwardConfig.TargetGroupStickinessConfig.Enabled != nil { - f0elemf3f0.Enabled = f0iter.ForwardConfig.TargetGroupStickinessConfig.Enabled - } - f0elemf3.TargetGroupStickinessConfig = f0elemf3f0 - } - if f0iter.ForwardConfig.TargetGroups != nil { - f0elemf3f1 := []*svcapitypes.TargetGroupTuple{} - for _, f0elemf3f1iter := range f0iter.ForwardConfig.TargetGroups { - f0elemf3f1elem := &svcapitypes.TargetGroupTuple{} - if f0elemf3f1iter.TargetGroupArn != nil { - f0elemf3f1elem.TargetGroupARN = f0elemf3f1iter.TargetGroupArn - } - if f0elemf3f1iter.Weight != nil { - weightCopy := int64(*f0elemf3f1iter.Weight) - f0elemf3f1elem.Weight = &weightCopy - } - f0elemf3f1 = append(f0elemf3f1, f0elemf3f1elem) - } - f0elemf3.TargetGroups = f0elemf3f1 - } - f0elem.ForwardConfig = f0elemf3 - } - if f0iter.Order != nil { - orderCopy := int64(*f0iter.Order) - f0elem.Order = &orderCopy - } - if f0iter.RedirectConfig != nil { - f0elemf5 := &svcapitypes.RedirectActionConfig{} - if f0iter.RedirectConfig.Host != nil { - f0elemf5.Host = f0iter.RedirectConfig.Host - } - if f0iter.RedirectConfig.Path != nil { - f0elemf5.Path = f0iter.RedirectConfig.Path - } - if f0iter.RedirectConfig.Port != nil { - f0elemf5.Port = f0iter.RedirectConfig.Port - } - if f0iter.RedirectConfig.Protocol != nil { - f0elemf5.Protocol = f0iter.RedirectConfig.Protocol - } - if f0iter.RedirectConfig.Query != nil { - f0elemf5.Query = f0iter.RedirectConfig.Query - } - if f0iter.RedirectConfig.StatusCode != "" { - f0elemf5.StatusCode = aws.String(string(f0iter.RedirectConfig.StatusCode)) - } - f0elem.RedirectConfig = f0elemf5 - } - if f0iter.TargetGroupArn != nil { - f0elem.TargetGroupARN = f0iter.TargetGroupArn - } - if f0iter.Type != "" { - f0elem.Type = aws.String(string(f0iter.Type)) - } - f0 = append(f0, f0elem) - } - ko.Spec.Actions = f0 - } else { - ko.Spec.Actions = nil - } if elem.IsDefault != nil { ko.Status.IsDefault = elem.IsDefault } else { @@ -885,159 +732,6 @@ func (rm *resourceManager) sdkUpdate( found := false for _, elem := range resp.Rules { - if elem.Actions != nil { - f0 := []*svcapitypes.Action{} - for _, f0iter := range elem.Actions { - f0elem := &svcapitypes.Action{} - if f0iter.AuthenticateCognitoConfig != nil { - f0elemf0 := &svcapitypes.AuthenticateCognitoActionConfig{} - if f0iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams != nil { - f0elemf0.AuthenticationRequestExtraParams = aws.StringMap(f0iter.AuthenticateCognitoConfig.AuthenticationRequestExtraParams) - } - if f0iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest != "" { - f0elemf0.OnUnauthenticatedRequest = aws.String(string(f0iter.AuthenticateCognitoConfig.OnUnauthenticatedRequest)) - } - if f0iter.AuthenticateCognitoConfig.Scope != nil { - f0elemf0.Scope = f0iter.AuthenticateCognitoConfig.Scope - } - if f0iter.AuthenticateCognitoConfig.SessionCookieName != nil { - f0elemf0.SessionCookieName = f0iter.AuthenticateCognitoConfig.SessionCookieName - } - if f0iter.AuthenticateCognitoConfig.SessionTimeout != nil { - f0elemf0.SessionTimeout = f0iter.AuthenticateCognitoConfig.SessionTimeout - } - if f0iter.AuthenticateCognitoConfig.UserPoolArn != nil { - f0elemf0.UserPoolARN = f0iter.AuthenticateCognitoConfig.UserPoolArn - } - if f0iter.AuthenticateCognitoConfig.UserPoolClientId != nil { - f0elemf0.UserPoolClientID = f0iter.AuthenticateCognitoConfig.UserPoolClientId - } - if f0iter.AuthenticateCognitoConfig.UserPoolDomain != nil { - f0elemf0.UserPoolDomain = f0iter.AuthenticateCognitoConfig.UserPoolDomain - } - f0elem.AuthenticateCognitoConfig = f0elemf0 - } - if f0iter.AuthenticateOidcConfig != nil { - f0elemf1 := &svcapitypes.AuthenticateOIDCActionConfig{} - if f0iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams != nil { - f0elemf1.AuthenticationRequestExtraParams = aws.StringMap(f0iter.AuthenticateOidcConfig.AuthenticationRequestExtraParams) - } - if f0iter.AuthenticateOidcConfig.AuthorizationEndpoint != nil { - f0elemf1.AuthorizationEndpoint = f0iter.AuthenticateOidcConfig.AuthorizationEndpoint - } - if f0iter.AuthenticateOidcConfig.ClientId != nil { - f0elemf1.ClientID = f0iter.AuthenticateOidcConfig.ClientId - } - if f0iter.AuthenticateOidcConfig.ClientSecret != nil { - f0elemf1.ClientSecret = f0iter.AuthenticateOidcConfig.ClientSecret - } - if f0iter.AuthenticateOidcConfig.Issuer != nil { - f0elemf1.Issuer = f0iter.AuthenticateOidcConfig.Issuer - } - if f0iter.AuthenticateOidcConfig.OnUnauthenticatedRequest != "" { - f0elemf1.OnUnauthenticatedRequest = aws.String(string(f0iter.AuthenticateOidcConfig.OnUnauthenticatedRequest)) - } - if f0iter.AuthenticateOidcConfig.Scope != nil { - f0elemf1.Scope = f0iter.AuthenticateOidcConfig.Scope - } - if f0iter.AuthenticateOidcConfig.SessionCookieName != nil { - f0elemf1.SessionCookieName = f0iter.AuthenticateOidcConfig.SessionCookieName - } - if f0iter.AuthenticateOidcConfig.SessionTimeout != nil { - f0elemf1.SessionTimeout = f0iter.AuthenticateOidcConfig.SessionTimeout - } - if f0iter.AuthenticateOidcConfig.TokenEndpoint != nil { - f0elemf1.TokenEndpoint = f0iter.AuthenticateOidcConfig.TokenEndpoint - } - if f0iter.AuthenticateOidcConfig.UseExistingClientSecret != nil { - f0elemf1.UseExistingClientSecret = f0iter.AuthenticateOidcConfig.UseExistingClientSecret - } - if f0iter.AuthenticateOidcConfig.UserInfoEndpoint != nil { - f0elemf1.UserInfoEndpoint = f0iter.AuthenticateOidcConfig.UserInfoEndpoint - } - f0elem.AuthenticateOIDCConfig = f0elemf1 - } - if f0iter.FixedResponseConfig != nil { - f0elemf2 := &svcapitypes.FixedResponseActionConfig{} - if f0iter.FixedResponseConfig.ContentType != nil { - f0elemf2.ContentType = f0iter.FixedResponseConfig.ContentType - } - if f0iter.FixedResponseConfig.MessageBody != nil { - f0elemf2.MessageBody = f0iter.FixedResponseConfig.MessageBody - } - if f0iter.FixedResponseConfig.StatusCode != nil { - f0elemf2.StatusCode = f0iter.FixedResponseConfig.StatusCode - } - f0elem.FixedResponseConfig = f0elemf2 - } - if f0iter.ForwardConfig != nil { - f0elemf3 := &svcapitypes.ForwardActionConfig{} - if f0iter.ForwardConfig.TargetGroupStickinessConfig != nil { - f0elemf3f0 := &svcapitypes.TargetGroupStickinessConfig{} - if f0iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds != nil { - durationSecondsCopy := int64(*f0iter.ForwardConfig.TargetGroupStickinessConfig.DurationSeconds) - f0elemf3f0.DurationSeconds = &durationSecondsCopy - } - if f0iter.ForwardConfig.TargetGroupStickinessConfig.Enabled != nil { - f0elemf3f0.Enabled = f0iter.ForwardConfig.TargetGroupStickinessConfig.Enabled - } - f0elemf3.TargetGroupStickinessConfig = f0elemf3f0 - } - if f0iter.ForwardConfig.TargetGroups != nil { - f0elemf3f1 := []*svcapitypes.TargetGroupTuple{} - for _, f0elemf3f1iter := range f0iter.ForwardConfig.TargetGroups { - f0elemf3f1elem := &svcapitypes.TargetGroupTuple{} - if f0elemf3f1iter.TargetGroupArn != nil { - f0elemf3f1elem.TargetGroupARN = f0elemf3f1iter.TargetGroupArn - } - if f0elemf3f1iter.Weight != nil { - weightCopy := int64(*f0elemf3f1iter.Weight) - f0elemf3f1elem.Weight = &weightCopy - } - f0elemf3f1 = append(f0elemf3f1, f0elemf3f1elem) - } - f0elemf3.TargetGroups = f0elemf3f1 - } - f0elem.ForwardConfig = f0elemf3 - } - if f0iter.Order != nil { - orderCopy := int64(*f0iter.Order) - f0elem.Order = &orderCopy - } - if f0iter.RedirectConfig != nil { - f0elemf5 := &svcapitypes.RedirectActionConfig{} - if f0iter.RedirectConfig.Host != nil { - f0elemf5.Host = f0iter.RedirectConfig.Host - } - if f0iter.RedirectConfig.Path != nil { - f0elemf5.Path = f0iter.RedirectConfig.Path - } - if f0iter.RedirectConfig.Port != nil { - f0elemf5.Port = f0iter.RedirectConfig.Port - } - if f0iter.RedirectConfig.Protocol != nil { - f0elemf5.Protocol = f0iter.RedirectConfig.Protocol - } - if f0iter.RedirectConfig.Query != nil { - f0elemf5.Query = f0iter.RedirectConfig.Query - } - if f0iter.RedirectConfig.StatusCode != "" { - f0elemf5.StatusCode = aws.String(string(f0iter.RedirectConfig.StatusCode)) - } - f0elem.RedirectConfig = f0elemf5 - } - if f0iter.TargetGroupArn != nil { - f0elem.TargetGroupARN = f0iter.TargetGroupArn - } - if f0iter.Type != "" { - f0elem.Type = aws.String(string(f0iter.Type)) - } - f0 = append(f0, f0elem) - } - ko.Spec.Actions = f0 - } else { - ko.Spec.Actions = nil - } if elem.IsDefault != nil { ko.Status.IsDefault = elem.IsDefault } else { diff --git a/test/e2e/tests/test_rule.py b/test/e2e/tests/test_rule.py index 54029c1..10b0181 100644 --- a/test/e2e/tests/test_rule.py +++ b/test/e2e/tests/test_rule.py @@ -18,6 +18,7 @@ import time import pytest +from acktest.k8s import condition from acktest.k8s import resource as k8s from acktest.resources import random_suffix_name from e2e import CRD_GROUP, CRD_VERSION, load_elbv2_resource, service_marker @@ -112,3 +113,13 @@ def test_create_delete(self, elbv2_client, simple_rule): assert rule["Priority"] == "500" assert rule["Conditions"][0]["Field"] == "http-request-method" assert rule["Conditions"][0]["HttpRequestMethodConfig"]["Values"] == ["GET"] + + def test_target_group_ref_preserved(self, simple_rule): + (ref, _) = simple_rule + + condition.assert_synced(ref) + + cr = k8s.get_resource(ref) + tg = cr["spec"]["actions"][0]["forwardConfig"]["targetGroups"][0] + assert "targetGroupRef" in tg + assert tg["targetGroupRef"]["from"]["name"] is not None