@@ -82,7 +82,7 @@ func (bal *BucketAccessListener) Add(ctx context.Context, inputBucketAccess *v1a
8282 "bucket" , bucketName ,
8383 )
8484
85- if bucketAccess .Spec . MintedSecretName != "" {
85+ if bucketAccess .Status . MintedSecret != nil {
8686 klog .V (5 ).InfoS ("AccessAlreadyGranted" ,
8787 "bucketAccess" , bucketAccess .Name ,
8888 "bucket" , bucketName ,
@@ -112,7 +112,7 @@ func (bal *BucketAccessListener) Add(ctx context.Context, inputBucketAccess *v1a
112112 return nil
113113 }
114114
115- if bucket .Spec .BucketID == "" {
115+ if bucket .Status .BucketID == "" {
116116 err := errors .New ("BucketID cannot be empty" )
117117 klog .ErrorS (err ,
118118 "Invalid arguments" ,
@@ -123,7 +123,7 @@ func (bal *BucketAccessListener) Add(ctx context.Context, inputBucketAccess *v1a
123123 }
124124
125125 req := & cosi.ProvisionerGrantBucketAccessRequest {
126- BucketId : bucket .Spec .BucketID ,
126+ BucketId : bucket .Status .BucketID ,
127127 AccountName : bucketAccess .Name ,
128128 AccessPolicy : bucketAccess .Spec .PolicyActionsConfigMapData ,
129129 }
@@ -177,16 +177,19 @@ func (bal *BucketAccessListener) Add(ctx context.Context, inputBucketAccess *v1a
177177 }
178178 }
179179
180- bucketAccess .Spec .AccountID = rsp .AccountId
180+ bucketAccess .Status .AccountID = rsp .AccountId
181+ bucketAccess .Status .MintedSecret = & corev1.SecretReference {
182+ Namespace : bal .namespace ,
183+ Name : mintedSecretName ,
184+ }
181185 bucketAccess .Status .AccessGranted = true
182- bucketAccess .Spec .MintedSecretName = mintedSecretName
183186
184187 // if this step fails, then controller will retry with backoff
185- if _ , err := bal .BucketAccesses ().Update (ctx , bucketAccess , metav1.UpdateOptions {}); err != nil {
186- klog .ErrorS (err , "Failed to update BucketAccess" ,
188+ if _ , err := bal .BucketAccesses ().UpdateStatus (ctx , bucketAccess , metav1.UpdateOptions {}); err != nil {
189+ klog .ErrorS (err , "Failed to update BucketAccess Status " ,
187190 "bucketAccess" , bucketAccess .Name ,
188191 "bucket" , bucket .Name )
189- return errors .Wrap (err , "Failed to update BucketAccess" )
192+ return errors .Wrap (err , "Failed to update BucketAccess Status " )
190193 }
191194
192195 return nil
@@ -212,6 +215,18 @@ func (bal *BucketAccessListener) Delete(ctx context.Context, bucketAccess *v1alp
212215 "name" , bucketAccess .Name ,
213216 "bucket" , bucketAccess .Spec .BucketName ,
214217 )
218+
219+ // TODO, check bucketAccess.Spec.DeletionPolicy
220+
221+ bucketAccess .Status .AccessGranted = false
222+
223+ // if this step fails, then controller will retry with backoff
224+ if _ , err := bal .BucketAccesses ().UpdateStatus (ctx , bucketAccess , metav1.UpdateOptions {}); err != nil {
225+ klog .ErrorS (err , "Failed to update BucketAccess Status" ,
226+ "bucketAccess" , bucketAccess .Name )
227+ return errors .Wrap (err , "Failed to update BucketAccess Status" )
228+ }
229+
215230 return nil
216231}
217232
0 commit comments