diff --git a/pkg/apis/v1/labels.go b/pkg/apis/v1/labels.go index 55cd3ee7ec2a..f87eea423b5c 100644 --- a/pkg/apis/v1/labels.go +++ b/pkg/apis/v1/labels.go @@ -70,10 +70,10 @@ var ( // Adheres to cluster name pattern matching as specified in the API spec // https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html regexp.MustCompile(`^kubernetes\.io/cluster/[0-9A-Za-z][A-Za-z0-9\-_]*$`), - regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(karpv1.NodePoolLabelKey))), + regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(NodePoolTagKey))), regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(EKSClusterNameTagKey))), - regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(LabelNodeClass))), - regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(TagNodeClaim))), + regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(NodeClassTagKey))), + regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(NodeClaimTagKey))), } AMIFamilyBottlerocket = "Bottlerocket" AMIFamilyAL2 = "AL2" @@ -96,8 +96,6 @@ var ( ResourcePrivateIPv4Address corev1.ResourceName = "vpc.amazonaws.com/PrivateIPv4Address" ResourceEFA corev1.ResourceName = "vpc.amazonaws.com/efa" - EKSClusterNameTagKey = "eks:eks-cluster-name" - LabelNodeClass = apis.Group + "/ec2nodeclass" LabelTopologyZoneID = "topology.k8s.aws/zone-id" @@ -126,6 +124,9 @@ var ( AnnotationEC2NodeClassHashVersion = apis.Group + "/ec2nodeclass-hash-version" AnnotationInstanceTagged = apis.Group + "/tagged" - TagNodeClaim = coreapis.Group + "/nodeclaim" - TagName = "Name" + NodeClaimTagKey = coreapis.Group + "/nodeclaim" + NameTagKey = "Name" + NodePoolTagKey = karpv1.NodePoolLabelKey + NodeClassTagKey = LabelNodeClass + EKSClusterNameTagKey = "eks:eks-cluster-name" ) diff --git a/pkg/controllers/nodeclaim/tagging/controller.go b/pkg/controllers/nodeclaim/tagging/controller.go index 2589168b1b11..6c3294a810e5 100644 --- a/pkg/controllers/nodeclaim/tagging/controller.go +++ b/pkg/controllers/nodeclaim/tagging/controller.go @@ -99,8 +99,8 @@ func (c *Controller) Register(_ context.Context, m manager.Manager) error { func (c *Controller) tagInstance(ctx context.Context, nc *karpv1.NodeClaim, id string) error { tags := map[string]string{ - v1.TagName: nc.Status.NodeName, - v1.TagNodeClaim: nc.Name, + v1.NameTagKey: nc.Status.NodeName, + v1.NodeClaimTagKey: nc.Name, v1.EKSClusterNameTagKey: options.FromContext(ctx).ClusterName, } diff --git a/pkg/controllers/nodeclaim/tagging/suite_test.go b/pkg/controllers/nodeclaim/tagging/suite_test.go index 0005e4ce8a39..5039f4d86ae2 100644 --- a/pkg/controllers/nodeclaim/tagging/suite_test.go +++ b/pkg/controllers/nodeclaim/tagging/suite_test.go @@ -118,7 +118,7 @@ var _ = Describe("TaggingController", func() { ExpectObjectReconciled(ctx, env.Client, taggingController, nodeClaim) Expect(nodeClaim.Annotations).To(Not(HaveKey(v1.AnnotationInstanceTagged))) Expect(lo.ContainsBy(ec2Instance.Tags, func(tag ec2types.Tag) bool { - return *tag.Key == v1.TagName + return *tag.Key == v1.NameTagKey })).To(BeFalse()) }) @@ -134,7 +134,7 @@ var _ = Describe("TaggingController", func() { ExpectObjectReconciled(ctx, env.Client, taggingController, nodeClaim) Expect(nodeClaim.Annotations).To(Not(HaveKey(v1.AnnotationInstanceTagged))) Expect(lo.ContainsBy(ec2Instance.Tags, func(tag ec2types.Tag) bool { - return tag.Key == &v1.TagName + return tag.Key == &v1.NameTagKey })).To(BeFalse()) }) @@ -181,7 +181,7 @@ var _ = Describe("TaggingController", func() { ExpectObjectReconciled(ctx, env.Client, taggingController, nodeClaim) Expect(nodeClaim.Annotations).To(Not(HaveKey(v1.AnnotationInstanceTagged))) Expect(lo.ContainsBy(ec2Instance.Tags, func(tag ec2types.Tag) bool { - return tag.Key == &v1.TagName + return tag.Key == &v1.NameTagKey })).To(BeFalse()) }) @@ -209,8 +209,8 @@ var _ = Describe("TaggingController", func() { Expect(nodeClaim.Annotations).To(HaveKey(v1.AnnotationInstanceTagged)) expectedTags := map[string]string{ - v1.TagName: nodeClaim.Status.NodeName, - v1.TagNodeClaim: nodeClaim.Name, + v1.NameTagKey: nodeClaim.Status.NodeName, + v1.NodeClaimTagKey: nodeClaim.Name, v1.EKSClusterNameTagKey: options.FromContext(ctx).ClusterName, } ec2Instance := lo.Must(awsEnv.EC2API.Instances.Load(*ec2Instance.InstanceId)).(ec2types.Instance) @@ -223,12 +223,12 @@ var _ = Describe("TaggingController", func() { Expect(instanceTags).To(HaveKeyWithValue(tag, value)) } }, - Entry("with the karpenter.sh/nodeclaim tag", v1.TagName, v1.EKSClusterNameTagKey), - Entry("with the eks:eks-cluster-name tag", v1.TagName, v1.TagNodeClaim), - Entry("with the Name tag", v1.TagNodeClaim, v1.EKSClusterNameTagKey), - Entry("with the karpenter.sh/nodeclaim and eks:eks-cluster-name tags", v1.TagName), - Entry("with the Name and eks:eks-cluster-name tags", v1.TagNodeClaim), + Entry("with the karpenter.sh/nodeclaim tag", v1.NameTagKey, v1.EKSClusterNameTagKey), + Entry("with the eks:eks-cluster-name tag", v1.NameTagKey, v1.NodeClaimTagKey), + Entry("with the Name tag", v1.NodeClaimTagKey, v1.EKSClusterNameTagKey), + Entry("with the karpenter.sh/nodeclaim and eks:eks-cluster-name tags", v1.NameTagKey), + Entry("with the Name and eks:eks-cluster-name tags", v1.NodeClaimTagKey), Entry("with the karpenter.sh/nodeclaim and Name tags", v1.EKSClusterNameTagKey), - Entry("with nothing to tag", v1.TagNodeClaim, v1.EKSClusterNameTagKey, v1.TagName), + Entry("with nothing to tag", v1.NodeClaimTagKey, v1.EKSClusterNameTagKey, v1.NameTagKey), ) }) diff --git a/pkg/providers/instance/instance.go b/pkg/providers/instance/instance.go index 3e7fdf8d3561..e4541906425d 100644 --- a/pkg/providers/instance/instance.go +++ b/pkg/providers/instance/instance.go @@ -150,15 +150,15 @@ func (p *DefaultProvider) List(ctx context.Context) ([]*Instance, error) { Filters: []ec2types.Filter{ { Name: aws.String("tag-key"), - Values: []string{karpv1.NodePoolLabelKey}, + Values: []string{v1.NodePoolTagKey}, }, { Name: aws.String("tag-key"), - Values: []string{v1.LabelNodeClass}, + Values: []string{v1.NodeClassTagKey}, }, { - Name: aws.String("tag-key"), - Values: []string{fmt.Sprintf("kubernetes.io/cluster/%s", options.FromContext(ctx).ClusterName)}, + Name: aws.String(v1.EKSClusterNameTagKey), + Values: []string{options.FromContext(ctx).ClusterName}, }, instanceStateFilter, }, diff --git a/pkg/providers/launchtemplate/launchtemplate.go b/pkg/providers/launchtemplate/launchtemplate.go index b67f22e9e433..13fdd748c068 100644 --- a/pkg/providers/launchtemplate/launchtemplate.go +++ b/pkg/providers/launchtemplate/launchtemplate.go @@ -404,7 +404,7 @@ func (p *DefaultProvider) DeleteAll(ctx context.Context, nodeClass *v1.EC2NodeCl Values: []string{clusterName}, }, { - Name: aws.String(fmt.Sprintf("tag:%s", v1.LabelNodeClass)), + Name: aws.String(fmt.Sprintf("tag:%s", v1.NodeClassTagKey)), Values: []string{nodeClass.Name}, }, },