Skip to content

Commit 3f57ee6

Browse files
committed
Fix tests
1 parent 3f8dff1 commit 3f57ee6

File tree

10 files changed

+106
-67
lines changed

10 files changed

+106
-67
lines changed

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: 19 additions & 28 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",
@@ -171,17 +148,28 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {
171148
WithStdin(clusterutils.Reader(clusterConfig))
172149
Expect(cmd).To(RunSuccessfully())
173150

151+
By("deleting coredns but preserving its resources")
174152
cmd = params.EksctlDeleteCmd.
175153
WithArgs(
176154
"addon",
155+
"--cluster", clusterConfig.Metadata.Name,
177156
"--name", "coredns",
178-
"--cluster", clusterName,
179-
"--verbose", "2",
180-
"--region", params.Region,
157+
"--verbose", "4",
181158
"--preserve",
159+
"--region", params.Region,
182160
)
183161
Expect(cmd).To(RunSuccessfully())
184162

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+
185173
configMap := getConfigMap(rawClient.ClientSet(), "coredns")
186174
oldCacheValue := getCacheValue(configMap)
187175
newCacheValue := addToString(oldCacheValue, 5)
@@ -207,7 +195,7 @@ var _ = Describe("(Integration) [EKS Addons test]", func() {
207195
).
208196
WithoutArg("--region", params.Region).
209197
WithStdin(bytes.NewReader(data))
210-
Expect(cmd).ShouldNot(RunSuccessfully())
198+
Expect(cmd).NotTo(RunSuccessfully())
211199

212200
Eventually(func() runner.Cmd {
213201
cmd := params.EksctlGetCmd.
@@ -888,6 +876,9 @@ func getInitialClusterConfig() *api.ClusterConfig {
888876
Name: "vpc-cni",
889877
AttachPolicyARNs: []string{"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"},
890878
},
879+
{
880+
Name: "kube-proxy",
881+
},
891882
}
892883
clusterConfig.AddonsConfig.DisableDefaultAddons = true
893884

integration/tests/crud/creategetdelete_test.go

Lines changed: 1 addition & 1 deletion
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)

integration/tests/update/update_cluster_test.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/hashicorp/go-version"
1414

15-
awseks "github.com/aws/aws-sdk-go-v2/service/eks"
1615
"github.com/aws/aws-sdk-go-v2/service/eks/types"
1716
"github.com/aws/aws-sdk-go/aws"
1817

@@ -208,17 +207,6 @@ var _ = Describe("(Integration) Upgrading cluster", func() {
208207
assertAddonError(updateAddonName, addonName)
209208
}
210209
})
211-
212-
It("should migrate to self-managed addons for testing `utils update`", func() {
213-
for _, addonName := range defaultNetworkingAddons {
214-
_, err := clusterProvider.AWSProvider.EKS().DeleteAddon(context.Background(), &awseks.DeleteAddonInput{
215-
ClusterName: aws.String(defaultCluster),
216-
AddonName: aws.String(addonName),
217-
Preserve: true,
218-
})
219-
Expect(err).NotTo(HaveOccurred())
220-
}
221-
})
222210
})
223211

224212
Context("addons", func() {
@@ -234,7 +222,7 @@ var _ = Describe("(Integration) Upgrading cluster", func() {
234222
)
235223
Expect(cmd).To(RunSuccessfully())
236224

237-
rawClient := getRawClient(clusterProvider)
225+
rawClient := getRawClient(context.Background(), clusterProvider)
238226
Eventually(func() string {
239227
daemonSet, err := rawClient.ClientSet().AppsV1().DaemonSets(metav1.NamespaceSystem).Get(context.TODO(), "kube-proxy", metav1.GetOptions{})
240228
Expect(err).NotTo(HaveOccurred())
@@ -249,7 +237,7 @@ var _ = Describe("(Integration) Upgrading cluster", func() {
249237
})
250238

251239
It("should upgrade aws-node", func() {
252-
rawClient := getRawClient(clusterProvider)
240+
rawClient := getRawClient(context.Background(), clusterProvider)
253241
getAWSNodeVersion := func() string {
254242
awsNode, err := rawClient.ClientSet().AppsV1().DaemonSets(metav1.NamespaceSystem).Get(context.TODO(), "aws-node", metav1.GetOptions{})
255243
Expect(err).NotTo(HaveOccurred())
@@ -365,8 +353,10 @@ func defaultClusterConfig() *api.ClusterConfig {
365353
}
366354
}
367355

368-
func getRawClient(ctl *eks.ClusterProvider) *kubewrapper.RawClient {
369-
rawClient, err := ctl.NewRawClient(defaultClusterConfig())
356+
func getRawClient(ctx context.Context, ctl *eks.ClusterProvider) *kubewrapper.RawClient {
357+
clusterConfig := defaultClusterConfig()
358+
Expect(ctl.RefreshClusterStatus(ctx, clusterConfig)).To(Succeed())
359+
rawClient, err := ctl.NewRawClient(clusterConfig)
370360
Expect(err).NotTo(HaveOccurred())
371361
return rawClient
372362
}

pkg/actions/addon/addon.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ type StackManager interface {
3737
type CreateClientSet func() (kubeclient.Interface, error)
3838

3939
type Manager struct {
40-
clusterConfig *api.ClusterConfig
41-
eksAPI awsapi.EKS
42-
withOIDC bool
43-
oidcManager *iamoidc.OpenIDConnectManager
44-
stackManager StackManager
45-
createClientSet CreateClientSet
40+
clusterConfig *api.ClusterConfig
41+
eksAPI awsapi.EKS
42+
withOIDC bool
43+
oidcManager *iamoidc.OpenIDConnectManager
44+
stackManager StackManager
45+
createClientSet CreateClientSet
46+
DisableAWSNodePatch bool
4647
}
4748

4849
func New(clusterConfig *api.ClusterConfig, eksAPI awsapi.EKS, stackManager StackManager, withOIDC bool, oidcManager *iamoidc.OpenIDConnectManager, createClientSet CreateClientSet) (*Manager, error) {

pkg/actions/addon/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (a *Manager) Create(ctx context.Context, addon *api.Addon, iamRoleCreator I
242242
logger.Warning(IAMPermissionsNotRequiredWarning(addon.Name))
243243
}
244244

245-
if addon.CanonicalName() == api.VPCCNIAddon {
245+
if !a.DisableAWSNodePatch && addon.CanonicalName() == api.VPCCNIAddon {
246246
logger.Debug("patching AWS node")
247247
err := a.patchAWSNodeSA(ctx)
248248
if err != nil {

pkg/actions/addon/tasks.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,20 @@ func CreateAddonTasks(ctx context.Context, cfg *api.ClusterConfig, clusterProvid
9898
if len(postAddons) > 0 {
9999
postTasks.Append(makeAddonTask(postAddons, cfg.HasNodes()))
100100
}
101-
var updateVPCCNI tasks.GenericTask
101+
var updateVPCCNI *tasks.GenericTask
102102
if vpcCNIAddon != nil && api.IsEnabled(cfg.IAM.WithOIDC) {
103-
updateVPCCNI = tasks.GenericTask{
103+
updateVPCCNI = &tasks.GenericTask{
104+
Description: "update VPC CNI to use IRSA if required",
104105
Doer: func() error {
105106
addonManager, err := createAddonManager(ctx, clusterProvider, cfg)
106107
if err != nil {
107108
return err
108109
}
109-
addonManager.setRecommendedPoliciesForIRSA(vpcCNIAddon)
110110
return addonManager.Update(ctx, vpcCNIAddon, nil, clusterProvider.AWSProvider.WaitTimeout())
111111
},
112112
}
113113
}
114-
return preTasks, postTasks, &updateVPCCNI, autoDefaultAddonNames
114+
return preTasks, postTasks, updateVPCCNI, autoDefaultAddonNames
115115
}
116116

117117
type createAddonTask struct {
@@ -135,6 +135,7 @@ func (t *createAddonTask) Do(errorCh chan error) error {
135135
return err
136136
}
137137

138+
addonManager.DisableAWSNodePatch = true
138139
// always install EKS Pod Identity Agent Addon first, if present,
139140
// as other addons might require IAM permissions
140141
for _, a := range t.addons {

pkg/eks/tasks.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (c *ClusterProvider) CreateExtraClusterConfigTasks(ctx context.Context, cfg
183183
newTasks := &tasks.TaskTree{
184184
Parallel: false,
185185
IsSubTask: true,
186+
Tasks: []tasks.Task{preNodeGroupAddons},
186187
}
187188

188189
newTasks.Append(&tasks.GenericTask{
@@ -208,9 +209,6 @@ func (c *ClusterProvider) CreateExtraClusterConfigTasks(ctx context.Context, cfg
208209
newTasks.Append(updateVPCCNITask)
209210
}
210211
}
211-
if preNodeGroupAddons.Len() > 0 {
212-
newTasks.Append(preNodeGroupAddons)
213-
}
214212

215213
if cfg.HasClusterCloudWatchLogging() {
216214
if logRetentionDays := cfg.CloudWatch.ClusterLogging.LogRetentionInDays; logRetentionDays != 0 {

pkg/nodebootstrap/al2023_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ var _ = DescribeTable("Unmanaged AL2023", func(e al2023Entry) {
4848
Expect(actual).To(Equal(e.expectedUserData))
4949
},
5050
Entry("default", al2023Entry{
51-
expectedUserData: wrapMIMEParts(nodeConfig),
51+
expectedUserData: wrapMIMEParts(xTablesLock + nodeConfig),
5252
}),
5353
Entry("efa enabled", al2023Entry{
5454
overrideNodegroupSettings: func(np api.NodePool) {
5555
np.BaseNodeGroup().EFAEnabled = aws.Bool(true)
5656
},
57-
expectedUserData: wrapMIMEParts(efaScript + nodeConfig),
57+
expectedUserData: wrapMIMEParts(xTablesLock + efaScript + nodeConfig),
5858
}),
5959
)
6060

@@ -83,26 +83,26 @@ var _ = DescribeTable("Managed AL2023", func(e al2023Entry) {
8383
Expect(actual).To(Equal(e.expectedUserData))
8484
},
8585
Entry("native AMI", al2023Entry{
86-
expectedUserData: "",
86+
expectedUserData: wrapMIMEParts(xTablesLock),
8787
}),
8888
Entry("native AMI && EFA enabled", al2023Entry{
8989
overrideNodegroupSettings: func(np api.NodePool) {
9090
np.BaseNodeGroup().EFAEnabled = aws.Bool(true)
9191
},
92-
expectedUserData: wrapMIMEParts(efaCloudhook),
92+
expectedUserData: wrapMIMEParts(xTablesLock + efaCloudhook),
9393
}),
9494
Entry("custom AMI", al2023Entry{
9595
overrideNodegroupSettings: func(np api.NodePool) {
9696
np.BaseNodeGroup().AMI = "ami-xxxx"
9797
},
98-
expectedUserData: wrapMIMEParts(managedNodeConfig),
98+
expectedUserData: wrapMIMEParts(xTablesLock + managedNodeConfig),
9999
}),
100100
Entry("custom AMI && EFA enabled", al2023Entry{
101101
overrideNodegroupSettings: func(np api.NodePool) {
102102
np.BaseNodeGroup().AMI = "ami-xxxx"
103103
np.BaseNodeGroup().EFAEnabled = aws.Bool(true)
104104
},
105-
expectedUserData: wrapMIMEParts(efaCloudhook + managedNodeConfig),
105+
expectedUserData: wrapMIMEParts(xTablesLock + efaCloudhook + managedNodeConfig),
106106
}),
107107
)
108108

@@ -274,6 +274,13 @@ Content-Type: multipart/mixed; boundary=//
274274
`
275275
}
276276

277+
xTablesLock = fmt.Sprintf(`--//
278+
Content-Type: text/x-shellscript
279+
Content-Type: charset="us-ascii"
280+
281+
%s
282+
`, assets.AL2023XTablesLock)
283+
277284
efaCloudhook = fmt.Sprintf(`--//
278285
Content-Type: text/cloud-boothook
279286
Content-Type: charset="us-ascii"

0 commit comments

Comments
 (0)