-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Describe the feature
Hi team, from a contributor perspective, I've been repeating myself a lot when working on 2 classes ManagedEc2EcsComputeEnvironment and ManagedEc2EksComputeEnvironment in https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-batch/lib/managed-compute-environment.ts
While adding 3 missing image type for #35839, I found that if there is no refactor, we will be repeating the same validation code https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-batch-computeenvironment-ec2configurationobject.html#cfn-batch-computeenvironment-ec2configurationobject-imagetype
Created this issue to know your thought on creating a new base class ManagedEc2ComputeEnvironment, then ECS and EKS can extend this base. Can see these properties and methods are exactly the same, good candidate for the base class:
- property instanceTypes
- property instanceClasses
- method addInstanceType
- method addInstanceClass
There are more duplicated properties from quick look, but at least with above 4 things we can start adding 3 missing image types in a clean way.
I believe the reason duplicated code keep being added is due to the 3rd class FargateComputeEnvironment which doesn't have any EC2-related props but is using the same base class.
Use Case
- Clean codebase
- Prevent the case when adding a new feature to ECS but forgot to do the same for EKS
Proposed Solution
Creating a new base class ManagedEc2ComputeEnvironment, then ECS and EKS can extend this base class. These 4 properties, methods are straight forward, can be a good starting point:
- property instanceTypes
- property instanceClasses
- method addInstanceType
- method addInstanceClass
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
AWS CDK Library version (aws-cdk-lib)
main
AWS CDK CLI version
main
Environment details (OS name and version, etc.)
Dev Container