Skip to content

Commit d0bc984

Browse files
authored
fix: delete FileSystem Policy when null (#45)
Description of changes: Delete File system Policy when null Add tests ensuring Policy is deleted when removed from Spec By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 6cc113f commit d0bc984

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

pkg/resource/file_system/hooks.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ func (rm *resourceManager) syncPolicy(ctx context.Context, r *resource) (err err
224224
exit := rlog.Trace("rm.syncPolicy")
225225
defer func() { exit(err) }()
226226

227+
if r.ko.Spec.Policy == nil {
228+
return rm.deletePolicy(ctx, r)
229+
}
230+
227231
_, err = rm.sdkapi.PutFileSystemPolicy(
228232
ctx,
229233
&svcsdk.PutFileSystemPolicyInput{
@@ -236,6 +240,21 @@ func (rm *resourceManager) syncPolicy(ctx context.Context, r *resource) (err err
236240
return err
237241
}
238242

243+
func (rm *resourceManager) deletePolicy(ctx context.Context, r *resource) (err error) {
244+
rlog := ackrtlog.FromContext(ctx)
245+
exit := rlog.Trace("rm.deletePolicy")
246+
defer func() { exit(err) }()
247+
248+
_, err = rm.sdkapi.DeleteFileSystemPolicy(
249+
ctx,
250+
&svcsdk.DeleteFileSystemPolicyInput{
251+
FileSystemId: r.ko.Status.FileSystemID,
252+
},
253+
)
254+
rm.metrics.RecordAPICall("UPDATE", "DeleteFileSystemPolicy", err)
255+
return err
256+
}
257+
239258
func (rm *resourceManager) syncBackupPolicy(ctx context.Context, r *resource) (err error) {
240259
rlog := ackrtlog.FromContext(ctx)
241260
exit := rlog.Trace("rm.syncBackupPolicy")

test/e2e/tests/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_file_system_policy(self, filesystem_id: str) -> dict:
4343

4444
except Exception as e:
4545
logging.debug(e)
46-
return None
46+
return e
4747

4848
def get_file_system_lifecycle_policy(self, filesystem_id: str) -> dict:
4949
try:

test/e2e/tests/test_file_system.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ def test_update_policies(self, efs_client, simple_file_system):
140140
observedPolicy = validator.get_file_system_policy(file_system_id)
141141
assert json.loads(policy) == json.loads(observedPolicy)
142142

143+
updates = {
144+
"spec": {
145+
"policy": None
146+
}
147+
}
148+
k8s.patch_custom_resource(ref, updates)
149+
time.sleep(UPDATE_WAIT_AFTER_SECONDS)
150+
observedPolicyException = validator.get_file_system_policy(file_system_id)
151+
assert isinstance(observedPolicyException , efs_client.exceptions.PolicyNotFound)
152+
143153
def test_update_backup_policy(self, efs_client, simple_file_system):
144154
(ref, _, file_system_id) = simple_file_system
145155
assert file_system_id is not None

0 commit comments

Comments
 (0)