Skip to content

Commit 74ade5a

Browse files
authored
Merge pull request #7866 from cPu1/bare-cluster
Cluster creation flexibility for default networking addons
2 parents 5aaba15 + 13885f7 commit 74ade5a

38 files changed

+802
-341
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ require (
6868
github.com/tj/assert v0.0.3
6969
github.com/vburenin/ifacemaker v1.2.1
7070
github.com/vektra/mockery/v2 v2.38.0
71-
github.com/weaveworks/goformation/v4 v4.10.2-0.20231113122203-bf1ae633f95c
71+
github.com/weaveworks/goformation/v4 v4.10.2-0.20240626091647-67263f64f317
7272
github.com/weaveworks/schemer v0.0.0-20230525114451-47139fe25848
7373
github.com/xgfone/netaddr v0.5.1
7474
golang.org/x/crypto v0.22.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,8 @@ github.com/vektra/mockery/v2 v2.38.0 h1:I0LBuUzZHqAU4d1DknW0DTFBPO6n8TaD38WL2KJf
18151815
github.com/vektra/mockery/v2 v2.38.0/go.mod h1:diB13hxXG6QrTR0ol2Rk8s2dRMftzvExSvPDKr+IYKk=
18161816
github.com/voxelbrain/goptions v0.0.0-20180630082107-58cddc247ea2 h1:txplJASvd6b/hrE0s/Ixfpp2cuwH9IO9oZBAN9iYa4A=
18171817
github.com/voxelbrain/goptions v0.0.0-20180630082107-58cddc247ea2/go.mod h1:DGCIhurYgnLz8J9ga1fMV/fbLDyUvTyrWXVWUIyJon4=
1818-
github.com/weaveworks/goformation/v4 v4.10.2-0.20231113122203-bf1ae633f95c h1:iejfxgm8iQ6Jr3yT7Javgk40drlL6w9B6+zgACs0fMw=
1819-
github.com/weaveworks/goformation/v4 v4.10.2-0.20231113122203-bf1ae633f95c/go.mod h1:3c2tyJmoge5qTS4PXS0niVJxR0YzroIBsts3dQI3EdI=
1818+
github.com/weaveworks/goformation/v4 v4.10.2-0.20240626091647-67263f64f317 h1:efLcD8csEtX1RO0444Wa4RQjO34pYuojsdPABc5QC3s=
1819+
github.com/weaveworks/goformation/v4 v4.10.2-0.20240626091647-67263f64f317/go.mod h1:3c2tyJmoge5qTS4PXS0niVJxR0YzroIBsts3dQI3EdI=
18201820
github.com/weaveworks/schemer v0.0.0-20230525114451-47139fe25848 h1:I7S+IHZIU49skVgTNArf9bIdy07mCn1Z0zv1r07ROws=
18211821
github.com/weaveworks/schemer v0.0.0-20230525114451-47139fe25848/go.mod h1:y8Luzq6JDsYVoIV0QAlnvIiq8bSaap0myMjWKyzVFTY=
18221822
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

integration/data/crud-podinfo.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: podinfo
6+
labels:
7+
app: podinfo
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: podinfo
13+
template:
14+
metadata:
15+
labels:
16+
app: podinfo
17+
annotations:
18+
prometheus.io/scrape: 'true'
19+
spec:
20+
nodeSelector:
21+
used-for: test-pods
22+
containers:
23+
- name: podinfod
24+
image: stefanprodan/podinfo:1.5.1@sha256:702633d438950f3675d0763a4ca6cfcf21a4d065cd7f470446c67607b1a26750
25+
securityContext:
26+
runAsNonRoot: true
27+
allowPrivilegeEscalation: false
28+
runAsUser: 1000
29+
command:
30+
- ./podinfo
31+
- --port=8080
32+
ports:
33+
- name: http
34+
containerPort: 8080
35+
protocol: TCP
36+
readinessProbe:
37+
httpGet:
38+
path: /readyz
39+
port: 8080
40+
initialDelaySeconds: 1
41+
periodSeconds: 5
42+
failureThreshold: 1
43+
livenessProbe:
44+
httpGet:
45+
path: /healthz
46+
port: 8080
47+
initialDelaySeconds: 1
48+
periodSeconds: 10
49+
failureThreshold: 2
50+
resources:
51+
requests:
52+
memory: "32Mi"
53+
cpu: "10m"

integration/data/podinfo.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ spec:
1717
annotations:
1818
prometheus.io/scrape: 'true'
1919
spec:
20-
nodeSelector:
21-
used-for: test-pods
2220
containers:
2321
- name: podinfod
2422
image: stefanprodan/podinfo:1.5.1@sha256:702633d438950f3675d0763a4ca6cfcf21a4d065cd7f470446c67607b1a26750

integration/tests/addons/addons_test.go

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,8 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {
107107
return cmd
108108
}, "5m", "30s").Should(RunSuccessfullyWithOutputStringLines(ContainElement(ContainSubstring("ACTIVE"))))
109109

110-
By("successfully creating the kube-proxy addon")
111-
cmd := params.EksctlCreateCmd.
112-
WithArgs(
113-
"addon",
114-
"--name", "kube-proxy",
115-
"--cluster", clusterName,
116-
"--force",
117-
"--wait",
118-
"--verbose", "2",
119-
)
120-
Expect(cmd).To(RunSuccessfully())
121-
122-
Eventually(func() runner.Cmd {
123-
cmd := params.EksctlGetCmd.
124-
WithArgs(
125-
"addon",
126-
"--name", "kube-proxy",
127-
"--cluster", clusterName,
128-
"--verbose", "2",
129-
)
130-
return cmd
131-
}, "5m", "30s").Should(RunSuccessfullyWithOutputStringLines(ContainElement(ContainSubstring("ACTIVE"))))
132-
133110
By("Deleting the kube-proxy addon")
134-
cmd = params.EksctlDeleteCmd.
111+
cmd := params.EksctlDeleteCmd.
135112
WithArgs(
136113
"addon",
137114
"--name", "kube-proxy",
@@ -155,12 +132,45 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {
155132
})
156133

157134
It("should have full control over configMap when creating addons", func() {
158-
var (
159-
clusterConfig *api.ClusterConfig
160-
configMap *corev1.ConfigMap
161-
)
135+
clusterConfig := getInitialClusterConfig()
136+
clusterConfig.Addons = []*api.Addon{
137+
{
138+
Name: "coredns",
139+
Version: "latest",
140+
},
141+
}
142+
cmd := params.EksctlCreateCmd.
143+
WithArgs(
144+
"addon",
145+
"--config-file", "-",
146+
).
147+
WithoutArg("--region", params.Region).
148+
WithStdin(clusterutils.Reader(clusterConfig))
149+
Expect(cmd).To(RunSuccessfully())
162150

163-
configMap = getConfigMap(rawClient.ClientSet(), "coredns")
151+
By("deleting coredns but preserving its resources")
152+
cmd = params.EksctlDeleteCmd.
153+
WithArgs(
154+
"addon",
155+
"--cluster", clusterConfig.Metadata.Name,
156+
"--name", "coredns",
157+
"--verbose", "4",
158+
"--preserve",
159+
"--region", params.Region,
160+
)
161+
Expect(cmd).To(RunSuccessfully())
162+
163+
Eventually(func() runner.Cmd {
164+
return params.EksctlGetCmd.
165+
WithArgs(
166+
"addon",
167+
"--name", "coredns",
168+
"--cluster", clusterName,
169+
"--verbose", "4",
170+
)
171+
}, "5m", "30s").ShouldNot(RunSuccessfully())
172+
173+
configMap := getConfigMap(rawClient.ClientSet(), "coredns")
164174
oldCacheValue := getCacheValue(configMap)
165175
newCacheValue := addToString(oldCacheValue, 5)
166176
updateCacheValue(configMap, oldCacheValue, newCacheValue)
@@ -178,14 +188,14 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {
178188
data, err := json.Marshal(clusterConfig)
179189
Expect(err).NotTo(HaveOccurred())
180190

181-
cmd := params.EksctlCreateCmd.
191+
cmd = params.EksctlCreateCmd.
182192
WithArgs(
183193
"addon",
184194
"--config-file", "-",
185195
).
186196
WithoutArg("--region", params.Region).
187197
WithStdin(bytes.NewReader(data))
188-
Expect(cmd).ShouldNot(RunSuccessfully())
198+
Expect(cmd).NotTo(RunSuccessfully())
189199

190200
Eventually(func() runner.Cmd {
191201
cmd := params.EksctlGetCmd.
@@ -866,7 +876,11 @@ func getInitialClusterConfig() *api.ClusterConfig {
866876
Name: "vpc-cni",
867877
AttachPolicyARNs: []string{"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"},
868878
},
879+
{
880+
Name: "kube-proxy",
881+
},
869882
}
883+
clusterConfig.AddonsConfig.DisableDefaultAddons = true
870884

871885
ng := &api.ManagedNodeGroup{
872886
NodeGroupBase: &api.NodeGroupBase{
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//go:build integration
2+
// +build integration
3+
4+
//revive:disable Not changing package name
5+
package bare_cluster
6+
7+
import (
8+
"context"
9+
"testing"
10+
11+
apierrors "k8s.io/apimachinery/pkg/api/errors"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
"k8s.io/client-go/kubernetes"
14+
"k8s.io/client-go/tools/clientcmd"
15+
16+
. "github.com/onsi/ginkgo/v2"
17+
. "github.com/onsi/gomega"
18+
19+
. "github.com/weaveworks/eksctl/integration/runner"
20+
"github.com/weaveworks/eksctl/integration/tests"
21+
clusterutils "github.com/weaveworks/eksctl/integration/utilities/cluster"
22+
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
23+
"github.com/weaveworks/eksctl/pkg/testutils"
24+
)
25+
26+
var params *tests.Params
27+
28+
func init() {
29+
testing.Init()
30+
params = tests.NewParams("bare-cluster")
31+
}
32+
33+
func TestBareCluster(t *testing.T) {
34+
testutils.RegisterAndRun(t)
35+
}
36+
37+
var _ = Describe("Bare Clusters", Ordered, func() {
38+
var clusterConfig *api.ClusterConfig
39+
40+
BeforeAll(func() {
41+
By("creating a cluster with only VPC CNI and no other default networking addons")
42+
clusterConfig = api.NewClusterConfig()
43+
clusterConfig.Metadata.Name = params.ClusterName
44+
clusterConfig.Metadata.Region = params.Region
45+
clusterConfig.AddonsConfig.DisableDefaultAddons = true
46+
clusterConfig.Addons = []*api.Addon{
47+
{
48+
Name: "vpc-cni",
49+
UseDefaultPodIdentityAssociations: true,
50+
},
51+
{
52+
Name: "eks-pod-identity-agent",
53+
},
54+
}
55+
cmd := params.EksctlCreateCmd.
56+
WithArgs(
57+
"cluster",
58+
"--config-file=-",
59+
"--verbose", "4",
60+
"--kubeconfig="+params.KubeconfigPath,
61+
).
62+
WithoutArg("--region", params.Region).
63+
WithStdin(clusterutils.Reader(clusterConfig))
64+
65+
Expect(cmd).To(RunSuccessfully())
66+
})
67+
68+
It("should have only VPC CNI installed", func() {
69+
config, err := clientcmd.BuildConfigFromFlags("", params.KubeconfigPath)
70+
Expect(err).NotTo(HaveOccurred())
71+
clientset, err := kubernetes.NewForConfig(config)
72+
Expect(err).NotTo(HaveOccurred())
73+
_, err = clientset.AppsV1().Deployments(metav1.NamespaceSystem).Get(context.Background(), "coredns", metav1.GetOptions{})
74+
Expect(apierrors.IsNotFound(err)).To(BeTrue(), "expected coredns to not exist")
75+
daemonSets := clientset.AppsV1().DaemonSets(metav1.NamespaceSystem)
76+
_, err = daemonSets.Get(context.Background(), "kube-proxy", metav1.GetOptions{})
77+
Expect(apierrors.IsNotFound(err)).To(BeTrue(), "expected kube-proxy to not exist")
78+
_, err = daemonSets.Get(context.Background(), "aws-node", metav1.GetOptions{})
79+
Expect(err).NotTo(HaveOccurred(), "expected aws-node to exist")
80+
})
81+
})
82+
83+
var _ = AfterSuite(func() {
84+
params.DeleteClusters()
85+
})

integration/tests/crud/creategetdelete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
274274
})
275275

276276
It("should deploy podinfo service to the cluster and access it via proxy", func() {
277-
d := test.CreateDeploymentFromFile(test.Namespace, "../../data/podinfo.yaml")
277+
d := test.CreateDeploymentFromFile(test.Namespace, "../../data/crud-podinfo.yaml")
278278
test.WaitForDeploymentReady(d, commonTimeout)
279279

280280
pods := test.ListPodsFromDeployment(d)
@@ -533,7 +533,7 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
533533
"1.1.1.1/32,2.2.2.0/24",
534534
"--approve",
535535
)).To(RunSuccessfully())
536-
Expect(k8sAPICall()).Should(HaveOccurred())
536+
Eventually(k8sAPICall, "5m", "20s").Should(HaveOccurred())
537537
})
538538

539539
It("should re-enable public access", func() {

0 commit comments

Comments
 (0)