@@ -750,6 +750,27 @@ func DeleteVPC(e2eCtx *E2EContext, vpcID string) (bool, error) {
750
750
return true , nil
751
751
}
752
752
753
+ func ListVpcSubnets (e2eCtx * E2EContext , vpcID string ) ([]* ec2.Subnet , error ) {
754
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
755
+
756
+ filter := & ec2.Filter {
757
+ Name : aws .String ("vpc-id" ),
758
+ Values : aws .StringSlice ([]string {vpcID }),
759
+ }
760
+
761
+ input := & ec2.DescribeSubnetsInput {
762
+ Filters : []* ec2.Filter {
763
+ filter ,
764
+ },
765
+ }
766
+
767
+ result , err := ec2Svc .DescribeSubnets (input )
768
+ if err != nil {
769
+ return nil , err
770
+ }
771
+ return result .Subnets , nil
772
+ }
773
+
753
774
func GetSubnet (e2eCtx * E2EContext , subnetID string ) (* ec2.Subnet , error ) {
754
775
ec2Svc := ec2 .New (e2eCtx .AWSSession )
755
776
@@ -771,7 +792,7 @@ func GetSubnet(e2eCtx *E2EContext, subnetID string) (*ec2.Subnet, error) {
771
792
return result .Subnets [0 ], nil
772
793
}
773
794
774
- func CreateSubnet (e2eCtx * E2EContext , subnetName string , cidrBlock string , az string , vpcID string ) (* ec2.Subnet , error ) {
795
+ func CreateSubnet (e2eCtx * E2EContext , clusterName string , cidrBlock string , az string , vpcID string , st string ) (* ec2.Subnet , error ) {
775
796
ec2Svc := ec2 .New (e2eCtx .AWSSession )
776
797
777
798
input := & ec2.CreateSubnetInput {
@@ -783,13 +804,31 @@ func CreateSubnet(e2eCtx *E2EContext, subnetName string, cidrBlock string, az st
783
804
Tags : []* ec2.Tag {
784
805
{
785
806
Key : aws .String ("Name" ),
786
- Value : aws .String (subnetName ),
807
+ Value : aws .String (clusterName + "-subnet-" + st ),
808
+ },
809
+ {
810
+ Key : aws .String ("kubernetes.io/cluster/" + clusterName ),
811
+ Value : aws .String ("shared" ),
787
812
},
788
813
},
789
814
},
790
815
},
791
816
}
792
817
818
+ // Tag subnet based on type(st)
819
+ switch st {
820
+ case "private" :
821
+ input .TagSpecifications [0 ].Tags = append (input .TagSpecifications [0 ].Tags , & ec2.Tag {
822
+ Key : aws .String ("kubernetes.io/role/internal-elb" ),
823
+ Value : aws .String ("1" ),
824
+ })
825
+ case "public" :
826
+ input .TagSpecifications [0 ].Tags = append (input .TagSpecifications [0 ].Tags , & ec2.Tag {
827
+ Key : aws .String ("kubernetes.io/role/elb" ),
828
+ Value : aws .String ("1" ),
829
+ })
830
+ }
831
+
793
832
if az != "" {
794
833
input .AvailabilityZone = aws .String (az )
795
834
}
@@ -1069,6 +1108,48 @@ func CreateRouteTable(e2eCtx *E2EContext, rtName string, vpcID string) (*ec2.Rou
1069
1108
return result .RouteTable , nil
1070
1109
}
1071
1110
1111
+ func ListVpcRouteTables (e2eCtx * E2EContext , vpcID string ) ([]* ec2.RouteTable , error ) {
1112
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1113
+
1114
+ filter := & ec2.Filter {
1115
+ Name : aws .String ("vpc-id" ),
1116
+ Values : aws .StringSlice ([]string {vpcID }),
1117
+ }
1118
+
1119
+ input := & ec2.DescribeRouteTablesInput {
1120
+ Filters : []* ec2.Filter {
1121
+ filter ,
1122
+ },
1123
+ }
1124
+
1125
+ result , err := ec2Svc .DescribeRouteTables (input )
1126
+ if err != nil {
1127
+ return nil , err
1128
+ }
1129
+ return result .RouteTables , nil
1130
+ }
1131
+
1132
+ func ListSubnetRouteTables (e2eCtx * E2EContext , subnetID string ) ([]* ec2.RouteTable , error ) {
1133
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1134
+
1135
+ filter := & ec2.Filter {
1136
+ Name : aws .String ("association.subnet-id" ),
1137
+ Values : aws .StringSlice ([]string {subnetID }),
1138
+ }
1139
+
1140
+ input := & ec2.DescribeRouteTablesInput {
1141
+ Filters : []* ec2.Filter {
1142
+ filter ,
1143
+ },
1144
+ }
1145
+
1146
+ result , err := ec2Svc .DescribeRouteTables (input )
1147
+ if err != nil {
1148
+ return nil , err
1149
+ }
1150
+ return result .RouteTables , nil
1151
+ }
1152
+
1072
1153
func GetRouteTable (e2eCtx * E2EContext , rtID string ) (* ec2.RouteTable , error ) {
1073
1154
ec2Svc := ec2 .New (e2eCtx .AWSSession )
1074
1155
@@ -1144,3 +1225,211 @@ func DeleteRoute(e2eCtx *E2EContext, rtID string, destinationCidr string) (bool,
1144
1225
}
1145
1226
return true , nil
1146
1227
}
1228
+
1229
+ func CreateSecurityGroup (e2eCtx * E2EContext , sgName string , sgDescription string , vpcID string ) (* ec2.CreateSecurityGroupOutput , error ) {
1230
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1231
+
1232
+ input := & ec2.CreateSecurityGroupInput {
1233
+ VpcId : aws .String (vpcID ),
1234
+ GroupName : aws .String (sgName ),
1235
+ Description : aws .String (sgDescription ),
1236
+ TagSpecifications : []* ec2.TagSpecification {
1237
+ {
1238
+ ResourceType : aws .String ("security-group" ),
1239
+ Tags : []* ec2.Tag {
1240
+ {
1241
+ Key : aws .String ("Name" ),
1242
+ Value : aws .String (sgName ),
1243
+ },
1244
+ },
1245
+ },
1246
+ },
1247
+ }
1248
+
1249
+ result , err := ec2Svc .CreateSecurityGroup (input )
1250
+ if err != nil {
1251
+ return nil , err
1252
+ }
1253
+ return result , nil
1254
+ }
1255
+
1256
+ func GetSecurityGroup (e2eCtx * E2EContext , sgID string ) (* ec2.SecurityGroup , error ) {
1257
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1258
+
1259
+ filter := & ec2.Filter {
1260
+ Name : aws .String ("group-id" ),
1261
+ Values : aws .StringSlice ([]string {sgID }),
1262
+ }
1263
+
1264
+ input := & ec2.DescribeSecurityGroupsInput {
1265
+ Filters : []* ec2.Filter {
1266
+ filter ,
1267
+ },
1268
+ }
1269
+
1270
+ result , err := ec2Svc .DescribeSecurityGroups (input )
1271
+ if err != nil {
1272
+ return nil , err
1273
+ }
1274
+ return result .SecurityGroups [0 ], nil
1275
+ }
1276
+
1277
+ func DeleteSecurityGroup (e2eCtx * E2EContext , sgID string ) (bool , error ) {
1278
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1279
+
1280
+ input := & ec2.DeleteSecurityGroupInput {
1281
+ GroupId : aws .String (sgID ),
1282
+ }
1283
+
1284
+ if _ , err := ec2Svc .DeleteSecurityGroup (input ); err != nil {
1285
+ return false , err
1286
+ }
1287
+ return true , nil
1288
+ }
1289
+
1290
+ func ListSecurityGroupRules (e2eCtx * E2EContext , sgID string ) ([]* ec2.SecurityGroupRule , error ) {
1291
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1292
+
1293
+ filter := & ec2.Filter {
1294
+ Name : aws .String ("group-id" ),
1295
+ Values : aws .StringSlice ([]string {sgID }),
1296
+ }
1297
+
1298
+ input := & ec2.DescribeSecurityGroupRulesInput {
1299
+ Filters : []* ec2.Filter {
1300
+ filter ,
1301
+ },
1302
+ }
1303
+
1304
+ result , err := ec2Svc .DescribeSecurityGroupRules (input )
1305
+ if err != nil {
1306
+ return nil , err
1307
+ }
1308
+ return result .SecurityGroupRules , nil
1309
+ }
1310
+
1311
+ func GetSecurityGroupRule (e2eCtx * E2EContext , sgrID string ) (* ec2.SecurityGroupRule , error ) {
1312
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1313
+
1314
+ filter := & ec2.Filter {
1315
+ Name : aws .String ("security-group-rule-id" ),
1316
+ Values : aws .StringSlice ([]string {sgrID }),
1317
+ }
1318
+
1319
+ input := & ec2.DescribeSecurityGroupRulesInput {
1320
+ Filters : []* ec2.Filter {
1321
+ filter ,
1322
+ },
1323
+ }
1324
+
1325
+ result , err := ec2Svc .DescribeSecurityGroupRules (input )
1326
+ if err != nil {
1327
+ return nil , err
1328
+ }
1329
+ return result .SecurityGroupRules [0 ], nil
1330
+ }
1331
+
1332
+ func CreateSecurityGroupIngressRule (e2eCtx * E2EContext , sgID string , sgrDescription string , cidr string , protocol string , fromPort int64 , toPort int64 ) (bool , error ) {
1333
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1334
+
1335
+ ipPerm := & ec2.IpPermission {
1336
+ FromPort : aws .Int64 (fromPort ),
1337
+ ToPort : aws .Int64 (toPort ),
1338
+ IpProtocol : aws .String (protocol ),
1339
+ IpRanges : []* ec2.IpRange {
1340
+ {
1341
+ CidrIp : aws .String (cidr ),
1342
+ Description : aws .String (sgrDescription ),
1343
+ },
1344
+ },
1345
+ }
1346
+
1347
+ input := & ec2.AuthorizeSecurityGroupIngressInput {
1348
+ GroupId : aws .String (sgID ),
1349
+ IpPermissions : []* ec2.IpPermission {
1350
+ ipPerm ,
1351
+ },
1352
+ }
1353
+
1354
+ result , err := ec2Svc .AuthorizeSecurityGroupIngress (input )
1355
+ if err != nil {
1356
+ return false , err
1357
+ }
1358
+ return * result .Return , nil
1359
+ }
1360
+
1361
+ func CreateSecurityGroupEgressRule (e2eCtx * E2EContext , sgID string , sgrDescription string , cidr string , protocol string , fromPort int64 , toPort int64 ) (bool , error ) {
1362
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1363
+
1364
+ ipPerm := & ec2.IpPermission {
1365
+ FromPort : aws .Int64 (fromPort ),
1366
+ ToPort : aws .Int64 (toPort ),
1367
+ IpProtocol : aws .String (protocol ),
1368
+ IpRanges : []* ec2.IpRange {
1369
+ {
1370
+ CidrIp : aws .String (cidr ),
1371
+ Description : aws .String (sgrDescription ),
1372
+ },
1373
+ },
1374
+ }
1375
+
1376
+ input := & ec2.AuthorizeSecurityGroupEgressInput {
1377
+ GroupId : aws .String (sgID ),
1378
+ IpPermissions : []* ec2.IpPermission {
1379
+ ipPerm ,
1380
+ },
1381
+ }
1382
+ result , err := ec2Svc .AuthorizeSecurityGroupEgress (input )
1383
+ if err != nil {
1384
+ return false , err
1385
+ }
1386
+ return * result .Return , nil
1387
+ }
1388
+
1389
+ func CreateSecurityGroupRule (e2eCtx * E2EContext , sgID string , sgrDescription string , cidr string , protocol string , fromPort int64 , toPort int64 , rt string ) (bool , error ) {
1390
+ switch rt {
1391
+ case "ingress" :
1392
+ return CreateSecurityGroupIngressRule (e2eCtx , sgID , sgrDescription , cidr , protocol , fromPort , toPort )
1393
+ case "egress" :
1394
+ return CreateSecurityGroupEgressRule (e2eCtx , sgID , sgrDescription , cidr , protocol , fromPort , toPort )
1395
+ }
1396
+ return false , nil
1397
+ }
1398
+
1399
+ func DeleteSecurityGroupIngressRule (e2eCtx * E2EContext , sgrID string ) (bool , error ) {
1400
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1401
+
1402
+ input := & ec2.RevokeSecurityGroupIngressInput {
1403
+ SecurityGroupRuleIds : aws .StringSlice ([]string {sgrID }),
1404
+ }
1405
+
1406
+ result , err := ec2Svc .RevokeSecurityGroupIngress (input )
1407
+ if err != nil {
1408
+ return false , err
1409
+ }
1410
+ return * result .Return , nil
1411
+ }
1412
+
1413
+ func DeleteSecurityGroupEgressRule (e2eCtx * E2EContext , sgrID string ) (bool , error ) {
1414
+ ec2Svc := ec2 .New (e2eCtx .AWSSession )
1415
+
1416
+ input := & ec2.RevokeSecurityGroupEgressInput {
1417
+ SecurityGroupRuleIds : aws .StringSlice ([]string {sgrID }),
1418
+ }
1419
+
1420
+ result , err := ec2Svc .RevokeSecurityGroupEgress (input )
1421
+ if err != nil {
1422
+ return false , err
1423
+ }
1424
+ return * result .Return , nil
1425
+ }
1426
+
1427
+ func DeleteSecurityGroupRule (e2eCtx * E2EContext , sgrID string , rt string ) (bool , error ) {
1428
+ switch rt {
1429
+ case "ingress" :
1430
+ return DeleteSecurityGroupIngressRule (e2eCtx , sgrID )
1431
+ case "egress" :
1432
+ return DeleteSecurityGroupEgressRule (e2eCtx , sgrID )
1433
+ }
1434
+ return false , nil
1435
+ }
0 commit comments