Skip to content

Commit

Permalink
Add a VPC-reference field to RoutingTable struct (#254)
Browse files Browse the repository at this point in the history
Signed-off-by: ZIV NEVO <[email protected]>
  • Loading branch information
zivnevo authored May 30, 2024
1 parent f6b0391 commit 34fe0bd
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
7 changes: 4 additions & 3 deletions pkg/ibm/datamodel/data_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,16 @@ func (res *Instance) GetCRN() *string { return res.CRN }
// RoutingTable configuration object (not taggable)
type RoutingTable struct {
vpcv1.RoutingTable
Routes []RouteWrapper `json:"routes"`
Routes []RouteWrapper `json:"routes"`
VPC *vpcv1.VPCReference `json:"vpc"`
}

func NewRoutingTable(rt *vpcv1.RoutingTable, routes []vpcv1.Route) *RoutingTable {
func NewRoutingTable(rt *vpcv1.RoutingTable, routes []vpcv1.Route, vpcRef *vpcv1.VPCReference) *RoutingTable {
routesWrapper := make([]RouteWrapper, len(routes))
for i := range routes {
routesWrapper[i] = RouteWrapper(routes[i])
}
return &RoutingTable{RoutingTable: *rt, Routes: routesWrapper}
return &RoutingTable{RoutingTable: *rt, Routes: routesWrapper, VPC: vpcRef}
}

// RouteWrapper is an alias to vpcv1.Route that allows us to override
Expand Down
9 changes: 8 additions & 1 deletion pkg/ibm/datamodel/test/data/demo-with-instances-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3209,7 +3209,14 @@
"resource_type": "subnet"
}
],
"routes": []
"routes": [],
"vpc": {
"crn": "crn:1",
"href": "href:2",
"id": "id:3",
"name": "ky-testenv-vpc",
"resource_type": "vpc"
}
}
],
"load_balancers": [],
Expand Down
27 changes: 24 additions & 3 deletions pkg/ibm/datamodel/test/data/experiments_env.json
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,14 @@
"resource_type": "subnet"
}
],
"routes": []
"routes": [],
"vpc": {
"crn": "crn:1",
"href": "href:2",
"id": "id:3",
"name": "test-vpc1-ky",
"resource_type": "vpc"
}
},
{
"accept_routes_from": [],
Expand Down Expand Up @@ -2414,7 +2421,14 @@
"name": "us-south-1"
}
}
]
],
"vpc": {
"crn": "crn:1",
"href": "href:2",
"id": "id:3",
"name": "test-vpc1-ky",
"resource_type": "vpc"
}
},
{
"accept_routes_from": [
Expand Down Expand Up @@ -2446,7 +2460,14 @@
"resource_type": "subnet"
}
],
"routes": []
"routes": [],
"vpc": {
"crn": "crn:17",
"href": "href:18",
"id": "id:19",
"name": "test-vpc2-ky",
"resource_type": "vpc"
}
}
],
"load_balancers": [],
Expand Down
9 changes: 8 additions & 1 deletion pkg/ibm/datamodel/test/data/iks-on-goldeneye-vpc-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,14 @@
"resource_type": "subnet"
}
],
"routes": []
"routes": [],
"vpc": {
"crn": "crn:1",
"href": "href:2",
"id": "id:3",
"name": "ky-test-vpc",
"resource_type": "vpc"
}
}
],
"load_balancers": [
Expand Down
27 changes: 24 additions & 3 deletions pkg/ibm/datamodel/test/data/transit-gateways.json
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,14 @@
"route_transit_gateway_ingress": false,
"route_vpc_zone_ingress": false,
"subnets": [],
"routes": []
"routes": [],
"vpc": {
"crn": "crn:30",
"href": "href:31",
"id": "id:32",
"name": "ky-vpc2",
"resource_type": "vpc"
}
},
{
"accept_routes_from": [
Expand Down Expand Up @@ -1559,7 +1566,14 @@
"resource_type": "subnet"
}
],
"routes": []
"routes": [],
"vpc": {
"crn": "crn:17",
"href": "href:18",
"id": "id:19",
"name": "ky-vpc1",
"resource_type": "vpc"
}
},
{
"accept_routes_from": [
Expand Down Expand Up @@ -1591,7 +1605,14 @@
"resource_type": "subnet"
}
],
"routes": []
"routes": [],
"vpc": {
"crn": "crn:30",
"href": "href:31",
"id": "id:32",
"name": "ky-vpc2",
"resource_type": "vpc"
}
}
],
"load_balancers": [],
Expand Down
13 changes: 11 additions & 2 deletions pkg/ibm/vpc_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,17 @@ func getRoutingTables(vpcService *vpcv1.VpcV1, vpcList []*datamodel.VPC) ([]*dat
return collection.RoutingTables
}

vpcResourceType := vpcv1.VPCReferenceResourceTypeVPCConst
for i := range vpcList {
vpcID := *vpcList[i].ID
vpc := vpcList[i]
vpcID := *vpc.ID
vpcRef := &vpcv1.VPCReference{
CRN: vpc.CRN,
Href: vpc.Href,
ID: vpc.ID,
Name: vpc.Name,
ResourceType: &vpcResourceType,
}

routingTables, err := iteratePagedAPI(routingTableAPIFunc(vpcID), routingTableGetArray)
if err != nil {
Expand All @@ -282,7 +291,7 @@ func getRoutingTables(vpcService *vpcv1.VpcV1, vpcList []*datamodel.VPC) ([]*dat
if err != nil {
return nil, err
}
res = append(res, datamodel.NewRoutingTable(&routingTables[j], routes))
res = append(res, datamodel.NewRoutingTable(&routingTables[j], routes, vpcRef))
}
}

Expand Down

0 comments on commit 34fe0bd

Please sign in to comment.