Skip to content

Commit 9e60690

Browse files
authored
Add new network properties to machineNetwork (#643)
1 parent 5b5af7b commit 9e60690

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

cmd/metal-api/internal/metal/machine.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ type MachineNetwork struct {
389389
Nat bool `rethinkdb:"nat" json:"nat"`
390390
Underlay bool `rethinkdb:"underlay" json:"underlay"`
391391
Shared bool `rethinkdb:"shared" json:"shared"`
392+
// The following 3 properties are persisted only for new machines, existing machine allocations will be updated
393+
// This required to enable forward compatibility to apiv2
394+
// TODO carry over these properties to metal-apiserver as well
395+
ProjectID string `rethinkdb:"projectid" json:"projectid"`
396+
NetworkTypeV2 NetworkTypeV2 `rethinkdb:"networktype" json:"networktype"`
397+
NATTypeV2 NATType `rethinkdb:"nattype" json:"nattype"`
392398
}
393399

394400
// NetworkType represents the type of a network

cmd/metal-api/internal/service/machine-service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,9 @@ func makeMachineNetwork(ctx context.Context, ds *datastore.RethinkStore, ipamer
17141714
Underlay: n.networkType.Underlay,
17151715
Nat: n.network.Nat,
17161716
Vrf: n.network.Vrf,
1717+
ProjectID: n.network.ProjectID,
1718+
NetworkTypeV2: pointer.SafeDeref(n.network.NetworkType),
1719+
NATTypeV2: pointer.SafeDeref(n.network.NATType),
17171720
}
17181721

17191722
return &machineNetwork, nil

cmd/metal-api/internal/service/v1/machine.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ type MachineNetwork struct {
8282
//
8383
// Deprecated: can be removed once old machine images without NetworkType are not supported anymore
8484
Underlay bool `json:"underlay" description:"if set to true, this network can be used for underlay communication"`
85+
86+
// The following type are used to get forward compatibility with apiv2
87+
// ProjectID is required to detect the new networktype
88+
ProjectID string `json:"projectid" description:"project of this network, empty string if not project scoped"`
89+
// NetworkTypeV2 is the apiv2 networktype
90+
NetworkTypeV2 metal.NetworkTypeV2 `json:"networktypev2"`
91+
// NatTypeV2 is the apiv2 nattype
92+
NATTypeV2 metal.NATType `json:"nattypev2"`
8593
}
8694

8795
type MachineHardwareBase struct {
@@ -555,6 +563,10 @@ func NewMachineResponse(m *metal.Machine, s *metal.Size, p *metal.Partition, i *
555563
// FIXME: Both following fields are deprecated and for backward compatibility reasons only
556564
Private: nt.Private,
557565
Underlay: nt.Underlay,
566+
567+
ProjectID: nw.ProjectID,
568+
NetworkTypeV2: nw.NetworkTypeV2,
569+
NATTypeV2: nw.NATTypeV2,
558570
}
559571
networks = append(networks, network)
560572
}

cmd/metal-api/internal/service/v1/network.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type NetworkImmutable struct {
2525
VrfShared *bool `json:"vrfshared" description:"if set to true, given vrf can be used by multiple networks, which is sometimes useful for network partitioning (default: false)" optional:"true"`
2626
ParentNetworkID *string `json:"parentnetworkid" description:"the id of the parent network" optional:"true"`
2727
AdditionalAnnouncableCIDRs []string `json:"additionalAnnouncableCIDRs,omitempty" description:"list of cidrs which are added to the route maps per tenant private network, these are typically pod- and service cidrs, can only be set for private super networks"`
28+
NetworkType *metal.NetworkTypeV2 `json:"networktype" description:"apiv2 network type"`
29+
NATType *metal.NATType `json:"nattype" description:"apiv2 nat type"`
2830
}
2931

3032
type NetworkConsumption struct {
@@ -133,6 +135,8 @@ func NewNetworkResponse(network *metal.Network, consumption *NetworkConsumption)
133135
Vrf: &network.Vrf,
134136
ParentNetworkID: parentNetworkID,
135137
AdditionalAnnouncableCIDRs: network.AdditionalAnnouncableCIDRs,
138+
NetworkType: network.NetworkType,
139+
NATType: network.NATType,
136140
},
137141
Consumption: *consumption,
138142
Timestamps: Timestamps{

spec/metal-api.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,9 @@
32583258
"description": "if set to true, packets leaving this network get masqueraded behind interface ip",
32593259
"type": "boolean"
32603260
},
3261+
"nattypev2": {
3262+
"type": "string"
3263+
},
32613264
"networkid": {
32623265
"description": "the networkID of the allocated machine in this vrf",
32633266
"type": "string"
@@ -3266,6 +3269,9 @@
32663269
"description": "the network type, types can be looked up in the network package of metal-lib",
32673270
"type": "string"
32683271
},
3272+
"networktypev2": {
3273+
"type": "string"
3274+
},
32693275
"prefixes": {
32703276
"description": "the prefixes of this network",
32713277
"items": {
@@ -3277,6 +3283,10 @@
32773283
"description": "indicates whether this network is the private network of this machine",
32783284
"type": "boolean"
32793285
},
3286+
"projectid": {
3287+
"description": "project of this network, empty string if not project scoped",
3288+
"type": "string"
3289+
},
32803290
"underlay": {
32813291
"description": "if set to true, this network can be used for underlay communication",
32823292
"type": "boolean"
@@ -3292,10 +3302,13 @@
32923302
"destinationprefixes",
32933303
"ips",
32943304
"nat",
3305+
"nattypev2",
32953306
"networkid",
32963307
"networktype",
3308+
"networktypev2",
32973309
"prefixes",
32983310
"private",
3311+
"projectid",
32993312
"underlay",
33003313
"vrf"
33013314
]
@@ -3831,6 +3844,14 @@
38313844
"description": "if set to true, packets leaving this ipv4 network get masqueraded behind interface ip",
38323845
"type": "boolean"
38333846
},
3847+
"nattype": {
3848+
"description": "apiv2 nat type",
3849+
"type": "string"
3850+
},
3851+
"networktype": {
3852+
"description": "apiv2 network type",
3853+
"type": "string"
3854+
},
38343855
"parentnetworkid": {
38353856
"description": "the id of the parent network",
38363857
"type": "string"
@@ -3876,6 +3897,8 @@
38763897
"destinationprefixes",
38773898
"id",
38783899
"nat",
3900+
"nattype",
3901+
"networktype",
38793902
"prefixes",
38803903
"privatesuper",
38813904
"underlay"
@@ -3966,6 +3989,14 @@
39663989
"description": "if set to true, packets leaving this ipv4 network get masqueraded behind interface ip",
39673990
"type": "boolean"
39683991
},
3992+
"nattype": {
3993+
"description": "apiv2 nat type",
3994+
"type": "string"
3995+
},
3996+
"networktype": {
3997+
"description": "apiv2 network type",
3998+
"type": "string"
3999+
},
39694000
"parentnetworkid": {
39704001
"description": "the id of the parent network",
39714002
"type": "string"
@@ -3998,6 +4029,8 @@
39984029
"required": [
39994030
"destinationprefixes",
40004031
"nat",
4032+
"nattype",
4033+
"networktype",
40014034
"prefixes",
40024035
"privatesuper",
40034036
"underlay"
@@ -4065,6 +4098,14 @@
40654098
"description": "if set to true, packets leaving this ipv4 network get masqueraded behind interface ip",
40664099
"type": "boolean"
40674100
},
4101+
"nattype": {
4102+
"description": "apiv2 nat type",
4103+
"type": "string"
4104+
},
4105+
"networktype": {
4106+
"description": "apiv2 network type",
4107+
"type": "string"
4108+
},
40684109
"parentnetworkid": {
40694110
"description": "the id of the parent network",
40704111
"type": "string"
@@ -4115,6 +4156,8 @@
41154156
"destinationprefixes",
41164157
"id",
41174158
"nat",
4159+
"nattype",
4160+
"networktype",
41184161
"prefixes",
41194162
"privatesuper",
41204163
"underlay",

0 commit comments

Comments
 (0)