Skip to content

Commit

Permalink
Remove subnet and security group selector defaulting. Limited relianc…
Browse files Browse the repository at this point in the history
…e on cluster-name
  • Loading branch information
ellistarn committed Jan 14, 2022
1 parent 459920f commit 4a9786f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 59 deletions.
10 changes: 5 additions & 5 deletions pkg/apis/provisioning/v1alpha5/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
20 changes: 0 additions & 20 deletions pkg/cloudprovider/aws/apis/v1alpha1/provider_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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): "*"}
}
27 changes: 8 additions & 19 deletions pkg/cloudprovider/aws/apis/v1alpha1/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 6 additions & 15 deletions website/content/en/docs/getting-started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}`.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4a9786f

Please sign in to comment.