Skip to content

Commit

Permalink
Added Propagation of ManagedNodeGroup Tags to their AutoScalingGroups
Browse files Browse the repository at this point in the history
Changes	to ensure that AutoScalingGroups Tags are the same as their
 ManagedNodeGroup.

All tags are copied from the ManagedNodeGroup to the AutoScalingGroup.
If the tags already exists, it is overridden.

This is the default behaviour (as it is for Unmanaged NodeGroup) and
can be enabled using propagateASGTags boolean configuration.

Issue eksctl-io#1571
  • Loading branch information
SlevinWasAlreadyTaken committed Apr 22, 2022
1 parent 227ab2c commit c82003f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 8 deletions.
14 changes: 11 additions & 3 deletions pkg/apis/eksctl.io/v1alpha5/assets/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,12 @@
"desiredCapacity": {
"type": "integer"
},
"disableASGTagPropagation": {
"type": "boolean",
"description": "disables the tag propagation to ASG.",
"x-intellij-html-description": "disables the tag propagation to ASG.",
"default": false
},
"disableIMDSv1": {
"type": "boolean",
"description": "requires requests to the metadata service to use IMDSv2 tokens",
Expand Down Expand Up @@ -1191,6 +1197,7 @@
"additionalVolumes",
"preBootstrapCommands",
"overrideBootstrapCommand",
"disableASGTagPropagation",
"disableIMDSv1",
"disablePodIMDS",
"placement",
Expand Down Expand Up @@ -1321,8 +1328,9 @@
},
"disableASGTagPropagation": {
"type": "boolean",
"description": "disable the tag propagation in case desired capacity is 0.",
"x-intellij-html-description": "disable the tag propagation in case desired capacity is 0."
"description": "disables the tag propagation to ASG in case desired capacity is 0.",
"x-intellij-html-description": "disables the tag propagation to ASG in case desired capacity is 0.",
"default": false
},
"disableIMDSv1": {
"type": "boolean",
Expand Down Expand Up @@ -1538,6 +1546,7 @@
"additionalVolumes",
"preBootstrapCommands",
"overrideBootstrapCommand",
"disableASGTagPropagation",
"disableIMDSv1",
"disablePodIMDS",
"placement",
Expand All @@ -1556,7 +1565,6 @@
"kubeletExtraConfig",
"containerRuntime",
"propagateASGTags",
"disableASGTagPropagation",
"maxInstanceLifetime"
],
"additionalProperties": false,
Expand Down
9 changes: 5 additions & 4 deletions pkg/apis/eksctl.io/v1alpha5/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,6 @@ type NodeGroup struct {
// +optional
PropagateASGTags *bool `json:"propagateASGTags,omitempty"`

// DisableASGTagPropagation disable the tag propagation in case desired capacity is 0.
// +optional
DisableASGTagPropagation *bool `json:"disableASGTagPropagation,omitempty"`

// MaxInstanceLifetime defines the maximum amount of time in seconds an instance stays alive.
// +optional
MaxInstanceLifetime *int `json:"maxInstanceLifetime,omitempty"`
Expand Down Expand Up @@ -1368,6 +1364,11 @@ type NodeGroupBase struct {
// +optional
OverrideBootstrapCommand *string `json:"overrideBootstrapCommand,omitempty"`

// DisableASGTagPropagation disables the tag propagation to ASG in case desired capacity is 0.
// Defaults to `false`
// +optional
DisableASGTagPropagation *bool `json:"disableASGTagPropagation,omitempty"`

// DisableIMDSv1 requires requests to the metadata service to use IMDSv2 tokens
// Defaults to `false`
// +optional
Expand Down
8 changes: 8 additions & 0 deletions pkg/cfn/manager/create_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ func (c *StackCollection) NewManagedNodeGroupTask(ctx context.Context, nodeGroup
info: fmt.Sprintf("create managed nodegroup %q", ng.Name),
ctx: ctx,
})
if ng.DisableASGTagPropagation != nil && *ng.DisableASGTagPropagation {
continue
}
taskTree.Append(&managedNodeGroupTagsToASGPropagationTask{
stackCollection: c,
nodeGroup: ng,
info: fmt.Sprintf("propagate tags to ASG for managed nodegroup %q", ng.Name),
})
}
return taskTree
}
Expand Down
43 changes: 43 additions & 0 deletions pkg/cfn/manager/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,49 @@ func (c *StackCollection) createManagedNodeGroupTask(ctx context.Context, errorC
return c.CreateStack(ctx, name, stack, ng.Tags, nil, errorCh)
}

func (c *StackCollection) propagateManagedNodeGroupTagsToASGTask(errorCh chan error, ng *api.ManagedNodeGroup) error {
if ng.DisableASGTagPropagation != nil && *ng.DisableASGTagPropagation {
return nil
}

// describe node group to retrieve ASG names
input := &eks.DescribeNodegroupInput{
ClusterName: aws.String(c.spec.Metadata.Name),
NodegroupName: aws.String(ng.Name),
}
res, err := c.eksAPI.DescribeNodegroup(input)
if err != nil {
return errors.Wrapf(err, "couldn't get managed nodegroup details for nodegroup %q", ng.Name)
}

// set the managed nodegroup tags to all the ASGs found
if res.Nodegroup.Resources != nil {
// build the input tags for all ASGs attached to the managed nodegroup
asgTags := []*autoscaling.Tag{}

for _, asg := range res.Nodegroup.Resources.AutoScalingGroups {
for ngTagKey, ngTagValue := range ng.Tags {
asgTag := &autoscaling.Tag{
ResourceId: aws.String(*asg.Name),
ResourceType: aws.String("auto-scaling-group"),
Key: aws.String(ngTagKey),
Value: aws.String(ngTagValue),
PropagateAtLaunch: aws.Bool(false),
}
asgTags = append(asgTags, asgTag)
}
}

input := &autoscaling.CreateOrUpdateTagsInput{Tags: asgTags}
if _, err := c.asgAPI.CreateOrUpdateTags(input); err != nil {
return errors.Wrapf(err, "creating or updating asg tags for managed nodegroup %q", ng.Name)
}
}

go func() { errorCh <- nil }()
return nil
}

// DescribeNodeGroupStacks calls DescribeStacks and filters out nodegroups
func (c *StackCollection) DescribeNodeGroupStacks(ctx context.Context) ([]*Stack, error) {
stacks, err := c.DescribeStacks(ctx)
Expand Down
12 changes: 12 additions & 0 deletions pkg/cfn/manager/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ func (t *managedNodeGroupTask) Do(errorCh chan error) error {
return t.stackCollection.createManagedNodeGroupTask(t.ctx, errorCh, t.nodeGroup, t.forceAddCNIPolicy, t.vpcImporter)
}

type managedNodeGroupTagsToASGPropagationTask struct {
info string
nodeGroup *api.ManagedNodeGroup
stackCollection *StackCollection
}

func (t *managedNodeGroupTagsToASGPropagationTask) Describe() string { return t.info }

func (t *managedNodeGroupTagsToASGPropagationTask) Do(errorCh chan error) error {
return t.stackCollection.propagateManagedNodeGroupTagsToASGTask(errorCh, t.nodeGroup)
}

type clusterCompatTask struct {
info string
stackCollection *StackCollection
Expand Down
2 changes: 1 addition & 1 deletion userdocs/src/usage/autoscaling.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ nodeGroups:
k8s.io/cluster-autoscaler/node-template/taint/feaster: "true:NoSchedule"
```
For unmanaged noderoups, this is done by `eksctl` automatically if `propagateASGTags` is set to `true` like this:
For unmanaged and managed noderoups, this is done by `eksctl` automatically if `propagateASGTags` is set to `true` like this:

```yaml
nodeGroups:
Expand Down

0 comments on commit c82003f

Please sign in to comment.