Skip to content

Commit

Permalink
Fixed the count zombie_cluster resources (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma authored Aug 20, 2024
1 parent a50f1a7 commit 58dbe5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,19 @@ def _get_tags_of_zombie_resources(self, resources: list, resource_id_name: str,
cluster_delete_days = self.get_tag_name_from_tags(tags=tags, tag_name='ClusterDeleteDays')
if cluster_delete_days:
if resource_id in zombies:
tags = self.update_resource_tags(tags=tags, tag_name='ClusterDeleteDays',
tag_value=str(int(cluster_delete_days) + 1))
if self.dry_run == 'no':
tags = self.update_resource_tags(tags=tags, tag_name='ClusterDeleteDays',
tag_value=str(int(cluster_delete_days) + 1))
else:
tags = self.update_resource_tags(tags=tags, tag_name='ClusterDeleteDays', tag_value=str(0))
else:
tags = self.update_resource_tags(tags=tags, tag_name='ClusterDeleteDays', tag_value=str(0))
else:
if resource_id in zombies:
tags = self.update_resource_tags(tags=tags, tag_name='ClusterDeleteDays', tag_value=str(1))
if self.dry_run == 'no':
tags = self.update_resource_tags(tags=tags, tag_name='ClusterDeleteDays', tag_value=str(1))
else:
tags = self.update_resource_tags(tags=tags, tag_name='ClusterDeleteDays', tag_value=str(0))
if old_tags != tags:
try:
if aws_service == 'ec2':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import boto3
import pytest
from moto import mock_ec2, mock_elb, mock_elbv2, mock_s3

from cloud_governance.main.environment_variables import environment_variables
from cloud_governance.policy.aws.zombie_cluster_resource import ZombieClusterResources
from cloud_governance.common.clouds.aws.ec2.ec2_operations import EC2Operations
from tests.unittest.configs import DRY_RUN_YES, DRY_RUN_NO

tags = [
{'Key': 'kubernetes.io/cluster/unittest-test-cluster', 'Value': 'Owned'},
Expand Down Expand Up @@ -61,6 +64,7 @@ def test_delete_ec2_ami_after_seven():
This method tests the deletion of AMI image after seven days
:return:
"""
environment_variables.environment_variables_dict['dry_run'] = DRY_RUN_NO
ec2_client = boto3.client('ec2', region_name=region_name)
default_ami_id = 'ami-03cf127a'
ec2_resource = boto3.resource('ec2', region_name=region_name)
Expand Down

0 comments on commit 58dbe5b

Please sign in to comment.