Skip to content

Commit

Permalink
Merge pull request #104 from tomoasleep/support-capacity-provider-str…
Browse files Browse the repository at this point in the history
…ategy

Support CapacityProviderStrategy
  • Loading branch information
Songmu authored Jul 4, 2024
2 parents ecbe01c + 0274d0e commit 4e8830d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
7 changes: 7 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func TestLoadConfig(t *testing.T) {
Group: "xxx",
PlatformVersion: "1.4.0",
LaunchType: "FARGATE",
CapacityProviderStrategy: []*CapacityProviderStrategyItem{
{
CapacityProvider: "FARGATE",
Weight: 1,
Base: 1,
},
},
NetworkConfiguration: &NetworkConfiguration{
AwsVpcConfiguration: &AwsVpcConfiguration{
Subnets: []string{"subnet-01234567", "subnet-12345678"},
Expand Down
41 changes: 30 additions & 11 deletions rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@ type Rule struct {

// Target cluster
type Target struct {
TargetID string `yaml:"targetId,omitempty" json:"targetId,omitempty"`
TaskDefinition string `yaml:"taskDefinition" json:"taskDefinition"`
TaskCount int32 `yaml:"taskCount,omitempty" json:"taskCount,omitempty"`
ContainerOverrides []*ContainerOverride `yaml:"containerOverrides,omitempty" json:"containerOverrides,omitempty"`
Role string `yaml:"role,omitempty" json:"role,omitempty"`
Group string `yaml:"group,omitempty" json:"group,omitempty"`
LaunchType string `yaml:"launch_type,omitempty" json:"launch_type,omitempty"`
PlatformVersion string `yaml:"platform_version,omitempty" json:"platform_version,omitempty"`
NetworkConfiguration *NetworkConfiguration `yaml:"network_configuration,omitempty" json:"network_configuration,omitempty"`
DeadLetterConfig *DeadLetterConfig `yaml:"dead_letter_config,omitempty" json:"dead_letter_config,omitempty"`
PropagateTags *string `yaml:"propagateTags,omitempty" json:"propagateTags,omitempty"`
TargetID string `yaml:"targetId,omitempty" json:"targetId,omitempty"`
TaskDefinition string `yaml:"taskDefinition" json:"taskDefinition"`
TaskCount int32 `yaml:"taskCount,omitempty" json:"taskCount,omitempty"`
ContainerOverrides []*ContainerOverride `yaml:"containerOverrides,omitempty" json:"containerOverrides,omitempty"`
Role string `yaml:"role,omitempty" json:"role,omitempty"`
Group string `yaml:"group,omitempty" json:"group,omitempty"`
CapacityProviderStrategy []*CapacityProviderStrategyItem `yaml:"capacityProviderStrategy,omitempty" json:"capacityProviderStrategy,omitempty"`
LaunchType string `yaml:"launch_type,omitempty" json:"launch_type,omitempty"`
PlatformVersion string `yaml:"platform_version,omitempty" json:"platform_version,omitempty"`
NetworkConfiguration *NetworkConfiguration `yaml:"network_configuration,omitempty" json:"network_configuration,omitempty"`
DeadLetterConfig *DeadLetterConfig `yaml:"dead_letter_config,omitempty" json:"dead_letter_config,omitempty"`
PropagateTags *string `yaml:"propagateTags,omitempty" json:"propagateTags,omitempty"`
}

// CapacityProviderStrategyItem represents ECS capacity provider strategy item
type CapacityProviderStrategyItem struct {
CapacityProvider string `yaml:"capacityProvider" json:"capacityProvider"`
Base int32 `yaml:"base" json:"base"`
Weight int32 `yaml:"weight" json:"weight"`
}

// ContainerOverride overrides container
Expand Down Expand Up @@ -222,6 +230,17 @@ func (r *Rule) ecsParameters() *cweTypes.EcsParameters {
if ta.LaunchType != "" {
p.LaunchType = cweTypes.LaunchType(ta.LaunchType)
}

var capacityProviderStrategy []cweTypes.CapacityProviderStrategyItem
for _, cps := range ta.CapacityProviderStrategy {
capacityProviderStrategy = append(capacityProviderStrategy, cweTypes.CapacityProviderStrategyItem{
CapacityProvider: aws.String(cps.CapacityProvider),
Base: cps.Base,
Weight: cps.Weight,
})
}
p.CapacityProviderStrategy = capacityProviderStrategy

if ta.PlatformVersion != "" {
p.PlatformVersion = aws.String(ta.PlatformVersion)
}
Expand Down
12 changes: 12 additions & 0 deletions rule_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ func (rg *ruleGetter) getRule(ctx context.Context, r *cweTypes.Rule) (*Rule, err

target.Group = aws.ToString(ecsParams.Group)
target.LaunchType = string(ecsParams.LaunchType)

var capacityProviderStrategy []*CapacityProviderStrategyItem
for _, cps := range ecsParams.CapacityProviderStrategy {
capacityProviderStrategy = append(capacityProviderStrategy, &CapacityProviderStrategyItem{
Base: cps.Base,
Weight: cps.Weight,
CapacityProvider: aws.ToString(cps.CapacityProvider),
})
}

target.CapacityProviderStrategy = capacityProviderStrategy

target.PlatformVersion = aws.ToString(ecsParams.PlatformVersion)
target.PropagateTags = aws.String(string(t.EcsParameters.PropagateTags))
if aws.ToString(target.PropagateTags) == "" {
Expand Down
7 changes: 7 additions & 0 deletions testdata/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"group": "xxx",
"platform_version": "1.4.0",
"launch_type": "FARGATE",
"capacityProviderStrategy": [
{
"capacityProvider": "FARGATE",
"base": 1,
"weight": 1
}
],
"network_configuration": {
"aws_vpc_configuration": {
"subnets": [
Expand Down
7 changes: 7 additions & 0 deletions testdata/sample.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ local envs = import 'envs.libsonnet';
"group": "xxx",
"platform_version": "1.4.0",
"launch_type": "FARGATE",
"capacityProviderStrategy": [
{
"capacityProvider": "FARGATE",
"base": 1,
"weight": 1
}
],
"network_configuration": envs.network_configuration,
"containerOverrides": [
{
Expand Down
4 changes: 4 additions & 0 deletions testdata/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ rules:
group: xxx
platform_version: 1.4.0
launch_type: FARGATE
capacityProviderStrategy:
- capacityProvider: "FARGATE"
base: 1
weight: 1
network_configuration:
aws_vpc_configuration:
subnets:
Expand Down

0 comments on commit 4e8830d

Please sign in to comment.