From 93cff0973a990c3fdcd31635283f4c39b2c4e72e Mon Sep 17 00:00:00 2001 From: Nathan Clonts Date: Thu, 17 Apr 2025 21:51:37 +0000 Subject: [PATCH 1/4] Schedule CoreDNS on Fargate even when eks.amazonaws.com/component selector is set --- go.mod | 2 +- go.sum | 2 ++ pkg/fargate/coredns/coredns.go | 2 +- pkg/fargate/coredns/coredns_test.go | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 3064e9a5f4..660bc89d7f 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.36.3 github.com/aws/aws-sdk-go-v2/config v1.29.12 github.com/aws/aws-sdk-go-v2/credentials v1.17.65 - github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.3 + github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4 github.com/aws/aws-sdk-go-v2/service/cloudformation v1.59.2 github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.48.4 github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.47.3 diff --git a/go.sum b/go.sum index 7a889d5343..7cbf41bfb7 100644 --- a/go.sum +++ b/go.sum @@ -126,6 +126,8 @@ github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.33 h1:/frG8aV09yhCVSOEC2pzktflJJO github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.33/go.mod h1:8vwASlAcV366M+qxZnjNzCjeastk1Rt1bpSRaGZanGU= github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.3 h1:QsKdBxtC8csnKt5BbV7D1op4Nf13p2YkTJIkppaCakw= github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.3/go.mod h1:CDqMoc3KRdZJ8qziW96J35lKH01Wq3B2aihtHj2JbRs= +github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4 h1:vzLD0FyNU4uxf2QE5UDG0jSEitiJXbVEUwf2Sk3usF4= +github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4/go.mod h1:CDqMoc3KRdZJ8qziW96J35lKH01Wq3B2aihtHj2JbRs= github.com/aws/aws-sdk-go-v2/service/cloudformation v1.59.2 h1:o9cuZdZlI9VWMqsNa2mnf2IRsFAROHnaYA1BW3lHGuY= github.com/aws/aws-sdk-go-v2/service/cloudformation v1.59.2/go.mod h1:penaZKzGmqHGZId4EUCBIW/f9l4Y7hQ5NKd45yoCYuI= github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.48.4 h1:pQpinmWv9jEisDR6/DccOf2cXdAf/CAwQ39nfJfJDlE= diff --git a/pkg/fargate/coredns/coredns.go b/pkg/fargate/coredns/coredns.go index 22fb826426..55837d9063 100644 --- a/pkg/fargate/coredns/coredns.go +++ b/pkg/fargate/coredns/coredns.go @@ -43,7 +43,7 @@ func IsSchedulableOnFargate(profiles []*api.FargateProfile) bool { } func selectsCoreDNS(selector api.FargateProfileSelector) bool { - return selector.Namespace == Namespace && len(selector.Labels) == 0 + return selector.Namespace == Namespace && (len(selector.Labels) == 0 || selector.Labels["eks.amazonaws.com/component"] == Name) } // IsScheduledOnFargate checks if EKS' coredns is scheduled onto Fargate. diff --git a/pkg/fargate/coredns/coredns_test.go b/pkg/fargate/coredns/coredns_test.go index f2a93df1a0..917386bdea 100644 --- a/pkg/fargate/coredns/coredns_test.go +++ b/pkg/fargate/coredns/coredns_test.go @@ -97,6 +97,23 @@ var _ = Describe("coredns", func() { Expect(coredns.IsSchedulableOnFargate(multipleProfilesWithOneSelectingCoreDNS)).To(BeTrue()) }) + It("should return true when a Fargate profile matches kube-system and has the CoreDNS component label", func() { + profileWithCoreDNSLabel := []*api.FargateProfile{ + { + Name: "selecting-coredns-with-label", + Selectors: []api.FargateProfileSelector{ + { + Namespace: "kube-system", + Labels: map[string]string{ + "eks.amazonaws.com/component": "coredns", + }, + }, + }, + }, + } + Expect(coredns.IsSchedulableOnFargate(profileWithCoreDNSLabel)).To(BeTrue()) + }) + It("should return true when provided the default Fargate profile", func() { cfg := api.NewClusterConfig() cfg.SetDefaultFargateProfile() From 6245d374650ebe1a931203909c4e7d2cd9ccc3cb Mon Sep 17 00:00:00 2001 From: Nathan Clonts Date: Thu, 17 Apr 2025 22:42:34 +0000 Subject: [PATCH 2/4] add test case --- pkg/fargate/coredns/coredns_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/fargate/coredns/coredns_test.go b/pkg/fargate/coredns/coredns_test.go index 917386bdea..ec2113b8a5 100644 --- a/pkg/fargate/coredns/coredns_test.go +++ b/pkg/fargate/coredns/coredns_test.go @@ -73,6 +73,21 @@ var ( }, } + profileWithCoreDNSLabelAndAdditionalLabels = []*api.FargateProfile{ + { + Name: "not-selecting-coredns-because-of-multiple-labels", + Selectors: []api.FargateProfileSelector{ + { + Namespace: "kube-system", + Labels: map[string]string{ + "eks.amazonaws.com/component": "coredns", + "environment": "prod", + }, + }, + }, + }, + } + profileNotSelectingCoreDNSBecauseOfNamespace = []*api.FargateProfile{ { Name: "not-selecting-coredns-because-of-namespace", @@ -124,6 +139,10 @@ var _ = Describe("coredns", func() { Expect(coredns.IsSchedulableOnFargate(profileNotSelectingCoreDNSBecauseOfLabels)).To(BeFalse()) }) + It("should return false when a Fargate profile has the CoreDNS component label but also additional labels", func() { + Expect(coredns.IsSchedulableOnFargate(profileWithCoreDNSLabelAndAdditionalLabels)).To(BeFalse()) + }) + It("should return false when a Fargate profile doesn't match kube-system", func() { Expect(coredns.IsSchedulableOnFargate(profileNotSelectingCoreDNSBecauseOfNamespace)).To(BeFalse()) }) From 1ae52b2db1cb09340fa01a7be9ca8be1da35deac Mon Sep 17 00:00:00 2001 From: Nathan Clonts Date: Fri, 18 Apr 2025 06:47:42 +0000 Subject: [PATCH 3/4] update tests --- pkg/fargate/coredns/coredns_test.go | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/pkg/fargate/coredns/coredns_test.go b/pkg/fargate/coredns/coredns_test.go index ec2113b8a5..d147f78c08 100644 --- a/pkg/fargate/coredns/coredns_test.go +++ b/pkg/fargate/coredns/coredns_test.go @@ -73,15 +73,14 @@ var ( }, } - profileWithCoreDNSLabelAndAdditionalLabels = []*api.FargateProfile{ + profileSelectingCoreDNSWithComponentLabel = []*api.FargateProfile{ { - Name: "not-selecting-coredns-because-of-multiple-labels", + Name: "selecting-coredns-with-label", Selectors: []api.FargateProfileSelector{ { Namespace: "kube-system", Labels: map[string]string{ "eks.amazonaws.com/component": "coredns", - "environment": "prod", }, }, }, @@ -113,20 +112,7 @@ var _ = Describe("coredns", func() { }) It("should return true when a Fargate profile matches kube-system and has the CoreDNS component label", func() { - profileWithCoreDNSLabel := []*api.FargateProfile{ - { - Name: "selecting-coredns-with-label", - Selectors: []api.FargateProfileSelector{ - { - Namespace: "kube-system", - Labels: map[string]string{ - "eks.amazonaws.com/component": "coredns", - }, - }, - }, - }, - } - Expect(coredns.IsSchedulableOnFargate(profileWithCoreDNSLabel)).To(BeTrue()) + Expect(coredns.IsSchedulableOnFargate(profileSelectingCoreDNSWithComponentLabel)).To(BeTrue()) }) It("should return true when provided the default Fargate profile", func() { @@ -139,10 +125,6 @@ var _ = Describe("coredns", func() { Expect(coredns.IsSchedulableOnFargate(profileNotSelectingCoreDNSBecauseOfLabels)).To(BeFalse()) }) - It("should return false when a Fargate profile has the CoreDNS component label but also additional labels", func() { - Expect(coredns.IsSchedulableOnFargate(profileWithCoreDNSLabelAndAdditionalLabels)).To(BeFalse()) - }) - It("should return false when a Fargate profile doesn't match kube-system", func() { Expect(coredns.IsSchedulableOnFargate(profileNotSelectingCoreDNSBecauseOfNamespace)).To(BeFalse()) }) From 6d6d8cf791dba8db357180d46351278ab7744b15 Mon Sep 17 00:00:00 2001 From: Nathan Clonts Date: Fri, 18 Apr 2025 06:52:56 +0000 Subject: [PATCH 4/4] go mod tidy --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 7cbf41bfb7..3e89e6eb65 100644 --- a/go.sum +++ b/go.sum @@ -124,8 +124,6 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 h1:bIqFDwgGXXN1Kpp99pDOdKMTTb5d github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3/go.mod h1:H5O/EsxDWyU+LP/V8i5sm8cxoZgc2fdNR9bxlOFrQTo= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.33 h1:/frG8aV09yhCVSOEC2pzktflJJO48NwY3xntHBwxHiA= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.33/go.mod h1:8vwASlAcV366M+qxZnjNzCjeastk1Rt1bpSRaGZanGU= -github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.3 h1:QsKdBxtC8csnKt5BbV7D1op4Nf13p2YkTJIkppaCakw= -github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.3/go.mod h1:CDqMoc3KRdZJ8qziW96J35lKH01Wq3B2aihtHj2JbRs= github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4 h1:vzLD0FyNU4uxf2QE5UDG0jSEitiJXbVEUwf2Sk3usF4= github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4/go.mod h1:CDqMoc3KRdZJ8qziW96J35lKH01Wq3B2aihtHj2JbRs= github.com/aws/aws-sdk-go-v2/service/cloudformation v1.59.2 h1:o9cuZdZlI9VWMqsNa2mnf2IRsFAROHnaYA1BW3lHGuY=