Skip to content

Commit

Permalink
fix(bucket): also sanitize observed FilterRules.Name of lambda and to…
Browse files Browse the repository at this point in the history
…pic configs

Signed-off-by: Charel Baum (external expert on behalf of DB InfraGO AG) <[email protected]>
(cherry picked from commit f0a48f9)
  • Loading branch information
Charel Baum (external expert on behalf of DB InfraGO AG) authored and github-actions[bot] committed May 21, 2024
1 parent bddb183 commit 7e2bc23
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/controller/s3/bucket/convert/converter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ import (
// goverter:converter
// goverter:ignoreUnexported
type Converter interface {
DeepCopyAWSLambdaFunctionConfiguration([]types.LambdaFunctionConfiguration) []types.LambdaFunctionConfiguration
DeepCopyAWSQueueConfiguration([]types.QueueConfiguration) []types.QueueConfiguration
DeepCopyAWSTopicConfiguration([]types.TopicConfiguration) []types.TopicConfiguration
}
70 changes: 70 additions & 0 deletions pkg/controller/s3/bucket/convert/zz_converter.go

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

60 changes: 59 additions & 1 deletion pkg/controller/s3/bucket/notificationConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ func IsNotificationConfigurationUpToDate(cr *v1beta1.NotificationConfiguration,
sortTopic(generated.TopicConfigurations)
sortTopic(external.TopicConfigurations)

// The AWS API returns QueueConfiguration.Filter.Key.FilterRules.Name as "Prefix"/"Suffix" but expects
// The AWS API returns *Configuration.Filter.Key.FilterRules.Name as "Prefix"/"Suffix" but expects
// "prefix"/"suffix" this leads to inconsistency and a constant diff. Fixes
// https://github.com/crossplane-contrib/provider-aws/issues/1165
external.LambdaFunctionConfigurations = sanitizedLambdaFunctionConfigurations(external.LambdaFunctionConfigurations)
external.QueueConfigurations = sanitizedQueueConfigurations(external.QueueConfigurations)
external.TopicConfigurations = sanitizedTopicConfigurations(external.TopicConfigurations)

if cmp.Equal(external.LambdaFunctionConfigurations, generated.LambdaFunctionConfigurations, cmpopts.IgnoreTypes(document.NoSerde{}, types.LambdaFunctionConfiguration{}.Id), cmpopts.EquateEmpty()) &&
cmp.Equal(external.QueueConfigurations, generated.QueueConfigurations, cmpopts.IgnoreTypes(document.NoSerde{}, types.QueueConfiguration{}.Id), cmpopts.EquateEmpty()) &&
Expand Down Expand Up @@ -137,6 +139,34 @@ func sortTopic(configs []types.TopicConfiguration) {
})
}

func sanitizedLambdaFunctionConfigurations(configs []types.LambdaFunctionConfiguration) []types.LambdaFunctionConfiguration {
if configs == nil {
return []types.LambdaFunctionConfiguration{}
}

sConfig := (&convert.ConverterImpl{}).DeepCopyAWSLambdaFunctionConfiguration(configs)
for c := range sConfig {
if sConfig[c].Events == nil {
sConfig[c].Events = []types.Event{}
}
if sConfig[c].Filter == nil {
continue
}
if sConfig[c].Filter.Key == nil {
continue
}
if sConfig[c].Filter.Key.FilterRules == nil {
sConfig[c].Filter.Key.FilterRules = []types.FilterRule{}
}
for r := range sConfig[c].Filter.Key.FilterRules {
name := string(sConfig[c].Filter.Key.FilterRules[r].Name)
sConfig[c].Filter.Key.FilterRules[r].Name = types.FilterRuleName(strings.ToLower(name))
}
}

return sConfig
}

func sanitizedQueueConfigurations(configs []types.QueueConfiguration) []types.QueueConfiguration {
if configs == nil {
return []types.QueueConfiguration{}
Expand Down Expand Up @@ -165,6 +195,34 @@ func sanitizedQueueConfigurations(configs []types.QueueConfiguration) []types.Qu
return sConfig
}

func sanitizedTopicConfigurations(configs []types.TopicConfiguration) []types.TopicConfiguration {
if configs == nil {
return []types.TopicConfiguration{}
}

sConfig := (&convert.ConverterImpl{}).DeepCopyAWSTopicConfiguration(configs)
for c := range sConfig {
if sConfig[c].Events == nil {
sConfig[c].Events = []types.Event{}
}
if sConfig[c].Filter == nil {
continue
}
if sConfig[c].Filter.Key == nil {
continue
}
if sConfig[c].Filter.Key.FilterRules == nil {
sConfig[c].Filter.Key.FilterRules = []types.FilterRule{}
}
for r := range sConfig[c].Filter.Key.FilterRules {
name := string(sConfig[c].Filter.Key.FilterRules[r].Name)
sConfig[c].Filter.Key.FilterRules[r].Name = types.FilterRuleName(strings.ToLower(name))
}
}

return sConfig
}

// GenerateLambdaConfiguration creates []awss3.LambdaFunctionConfiguration from the local NotificationConfiguration
func GenerateLambdaConfiguration(config *v1beta1.NotificationConfiguration) []types.LambdaFunctionConfiguration {
// NOTE(muvaf): We skip prealloc because the behavior of AWS SDK differs when
Expand Down

0 comments on commit 7e2bc23

Please sign in to comment.