Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ec2_run policy #703

Merged
merged 1 commit into from
Dec 19, 2023
Merged

Conversation

athiruma
Copy link
Collaborator

Type of change

Note: Fill x in []

  • bug
  • enhancement
  • documentation
  • dependencies

Description

Added the ec2_run policy.
Created the ADR for the changes

For security reasons, all pull requests need to be approved first before running any automated CI

@athiruma athiruma added enhancement New feature or request ok-to-test PR ok to test labels Dec 16, 2023
@athiruma athiruma requested a review from ebattat December 16, 2023 10:19
@athiruma athiruma self-assigned this Dec 16, 2023
@athiruma athiruma force-pushed the run_ec2_policy branch 3 times, most recently from 2a9df1c to da5629c Compare December 16, 2023 16:11
@ebattat
Copy link
Collaborator

ebattat commented Dec 17, 2023

The best practice is to split this PR to 2:

  1. Add ADR
  2. Add ec2 run policy
    When you are mixing between 2 functions its difficult to debug it in case of errors and also difficult to review it.

:rtype:
"""
action = "deleted"
try:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should replace to case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, does python have the switch case? 🤔

return tag.get('Value').strip()
return ''

def get_clean_up_days_count(self, tags: list):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems it also updates the cleanup days value ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, It returns the clean_up days count. We have another method which updates the days count.
Check here.

self._s3_client.put_bucket_tagging(Bucket=resource_id, Tagging={'TagSet': tags})
elif self._policy == 'empty_roles':
self._iam_client.tag_role(RoleName=resource_id, Tags=tags)
elif self._policy in ('ip_unattached', 'unused_nat_gateway', 'zombie_snapshots', 'ebs_unattached', 'ec2_run'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about new policies that we will add in the future line s3_age, do you need add it also here ?
its very risky to tide to specific policy name !!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know. I was thinking about how I change the process. As of now, we will stick to it later we can replace it.

policies_list = self.__get_policies()
for policy_type, policies in policies_list.items():
# @Todo support for all the aws policies, currently supports ec2_run as urgent requirement
if self.__policy in policies and self.__policy == "ec2_run":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you ask for specific policy self.__policy == "ec2_run"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I specified in the new ADR, this is only for ec2_run. So this should work against only ec2_run. I'll activate other policies later. Its risky to activate all policies without testing.

@@ -48,7 +52,7 @@ def __init__(self):
self._environment_variables_dict['account'] = self.get_aws_account_alias_name().upper().replace('OPENSHIFT-', '')
self._environment_variables_dict['policy'] = EnvironmentVariables.get_env('policy', '')

self._environment_variables_dict['aws_non_cluster_policies'] = ['ec2_idle', 'ec2_stop', 'ec2_run', 'ebs_in_use',
self._environment_variables_dict['aws_non_cluster_policies'] = ['ec2_idle', 'ec2_stop', 'ebs_in_use',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do u remove ec2_run from this list ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the static approach. It is very bad to have like this.
Look this new ADR Dir structure. I added policy/cleanup, so all cleanup policies will reside in this folder and we will walk through this and run the policies.

else:
cleanup_days = 0
force_tag_update = self._aws_cleanup_policies.get_force_tag_update()
self._aws_cleanup_policies.update_resource_tags(resource_id=instance.get('InstanceId'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name should be update_resource_day_counts and not all the tags, do you update only the day count ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can rename the method. 👍


if self._es_operations.check_elastic_search_connection():
if policy_result:
if len(policy_result) > 500:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update what the meaning of 500 ?

@@ -11,7 +11,7 @@ This tool support the following policies:

* Real time Openshift Cluster cost, User cost
* [ec2_idle](../../cloud_governance/policy/aws/ec2_idle.py): idle ec2 in last 4 days, cpu < 2% & network < 5mb.
* [ec2_run](../../cloud_governance/policy/aws/ec2_run.py): running ec2.
* [ec2_run](../../cloud_governance/policy/aws/cleanup/ec2_run.py): running ec2.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you add cleanup ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved ec2_run to the cleanup folder. So we have all cleanup policies collectively. ADR

@athiruma
Copy link
Collaborator Author

The best practice is to split this PR to 2:

  1. Add ADR
  2. Add ec2 run policy
    When you are mixing between 2 functions its difficult to debug it in case of errors and also difficult to review it.

I added ADR for the ec2_run policy. It's not the two separate PRs. It was the better time to have the ADR. Thats why I added the major change.

@athiruma athiruma force-pushed the run_ec2_policy branch 6 times, most recently from f378d08 to 3bd9819 Compare December 18, 2023 21:17
@ebattat ebattat merged commit 9517e3c into redhat-performance:main Dec 19, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ok-to-test PR ok to test
Projects
Development

Successfully merging this pull request may close these issues.

2 participants