(t *testing.T)
| 163 | } |
| 164 | |
| 165 | func 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()) |
nothing calls this directly
no test coverage detected