Added test for the case when IMDS is disabled for the task.
@@ -51,15 +51,32 @@ func getECSBridgeResult() *current.Result {
}
func TestConfigureTaskNamespaceRouting(t *testing.T) {
+ var tests = []struct {
+ name string
+ blockIMDS bool
+ }{
+ {
+ name: "DisabledIMDS",
+ blockIMDS: true,
+ },
+ {
+ name: "EnabledIMDS",
+ blockIMDS: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
dockerClient := mock_dockerapi.NewMockDockerClient(ctrl)
- cniConig := getCNIConfig()
taskENI := getTaskENI()
+ cniConfig := getCNIConfig()
+ cniConfig.BlockInstanceMetadata = tt.blockIMDS
- cniConig.AdditionalLocalRoutes = append(cniConig.AdditionalLocalRoutes, cnitypes.IPNet{
+ cniConfig.AdditionalLocalRoutes = append(cniConfig.AdditionalLocalRoutes, cnitypes.IPNet{
IP: net.ParseIP("10.0.0.0"),
Mask: net.CIDRMask(24, 32),
})
@@ -71,7 +88,13 @@ func TestConfigureTaskNamespaceRouting(t *testing.T) {
cmd1 := fmt.Sprintf(windowsRouteDeleteCmdFormat, windowsDefaultRoute, bridgeEpName)
cmd2 := fmt.Sprintf(windowsRouteDeleteCmdFormat, "10.0.0.0/24", bridgeEpName)
cmd3 := fmt.Sprintf(windowsRouteAddCmdFormat, credentialsEndpointRoute, bridgeEpName)
- cmd4 := fmt.Sprintf(windowsRouteAddCmdFormat, imdsEndpointIPAddress, taskEPName)
+
+ var cmd4 string
+ if cniConfig.BlockInstanceMetadata {
+ cmd4 = fmt.Sprintf(windowsRouteAddCmdFormat, imdsEndpointIPAddress, loopbackInterfaceName)
+ } else {
+ cmd4 = fmt.Sprintf(windowsRouteAddCmdFormat, imdsEndpointIPAddress, taskEPName)
+ }
cmd5 := fmt.Sprintf(windowsRouteAddCmdFormat, "10.0.0.0/24", bridgeEpName)
finalCmd := strings.Join([]string{cmd1, cmd2, cmd3, cmd4, cmd5}, " && ")
@@ -96,6 +119,8 @@ func TestConfigureTaskNamespaceRouting(t *testing.T) {
)
nsHelper := NewNamespaceHelper(dockerClient)
- err := nsHelper.ConfigureTaskNamespaceRouting(ctx, taskENI, cniConig, getECSBridgeResult())
+ err := nsHelper.ConfigureTaskNamespaceRouting(ctx, taskENI, cniConfig, getECSBridgeResult())
assert.NoError(t, err)
+ })
+ }
}
