diff --git a/pkg/apis/provisioning/v1alpha5/register.go b/pkg/apis/provisioning/v1alpha5/register.go index abdbb183ccaf..64cb1d3e4cc1 100644 --- a/pkg/apis/provisioning/v1alpha5/register.go +++ b/pkg/apis/provisioning/v1alpha5/register.go @@ -40,11 +40,11 @@ var ( metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil }) - ProvisionerNameLabelKey = SchemeGroupVersion.Group + "/provisioner-name" - NotReadyTaintKey = SchemeGroupVersion.Group + "/not-ready" - DoNotEvictPodAnnotationKey = SchemeGroupVersion.Group + "/do-not-evict" - EmptinessTimestampAnnotationKey = SchemeGroupVersion.Group + "/emptiness-timestamp" - TerminationFinalizer = SchemeGroupVersion.Group + "/termination" + ProvisionerNameLabelKey = Group + "/provisioner-name" + NotReadyTaintKey = Group + "/not-ready" + DoNotEvictPodAnnotationKey = Group + "/do-not-evict" + EmptinessTimestampAnnotationKey = Group + "/emptiness-timestamp" + TerminationFinalizer = Group + "/termination" ) const ( diff --git a/pkg/cloudprovider/aws/apis/v1alpha1/provider_defaults.go b/pkg/cloudprovider/aws/apis/v1alpha1/provider_defaults.go index ae68956a011c..834062b86259 100644 --- a/pkg/cloudprovider/aws/apis/v1alpha1/provider_defaults.go +++ b/pkg/cloudprovider/aws/apis/v1alpha1/provider_defaults.go @@ -16,22 +16,16 @@ package v1alpha1 import ( "context" - "fmt" "github.com/aws/karpenter/pkg/apis/provisioning/v1alpha5" "github.com/aws/karpenter/pkg/utils/functional" - "github.com/aws/karpenter/pkg/utils/injection" v1 "k8s.io/api/core/v1" ) -var ClusterDiscoveryTagKeyFormat = "kubernetes.io/cluster/%s" - // Default the constraints. func (c *Constraints) Default(ctx context.Context) { c.defaultArchitecture() c.defaultCapacityTypes() - c.defaultSubnets(injection.GetOptions(ctx).ClusterName) - c.defaultSecurityGroups(injection.GetOptions(ctx).ClusterName) } func (c *Constraints) defaultCapacityTypes() { @@ -61,17 +55,3 @@ func (c *Constraints) defaultArchitecture() { Values: []string{v1alpha5.ArchitectureAmd64}, }) } - -func (c *Constraints) defaultSubnets(clusterName string) { - if c.SubnetSelector != nil { - return - } - c.SubnetSelector = map[string]string{fmt.Sprintf(ClusterDiscoveryTagKeyFormat, clusterName): "*"} -} - -func (c *Constraints) defaultSecurityGroups(clusterName string) { - if c.SecurityGroupSelector != nil { - return - } - c.SecurityGroupSelector = map[string]string{fmt.Sprintf(ClusterDiscoveryTagKeyFormat, clusterName): "*"} -} diff --git a/pkg/cloudprovider/aws/apis/v1alpha1/tags.go b/pkg/cloudprovider/aws/apis/v1alpha1/tags.go index a6cf7661f0c2..a4729fe2cb4f 100644 --- a/pkg/cloudprovider/aws/apis/v1alpha1/tags.go +++ b/pkg/cloudprovider/aws/apis/v1alpha1/tags.go @@ -20,28 +20,17 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/karpenter/pkg/apis/provisioning/v1alpha5" "github.com/aws/karpenter/pkg/utils/functional" "github.com/aws/karpenter/pkg/utils/injection" ) -const ( - // ClusterTagKeyFormat is set on all Kubernetes owned resources. - ClusterTagKeyFormat = "kubernetes.io/cluster/%s" - // KarpenterTagKeyFormat is set on all Karpenter owned resources. - KarpenterTagKeyFormat = "karpenter.sh/cluster/%s" -) - -func MergeTags(ctx context.Context, customTags map[string]string) []*ec2.Tag { - // We'll set some default tags, but allow them to be overridden in the merge - managedTags := map[string]string{ - "Name": fmt.Sprintf("karpenter.sh/cluster/%s/provisioner/%s", - injection.GetOptions(ctx).ClusterName, injection.GetNamespacedName(ctx).Name), - fmt.Sprintf(ClusterTagKeyFormat, injection.GetOptions(ctx).ClusterName): "owned", - fmt.Sprintf(KarpenterTagKeyFormat, injection.GetOptions(ctx).ClusterName): "owned", - } - ec2Tags := []*ec2.Tag{} - for key, value := range functional.UnionStringMaps(managedTags, customTags) { - ec2Tags = append(ec2Tags, &ec2.Tag{Key: aws.String(key), Value: aws.String(value)}) +func MergeTags(ctx context.Context, custom ...map[string]string) (tags []*ec2.Tag) { + for key, value := range functional.UnionStringMaps(append(custom, map[string]string{ + v1alpha5.ProvisionerNameLabelKey: injection.GetNamespacedName(ctx).Name, + "Name": fmt.Sprintf("%s/%s", v1alpha5.ProvisionerNameLabelKey, injection.GetNamespacedName(ctx).Name), + })...) { + tags = append(tags, &ec2.Tag{Key: aws.String(key), Value: aws.String(value)}) } - return ec2Tags + return tags } diff --git a/website/content/en/docs/getting-started/_index.md b/website/content/en/docs/getting-started/_index.md index 54c83fea6e0a..1ed812db573e 100644 --- a/website/content/en/docs/getting-started/_index.md +++ b/website/content/en/docs/getting-started/_index.md @@ -63,6 +63,8 @@ metadata: name: ${CLUSTER_NAME} region: ${AWS_DEFAULT_REGION} version: "1.21" + tags: + karpenter.sh/discovery: ${CLUSTER_NAME} managedNodeGroups: - instanceType: m5.large amiFamily: AmazonLinux2 @@ -82,21 +84,6 @@ Karpenter itself can run anywhere, including on [self-managed node groups](https Karpenter will provision EC2 instances in your account. -### Tag Subnets - -Karpenter discovers subnets tagged `kubernetes.io/cluster/$CLUSTER_NAME`. Add this tag to subnets associated configured for your cluster. -Retrieve the subnet IDs and tag them with the cluster name. - -```bash -SUBNET_IDS=$(aws cloudformation describe-stacks \ - --stack-name eksctl-${CLUSTER_NAME}-cluster \ - --query 'Stacks[].Outputs[?OutputKey==`SubnetsPrivate`].OutputValue' \ - --output text) -aws ec2 create-tags \ - --resources $(echo $SUBNET_IDS | tr ',' '\n') \ - --tags Key="kubernetes.io/cluster/${CLUSTER_NAME}",Value= -``` - ### Create the KarpenterNode IAM Role Instances launched by Karpenter must run with an InstanceProfile that grants permissions necessary to run containers and configure networking. Karpenter discovers the InstanceProfile using the name `KarpenterNodeRole-${ClusterName}`. @@ -236,6 +223,10 @@ spec: resources: cpu: 1000 provider: + subnetSelector: + karpenter.sh/discovery: ${CLUSTER_NAME} + securityGroupSelector: + karpenter.sh/discovery: ${CLUSTER_NAME} instanceProfile: KarpenterNodeInstanceProfile-${CLUSTER_NAME} ttlSecondsAfterEmpty: 30 EOF