@@ -55,17 +55,14 @@ func (in *LoggingConfigurationClient) Observe(ctx context.Context, bucket *v1bet
5555 return NeedsUpdate , errorutils .Wrap (err , loggingGetFailed )
5656 }
5757 if ! cmp .Equal (GenerateAWSLogging (bucket .Spec .ForProvider .LoggingConfiguration ), external .LoggingEnabled ,
58- cmpopts .IgnoreTypes (& xpv1.Reference {}, & xpv1.Selector {}), cmpopts .IgnoreTypes (document.NoSerde {})) {
58+ cmpopts .EquateEmpty (), cmpopts . IgnoreTypes (& xpv1.Reference {}, & xpv1.Selector {}), cmpopts .IgnoreTypes (document.NoSerde {})) {
5959 return NeedsUpdate , nil
6060 }
6161 return Updated , nil
6262}
6363
6464// CreateOrUpdate sends a request to have resource created on AWS
6565func (in * LoggingConfigurationClient ) CreateOrUpdate (ctx context.Context , bucket * v1beta1.Bucket ) error {
66- if bucket .Spec .ForProvider .LoggingConfiguration == nil {
67- return nil
68- }
6966 input := GeneratePutBucketLoggingInput (meta .GetExternalName (bucket ), bucket .Spec .ForProvider .LoggingConfiguration )
7067 _ , err := in .client .PutBucketLogging (ctx , input )
7168 return errorutils .Wrap (err , loggingPutFailed )
@@ -76,44 +73,9 @@ func (*LoggingConfigurationClient) Delete(_ context.Context, _ *v1beta1.Bucket)
7673 return nil
7774}
7875
79- // LateInitialize is responsible for initializing the resource based on the external value
76+ // LateInitialize is not needed because loggingConfiguration is not something which is created be default
77+ // it means if it is not set in the desired state, but it exists on aws side it should be deleted(by CreateOrUpdate), not late initialized
8078func (in * LoggingConfigurationClient ) LateInitialize (ctx context.Context , bucket * v1beta1.Bucket ) error {
81- external , err := in .client .GetBucketLogging (ctx , & awss3.GetBucketLoggingInput {Bucket : pointer .ToOrNilIfZeroValue (meta .GetExternalName (bucket ))})
82- if err != nil {
83- return errorutils .Wrap (err , loggingGetFailed )
84- }
85-
86- if external == nil || external .LoggingEnabled == nil {
87- // There is no value send by AWS to initialize
88- return nil
89- }
90-
91- if bucket .Spec .ForProvider .LoggingConfiguration == nil {
92- // We need the configuration to exist so we can initialize
93- bucket .Spec .ForProvider .LoggingConfiguration = & v1beta1.LoggingConfiguration {}
94- }
95-
96- config := bucket .Spec .ForProvider .LoggingConfiguration
97- // Late initialize the target Bucket and target prefix
98- config .TargetBucket = pointer .LateInitialize (config .TargetBucket , external .LoggingEnabled .TargetBucket )
99- config .TargetPrefix = pointer .LateInitializeValueFromPtr (config .TargetPrefix , external .LoggingEnabled .TargetPrefix )
100- // If the there is an external target grant list, and the local one does not exist
101- // we create the target grant list
102- if len (external .LoggingEnabled .TargetGrants ) != 0 && config .TargetGrants == nil {
103- config .TargetGrants = make ([]v1beta1.TargetGrant , len (external .LoggingEnabled .TargetGrants ))
104- for i , v := range external .LoggingEnabled .TargetGrants {
105- config .TargetGrants [i ] = v1beta1.TargetGrant {
106- Grantee : v1beta1.TargetGrantee {
107- DisplayName : v .Grantee .DisplayName ,
108- EmailAddress : v .Grantee .EmailAddress ,
109- ID : v .Grantee .ID ,
110- Type : string (v .Grantee .Type ),
111- URI : v .Grantee .URI ,
112- },
113- Permission : string (v .Permission ),
114- }
115- }
116- }
11779 return nil
11880}
11981
@@ -125,24 +87,30 @@ func (in *LoggingConfigurationClient) SubresourceExists(bucket *v1beta1.Bucket)
12587// GeneratePutBucketLoggingInput creates the input for the PutBucketLogging request for the S3 Client
12688func GeneratePutBucketLoggingInput (name string , config * v1beta1.LoggingConfiguration ) * awss3.PutBucketLoggingInput {
12789 bci := & awss3.PutBucketLoggingInput {
128- Bucket : pointer .ToOrNilIfZeroValue (name ),
129- BucketLoggingStatus : & types.BucketLoggingStatus {LoggingEnabled : & types.LoggingEnabled {
130- TargetBucket : config .TargetBucket ,
131- TargetGrants : make ([]types.TargetGrant , 0 ),
132- TargetPrefix : pointer .ToOrNilIfZeroValue (config .TargetPrefix ),
133- }},
90+ Bucket : pointer .ToOrNilIfZeroValue (name ),
91+ BucketLoggingStatus : & types.BucketLoggingStatus {},
13492 }
135- for _ , grant := range config .TargetGrants {
136- bci .BucketLoggingStatus .LoggingEnabled .TargetGrants = append (bci .BucketLoggingStatus .LoggingEnabled .TargetGrants , types.TargetGrant {
137- Grantee : & types.Grantee {
138- DisplayName : grant .Grantee .DisplayName ,
139- EmailAddress : grant .Grantee .EmailAddress ,
140- ID : grant .Grantee .ID ,
141- Type : types .Type (grant .Grantee .Type ),
142- URI : grant .Grantee .URI ,
143- },
144- Permission : types .BucketLogsPermission (grant .Permission ),
145- })
93+ if config != nil {
94+ bci = & awss3.PutBucketLoggingInput {
95+ Bucket : pointer .ToOrNilIfZeroValue (name ),
96+ BucketLoggingStatus : & types.BucketLoggingStatus {LoggingEnabled : & types.LoggingEnabled {
97+ TargetBucket : config .TargetBucket ,
98+ TargetGrants : make ([]types.TargetGrant , 0 ),
99+ TargetPrefix : pointer .ToOrNilIfZeroValue (config .TargetPrefix ),
100+ }},
101+ }
102+ for _ , grant := range config .TargetGrants {
103+ bci .BucketLoggingStatus .LoggingEnabled .TargetGrants = append (bci .BucketLoggingStatus .LoggingEnabled .TargetGrants , types.TargetGrant {
104+ Grantee : & types.Grantee {
105+ DisplayName : grant .Grantee .DisplayName ,
106+ EmailAddress : grant .Grantee .EmailAddress ,
107+ ID : grant .Grantee .ID ,
108+ Type : types .Type (grant .Grantee .Type ),
109+ URI : grant .Grantee .URI ,
110+ },
111+ Permission : types .BucketLogsPermission (grant .Permission ),
112+ })
113+ }
146114 }
147115 return bci
148116}
@@ -155,9 +123,7 @@ func GenerateAWSLogging(local *v1beta1.LoggingConfiguration) *types.LoggingEnabl
155123 output := types.LoggingEnabled {
156124 TargetBucket : local .TargetBucket ,
157125 TargetPrefix : pointer .ToOrNilIfZeroValue (local .TargetPrefix ),
158- }
159- if local .TargetGrants != nil {
160- output .TargetGrants = make ([]types.TargetGrant , len (local .TargetGrants ))
126+ TargetGrants : []types.TargetGrant {},
161127 }
162128 for i := range local .TargetGrants {
163129 target := types.TargetGrant {
@@ -171,7 +137,7 @@ func GenerateAWSLogging(local *v1beta1.LoggingConfiguration) *types.LoggingEnabl
171137 Permission : types .BucketLogsPermission (local .TargetGrants [i ].Permission ),
172138 }
173139
174- output .TargetGrants [ i ] = target
140+ output .TargetGrants = append ( output . TargetGrants , target )
175141 }
176142 return & output
177143}
0 commit comments