MCPcopy
hub / github.com/eksctl-io/eksctl / TestManagedNodeRole

Function TestManagedNodeRole

pkg/cfn/builder/managed_nodegroup_test.go:165–240  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestManagedNodeRole(t *testing.T) {
166 nodeRoleTests := []struct {
167 description string
168 nodeGroup *api.ManagedNodeGroup
169 expectedNewRole bool
170 expectedNodeRoleARN *gfnt.Value
171 }{
172 {
173 description: "InstanceRoleARN is not provided",
174 nodeGroup: &api.ManagedNodeGroup{
175 NodeGroupBase: &api.NodeGroupBase{},
176 },
177 expectedNewRole: true,
178 expectedNodeRoleARN: gfnt.MakeFnGetAtt(builder.GetIAMRoleName(), gfnt.NewString("Arn")), // creating new role
179 },
180 {
181 description: "InstanceRoleARN is provided",
182 nodeGroup: &api.ManagedNodeGroup{
183 NodeGroupBase: &api.NodeGroupBase{
184 IAM: &api.NodeGroupIAM{
185 InstanceRoleARN: "arn::DUMMY::DUMMYROLE",
186 },
187 },
188 },
189 expectedNewRole: false,
190 expectedNodeRoleARN: gfnt.NewString("arn::DUMMY::DUMMYROLE"), // using the provided role
191 },
192 {
193 description: "InstanceRoleARN is provided and normalized",
194 nodeGroup: &api.ManagedNodeGroup{
195 NodeGroupBase: &api.NodeGroupBase{
196 IAM: &api.NodeGroupIAM{
197 InstanceRoleARN: "arn:aws:iam::1234567890:role/foo/bar/baz/custom-eks-role",
198 },
199 },
200 },
201 expectedNewRole: false,
202 expectedNodeRoleARN: gfnt.NewString("arn:aws:iam::1234567890:role/custom-eks-role"),
203 },
204 }
205
206 for i, tt := range nodeRoleTests {
207 t.Run(fmt.Sprintf("%d: %s", i, tt.description), func(t *testing.T) {
208 require := require.New(t)
209 clusterConfig := api.NewClusterConfig()
210 clusterConfig.Status = &api.ClusterStatus{}
211 err := api.SetManagedNodeGroupDefaults(tt.nodeGroup, clusterConfig.Metadata, false)
212 require.NoError(err)
213 p := mockprovider.NewMockProvider()
214 fakeVPCImporter := new(vpcfakes.FakeImporter)
215 bootstrapper, err := nodebootstrap.NewManagedBootstrapper(clusterConfig, tt.nodeGroup)
216 require.NoError(err)
217 mockSubnetsAndAZInstanceSupport(clusterConfig, p,
218 []string{"us-west-2a"},
219 []string{}, // local zones
220 []ec2types.InstanceType{api.DefaultNodeType})
221 stack := builder.NewManagedNodeGroup(p.EC2(), clusterConfig, tt.nodeGroup, nil, bootstrapper, false, fakeVPCImporter)
222 err = stack.AddAllResources(context.Background())

Callers

nothing calls this directly

Calls 12

EC2Method · 0.95
GetIAMRoleNameFunction · 0.92
NewMockProviderFunction · 0.92
NewManagedBootstrapperFunction · 0.92
NewManagedNodeGroupFunction · 0.92
ParseJSONFunction · 0.92
NewMethod · 0.80
RunMethod · 0.65
AddAllResourcesMethod · 0.65
RenderJSONMethod · 0.65

Tested by

no test coverage detected