Skip to content

Commit

Permalink
Merge pull request #2057 from wotolom/bucket-fix-notificationConfigur…
Browse files Browse the repository at this point in the history
…ation-diff

fix(bucket): also sanitize observed FilterRules.Name of lambda and topic configs
  • Loading branch information
MisterMX authored May 21, 2024
2 parents 72c3680 + f0a48f9 commit 031d774
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 031d774

Please sign in to comment.