-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dualstack Network Support #549
base: master
Are you sure you want to change the base?
Changes from 57 commits
5ea7ea6
22d916e
e8571c9
59c7511
9f52dfd
89a0857
aae9274
1b09d5d
87a2a98
23e4cbd
a175469
c519d3b
a1575ef
f553164
fa47c76
6430ea1
5f3287e
1822069
72ac513
82cc73e
d2cb195
d408762
8f06d84
10f49c7
88835d4
02a518f
44c8825
fbe6a32
7568f8e
9db0e6e
84c63ad
43dc320
5719737
576df4a
2e72212
f2da96e
bd57dcb
343ef3b
f313f41
4bb6603
fbf1970
03c2436
e726090
c9c4b7e
5e73c10
3b7bb28
a1a3428
391d997
3fd8505
3cc62cf
94bc6e8
ce53bcd
a374b2c
6b2c3a8
9d1c340
26a9b5e
d3610e8
9ee694a
d964c1b
04a84e5
e38db83
60c9d8a
0d64c98
ff87efa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package migrations | ||
|
||
import ( | ||
"net/netip" | ||
|
||
r "gopkg.in/rethinkdb/rethinkdb-go.v6" | ||
|
||
"github.com/metal-stack/metal-api/cmd/metal-api/internal/datastore" | ||
"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" | ||
) | ||
|
||
func init() { | ||
type tmpPartition struct { | ||
PrivateNetworkPrefixLength uint8 `rethinkdb:"privatenetworkprefixlength"` | ||
} | ||
datastore.MustRegisterMigration(datastore.Migration{ | ||
Name: "migrate partition.childprefixlength to tenant super network", | ||
Version: 8, | ||
Up: func(db *r.Term, session r.QueryExecutor, rs *datastore.RethinkStore) error { | ||
nws, err := rs.ListNetworks() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, old := range nws { | ||
cursor, err := db.Table("partition").Get(old.PartitionID).Run(session) | ||
if err != nil { | ||
return err | ||
} | ||
if cursor.IsNil() { | ||
_ = cursor.Close() | ||
continue | ||
} | ||
var partition tmpPartition | ||
err = cursor.One(&partition) | ||
if err != nil { | ||
_ = cursor.Close() | ||
return err | ||
} | ||
err = cursor.Close() | ||
if err != nil { | ||
return err | ||
} | ||
new := old | ||
|
||
var ( | ||
af metal.AddressFamily | ||
defaultChildPrefixLength = metal.ChildPrefixLength{} | ||
) | ||
// FIXME check all prefixes | ||
parsed, err := netip.ParsePrefix(new.Prefixes[0].String()) | ||
if err != nil { | ||
return err | ||
} | ||
if parsed.Addr().Is4() { | ||
af = metal.IPv4AddressFamily | ||
defaultChildPrefixLength[af] = 22 | ||
} | ||
if parsed.Addr().Is6() { | ||
af = metal.IPv6AddressFamily | ||
defaultChildPrefixLength[af] = 64 | ||
} | ||
|
||
if new.AddressFamilies == nil { | ||
new.AddressFamilies = metal.AddressFamilies{} | ||
} | ||
new.AddressFamilies = metal.AddressFamilies{af} | ||
Comment on lines
+55
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only required for private super networks and for those it's probably enough just to take the value from the partition for IPv4 and 64 for IPv6. |
||
|
||
if new.PrivateSuper { | ||
if new.DefaultChildPrefixLength == nil { | ||
new.DefaultChildPrefixLength = make(map[metal.AddressFamily]uint8) | ||
} | ||
if partition.PrivateNetworkPrefixLength > 0 { | ||
new.DefaultChildPrefixLength[af] = partition.PrivateNetworkPrefixLength | ||
} else { | ||
new.DefaultChildPrefixLength = defaultChildPrefixLength | ||
} | ||
|
||
} | ||
err = rs.UpdateNetwork(&old, &new) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
_, err = db.Table("partition").Replace(r.Row.Without("privatenetworkprefixlength")).RunWrite(session) | ||
return err | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ type NetworkSearchQuery struct { | |||||
Vrf *int64 `json:"vrf" optional:"true"` | ||||||
ParentNetworkID *string `json:"parentnetworkid" optional:"true"` | ||||||
Labels map[string]string `json:"labels" optional:"true"` | ||||||
AddressFamily *string `json:"addressfamily" optional:"true" enum:"IPv4|IPv6"` | ||||||
} | ||||||
|
||||||
func (p *NetworkSearchQuery) Validate() error { | ||||||
|
@@ -154,6 +155,25 @@ func (p *NetworkSearchQuery) generateTerm(rs *RethinkStore) (*r.Term, error) { | |||||
}) | ||||||
} | ||||||
|
||||||
if p.AddressFamily != nil { | ||||||
separator := "." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
af := metal.ToAddressFamily(*p.AddressFamily) | ||||||
switch af { | ||||||
case metal.IPv4AddressFamily: | ||||||
separator = "\\." | ||||||
case metal.IPv6AddressFamily: | ||||||
separator = ":" | ||||||
} | ||||||
|
||||||
fmt.Printf("Separator:%s\n", separator) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
q = q.Filter(func(row r.Term) r.Term { | ||||||
return row.Field("prefixes").Contains(func(p r.Term) r.Term { | ||||||
return p.Field("ip").Match(separator) | ||||||
}) | ||||||
}) | ||||||
} | ||||||
|
||||||
return &q, nil | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.