Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal committed Feb 26, 2024
1 parent 69884dc commit 48abaf2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 33 deletions.
40 changes: 40 additions & 0 deletions pkg/controllers/nodeclass/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/aws/aws-sdk-go/service/iam"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/events"
Expand Down Expand Up @@ -107,6 +108,45 @@ var _ = Describe("NodeClassController", func() {
},
})
})
FContext("Cluster CIDR Resolution", func() {
BeforeEach(func() {
awsEnv.LaunchTemplateProvider.ClusterCIDR = nil
})
AfterEach(func() {
awsEnv.LaunchTemplateProvider.ClusterCIDR = lo.ToPtr("10.100.0.0/16")
})
It("should only resolve cluster CIDR for AL2023", func() {
for _, family := range []string{
v1beta1.AMIFamilyAL2,
v1beta1.AMIFamilyBottlerocket,
v1beta1.AMIFamilyUbuntu,
v1beta1.AMIFamilyWindows2019,
v1beta1.AMIFamilyWindows2022,
v1beta1.AMIFamilyCustom,
} {
nodeClass.Spec.AMIFamily = lo.ToPtr(family)
ExpectReconcileSucceeded(ctx, nodeClassController, client.ObjectKeyFromObject(nodeClass))
Expect(awsEnv.LaunchTemplateProvider.ClusterCIDR).To(BeNil())
}
})
It("should resolve cluster CIDR for IPv4 clusters", func() {
nodeClass.Spec.AMIFamily = lo.ToPtr(v1beta1.AMIFamilyAL2023)
ExpectReconcileSucceeded(ctx, nodeClassController, client.ObjectKeyFromObject(nodeClass))
Expect(lo.FromPtr(awsEnv.LaunchTemplateProvider.ClusterCIDR)).To(Equal("10.100.0.0/16"))
})
It("should resolve cluster CIDR for IPv6 clusters", func() {
awsEnv.EKSAPI.DescribeClusterBehavior.Output.Set(&eks.DescribeClusterOutput{
Cluster: &eks.Cluster{
KubernetesNetworkConfig: &eks.KubernetesNetworkConfigResponse{
ServiceIpv6Cidr: lo.ToPtr("2001:db8::/64"),
},
},
})
nodeClass.Spec.AMIFamily = lo.ToPtr(v1beta1.AMIFamilyAL2023)
ExpectReconcileSucceeded(ctx, nodeClassController, client.ObjectKeyFromObject(nodeClass))
Expect(lo.FromPtr(awsEnv.LaunchTemplateProvider.ClusterCIDR)).To(Equal("2001:2b8::/64"))
})
})
Context("Subnet Status", func() {
It("Should update EC2NodeClass status for Subnets", func() {
ExpectApplied(ctx, env.Client, nodeClass)
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func NewOperator(ctx context.Context, operator *operator.Operator) (context.Cont
operator.Elected(),
kubeDNSIP,
clusterEndpoint,
nil,
)
instanceTypeProvider := instancetype.NewProvider(
*sess.Config.Region,
Expand Down
30 changes: 0 additions & 30 deletions pkg/operator/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,4 @@ var _ = Describe("Operator", func() {
_, err := awscontext.ResolveClusterEndpoint(ctx, fakeEKSAPI)
Expect(err).To(HaveOccurred())
})
It("should resolve IPv4 cluster CIDR via call to API", func() {
ctx = options.ToContext(ctx, test.Options(test.OptionsFields{
ClusterName: lo.ToPtr("test-cluster"),
}))
fakeEKSAPI.DescribeClusterBehavior.Output.Set(&eks.DescribeClusterOutput{
Cluster: &eks.Cluster{
KubernetesNetworkConfig: &eks.KubernetesNetworkConfigResponse{
ServiceIpv4Cidr: lo.ToPtr("10.100.0.0/16"),
},
},
})
clusterCIDR, err := awscontext.ResolveClusterCIDR(ctx, fakeEKSAPI)
Expect(err).To(BeNil())
Expect(clusterCIDR).To(Equal("10.100.0.0/16"))
})
It("should resolve IPv6 cluster CIDR via call to API", func() {
ctx = options.ToContext(ctx, test.Options(test.OptionsFields{
ClusterName: lo.ToPtr("test-cluster"),
}))
fakeEKSAPI.DescribeClusterBehavior.Output.Set(&eks.DescribeClusterOutput{
Cluster: &eks.Cluster{
KubernetesNetworkConfig: &eks.KubernetesNetworkConfigResponse{
ServiceIpv6Cidr: lo.ToPtr("2001:db8::/64"),
},
},
})
clusterCIDR, err := awscontext.ResolveClusterCIDR(ctx, fakeEKSAPI)
Expect(err).To(BeNil())
Expect(clusterCIDR).To(Equal("2001:db8::/64"))
})
})
3 changes: 1 addition & 2 deletions pkg/providers/instancetype/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ func memory(ctx context.Context, info *ec2.InstanceTypeInfo) *resource.Quantity
// nolint:gocyclo
func ephemeralStorage(info *ec2.InstanceTypeInfo, amiFamily amifamily.AMIFamily, nodeClass *v1beta1.EC2NodeClass) *resource.Quantity {
// If local store disks have been configured for node ephemeral-storage, use the total size of the disks.
// if *nodeClass.Spec.AMIFamily == v1beta1.AMIFamilyAL2023 || lo.FromPtr(nodeClass.Spec.InstanceStorePolicy) == v1beta1.InstanceStorePolicyRAID0 {
if lo.FromPtr(nodeClass.Spec.InstanceStorePolicy) == v1beta1.InstanceStorePolicyRAID0 {
if *nodeClass.Spec.AMIFamily == v1beta1.AMIFamilyAL2023 || lo.FromPtr(nodeClass.Spec.InstanceStorePolicy) == v1beta1.InstanceStorePolicyRAID0 {
if info.InstanceStorageInfo != nil && info.InstanceStorageInfo.TotalSizeInGB != nil {
return resources.Quantity(fmt.Sprintf("%dG", *info.InstanceStorageInfo.TotalSizeInGB))
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/providers/launchtemplate/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Provider struct {

func NewProvider(ctx context.Context, cache *cache.Cache, ec2api ec2iface.EC2API, eksapi eksiface.EKSAPI, amiFamily *amifamily.Resolver,
securityGroupProvider *securitygroup.Provider, subnetProvider *subnet.Provider, instanceProfileProvider *instanceprofile.Provider,
caBundle *string, startAsync <-chan struct{}, kubeDNSIP net.IP, clusterEndpoint string) *Provider {
caBundle *string, startAsync <-chan struct{}, kubeDNSIP net.IP, clusterEndpoint string, clusterCIDR *string) *Provider {
l := &Provider{
ec2api: ec2api,
eksapi: eksapi,
Expand All @@ -94,6 +94,7 @@ func NewProvider(ctx context.Context, cache *cache.Cache, ec2api ec2iface.EC2API
cm: pretty.NewChangeMonitor(),
KubeDNSIP: kubeDNSIP,
ClusterEndpoint: clusterEndpoint,
ClusterCIDR: clusterCIDR,
}
l.cache.OnEvicted(l.cachedEvictedFunc(ctx))
go func() {
Expand Down Expand Up @@ -443,9 +444,11 @@ func (p *Provider) ResolveClusterCIDR(ctx context.Context) error {
}
if ipv4CIDR := out.Cluster.KubernetesNetworkConfig.ServiceIpv4Cidr; ipv4CIDR != nil {
p.ClusterCIDR = ipv4CIDR
logging.FromContext(ctx).Debugf("discovered cluster CIDR %q", p.ClusterCIDR)
return nil
}
if ipv6CIDR := out.Cluster.KubernetesNetworkConfig.ServiceIpv6Cidr; ipv6CIDR != nil {
logging.FromContext(ctx).Debugf("discovered cluster CIDR %q", p.ClusterCIDR)
p.ClusterCIDR = ipv6CIDR
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/test/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func init() {
type Environment struct {
// API
EC2API *fake.EC2API
EKSAPI *fake.EKSAPI
SSMAPI *fake.SSMAPI
IAMAPI *fake.IAMAPI
PricingAPI *fake.PricingAPI
Expand Down Expand Up @@ -120,6 +121,7 @@ func NewEnvironment(ctx context.Context, env *coretest.Environment) *Environment
make(chan struct{}),
net.ParseIP("10.0.100.10"),
"https://test-cluster",
lo.ToPtr("10.100.0.0/16"),
)
instanceProvider :=
instance.NewProvider(ctx,
Expand All @@ -133,6 +135,7 @@ func NewEnvironment(ctx context.Context, env *coretest.Environment) *Environment

return &Environment{
EC2API: ec2api,
EKSAPI: eksapi,
SSMAPI: ssmapi,
IAMAPI: iamapi,
PricingAPI: fakePricingAPI,
Expand Down

0 comments on commit 48abaf2

Please sign in to comment.