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

Allow users to override Name tag in autoscaling group #859

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions nodejs/eks/nodegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,14 +843,17 @@ ${customUserData}
}
const autoScalingGroupTags: InputTags = pulumi
.all([eksCluster.name, args.autoScalingGroupTags])
.apply(
([clusterName, asgTags]) =>
<aws.Tags>{
Name: `${clusterName}-worker`,
[`kubernetes.io/cluster/${clusterName}`]: "owned",
...asgTags,
Comment on lines -849 to -851
Copy link
Member

Choose a reason for hiding this comment

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

The spread in the original implementation is after the explicit name - and therefore if a Name exists in asgTags it should overwrite the Name specified before the spread.

Do you have example code which demonstrates the issue you're seeing with the custom name not being applied?

Copy link
Member

@danielrbradley danielrbradley Mar 8, 2023

Choose a reason for hiding this comment

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

Quick test run:

const clusterName = "test-cluster"
const asgTags = {
  Name: "overriden-name"
}
const result = {
  Name: `${clusterName}-worker`,
  [`kubernetes.io/cluster/${clusterName}`]: "owned",
  ...asgTags
};

console.log(result);

prints:

{
  kubernetes.io/cluster/test-cluster: "owned",
  Name: "overriden-name"
}

https://jsfiddle.net/5mgwru8t/

Copy link
Author

@zeevallin zeevallin Mar 10, 2023

Choose a reason for hiding this comment

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

As it stands now it works to set your own name with the tag, that's not the issue. But everytime you re-run the command you get a diff on tags since the value fetched from AWS does not contain the Name: {clusterName}-worker value.

There might be a difference between your example and how it works when evaluating it the way it's done in the code?

Copy link
Author

Choose a reason for hiding this comment

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

This happens every time you run preview or up but you've provided your own name tag.

                ~ aws:autoscaling/group:Group: (update)
                    [id=k8s-core]
                    [urn=urn:pulumi:dev.eu-central-1::k8s::eks:index:Cluster$aws:iam/instanceProfile:InstanceProfile$eks:index:NodeGroupV2$aws:autoscaling/group:Group::k8s-core]
                    [provider=urn:pulumi:dev.eu-central-1::k8s::pulumi:providers:aws::default_5_16_2::5f73b234-f1c8-489b-8de0-2c66cf783459]
                  ~ launchTemplate: {
                      ~ version: "18" => output<string>
                    }
                  ~ tags          : [
                      + [9]: {
                              + key              : "Name"
                              + propagateAtLaunch: true
                              + value            : "k8s-worker"
                            }
                    ]

},
);
.apply(([clusterName, asgTags]): aws.Tags => {
if (!asgTags) { asgTags = {} }
// The kubernetes.io/cluster/<cluster-name> tag is required to be set to "owned"
// Users should not be able to override this tag.
asgTags[`kubernetes.io/cluster/${clusterName}`] = "owned";
// Only set the Name tag if it's not already set to allow users to override it.
if (!asgTags["Name"]) {
asgTags["Name"] = `${clusterName}-worker`;
}
return <aws.Tags>asgTags;
});

const cfnTemplateBody = pulumi
.all([
Expand Down