Skip to content

Commit b39bdd6

Browse files
Operator v1 for netris-controller 3.x (#41)
* fix: l4-watcher: change lb generation and ip assignment logic * fix: lb-watcher: stop using iprole annotation * fix: bgp: set status N/A when trasport type is vnet * refactor: migrate to netris v3.0.0 v2 api * fix: update netriswebapi package * fix: update netriswebapi package, fix fields * fix: bgp: delete nfvid field, add additional logs * refactor: change bgp according to the new version * feat: bgp: add debug info about which field is changed * fix: calicowatcher: set hardware value to 'auto' * fix: bgp: compare route maps in right way * fix: bgp: delete logic * refactor: bgp: use unireconciler in compare function * refactor: bgp: use unireconciler in compare function * fix: bgp: compare ports * fix: bgp: ahrdware auto functionality * fix: bgp: prefix limit field type * fix: zz generated deepcopy * fix: calicowatcher: fix vnet searching logic * fix: bgp: vlan field comparison * refactor: vnet: remove unused logs * fix: bgp, calico: make hardware not required field * Preparation for v1 release Co-authored-by: Artashes Balabekyan <[email protected]>
1 parent 631db98 commit b39bdd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+742
-805
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ bin
1212

1313
# Output of the go coverage tool, specifically when used with LiteIDE
1414
*.out
15+
k8s
1516

1617
# Kubernetes Generated files - skip generated files, except for vendored files
1718

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ You can also use [Helm charts](./deploy/charts/netris-operator) to deploy Netris
2828
## Documentation
2929
Netris Operator managing resources samples are available in the `samples/` [folder](./samples/).
3030

31+
## Compatibility with Netris-Controller
32+
| Operator version | Controller version |
33+
| -----------------| -------------------|
34+
| `v0.X` | `v2.9.X` |
35+
| `v1.X` | `v3.X` |
36+
3137
## Features
3238
* Managing Netris Controller via CRD
3339
* Automatically creating `L4LB` resource for `type: load-balancer` services

api/v1alpha1/bgp_types.go

+16-23
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ type BGPSpec struct {
4646
// Important: Run "make" to regenerate code after modifying this file
4747

4848
Site string `json:"site"`
49-
Softgate string `json:"softgate,omitempty"`
5049
NeighborAS int `json:"neighborAs"`
5150
Transport BGPTransport `json:"transport"`
51+
Hardware string `json:"hardware,omitempty"`
5252

5353
// +kubebuilder:validation:Pattern=`(^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/([0-9]|[12]\d|3[0-2]))?$)|(^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?(\/([1-9]|[1-5][0-9]|6[0-4]))?$)`
5454
LocalIP string `json:"localIP"`
@@ -58,28 +58,21 @@ type BGPSpec struct {
5858
Description string `json:"description,omitempty"`
5959

6060
// +kubebuilder:validation:Enum=enabled;disabled
61-
State string `json:"state,omitempty"`
62-
TerminateOnSwitch BGPTerminateOnSwitch `json:"terminateOnSwitch,omitempty"`
63-
Multihop BGPMultihop `json:"multihop,omitempty"`
64-
BGPPassword string `json:"bgpPassword,omitempty"`
65-
AllowAsIn int `json:"allowAsIn,omitempty"`
66-
DefaultOriginate bool `json:"defaultOriginate,omitempty"`
67-
PrefixInboundMax int `json:"prefixInboundMax,omitempty"`
68-
InboundRouteMap string `json:"inboundRouteMap,omitempty"`
69-
OutboundRouteMap string `json:"outboundRouteMap,omitempty"`
70-
LocalPreference int `json:"localPreference,omitempty"`
71-
Weight int `json:"weight,omitempty"`
72-
PrependInbound int `json:"prependInbound,omitempty"`
73-
PrependOutbound int `json:"prependOutbound,omitempty"`
74-
PrefixListInbound []string `json:"prefixListInbound,omitempty"`
75-
PrefixListOutbound []string `json:"prefixListOutbound,omitempty"`
76-
SendBGPCommunity []string `json:"sendBGPCommunity,omitempty"`
77-
}
78-
79-
// BGPTerminateOnSwitch .
80-
type BGPTerminateOnSwitch struct {
81-
Enabled bool `json:"enabled"`
82-
SwitchName string `json:"switchName,omitempty"`
61+
State string `json:"state,omitempty"`
62+
Multihop BGPMultihop `json:"multihop,omitempty"`
63+
BGPPassword string `json:"bgpPassword,omitempty"`
64+
AllowAsIn int `json:"allowAsIn,omitempty"`
65+
DefaultOriginate bool `json:"defaultOriginate,omitempty"`
66+
PrefixInboundMax int `json:"prefixInboundMax,omitempty"`
67+
InboundRouteMap string `json:"inboundRouteMap,omitempty"`
68+
OutboundRouteMap string `json:"outboundRouteMap,omitempty"`
69+
LocalPreference int `json:"localPreference,omitempty"`
70+
Weight int `json:"weight,omitempty"`
71+
PrependInbound int `json:"prependInbound,omitempty"`
72+
PrependOutbound int `json:"prependOutbound,omitempty"`
73+
PrefixListInbound []string `json:"prefixListInbound,omitempty"`
74+
PrefixListOutbound []string `json:"prefixListOutbound,omitempty"`
75+
SendBGPCommunity []string `json:"sendBGPCommunity,omitempty"`
8376
}
8477

8578
// BGPMultihop .

api/v1alpha1/bgpmeta_types.go

+30-36
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,36 @@ type BGPMetaSpec struct {
3333
ID int `json:"id"`
3434
BGPName string `json:"bgpName"`
3535

36-
AllowasIn int `json:"allowas_in"`
37-
BgpPassword string `json:"bgp_password"`
38-
Community string `json:"community"`
39-
Description string `json:"description"`
40-
InboundRouteMap int `json:"inboundRouteMap"`
41-
Internal string `json:"internal"`
42-
IPVersion string `json:"ip_version"`
43-
LocalIP string `json:"local_ip"`
44-
LocalPreference int `json:"local_preference"`
45-
Multihop int `json:"multihop"`
46-
Name string `json:"name"`
47-
NeighborAddress string `json:"neighbor_address"`
48-
NeighborAs int `json:"neighbor_as"`
49-
NfvID int `json:"nfv_id"`
50-
NfvPortID int `json:"nfv_port_id"`
51-
Originate string `json:"originate"`
52-
OutboundRouteMap int `json:"outboundRouteMap"`
53-
PrefixLength int `json:"prefix_length"`
54-
PrefixLimit int `json:"prefix_limit"`
55-
PrefixListInbound string `json:"prefix_list_inbound"`
56-
PrefixListOutbound string `json:"prefix_list_outbound"`
57-
PrependInbound int `json:"prepend_inbound"`
58-
PrependOutbound int `json:"prepend_outbound"`
59-
RcircuitID int `json:"rcircuit_id"`
60-
RemoteIP string `json:"remote_ip"`
61-
SiteID int `json:"site_id"`
62-
Status string `json:"status"`
63-
SwitchID int `json:"switch_id"`
64-
SwitchName string `json:"switch_name"`
65-
SwitchPortID int `json:"switch_port_id"`
66-
TermSwitchID int `json:"term_switch_id"`
67-
TermSwitchName string `json:"term_switch_name"`
68-
TerminateOnSwitch string `json:"terminate_on_switch"`
69-
UpdateSource string `json:"update_source"`
70-
Vlan int `json:"vlan"`
71-
Weight int `json:"weight"`
36+
AllowasIn int `json:"allowas_in"`
37+
HWID int `json:"hwid"`
38+
Port string `json:"port"`
39+
VnetID int `json:"vnet"`
40+
Site string `json:"site"`
41+
BgpPassword string `json:"bgp_password"`
42+
Community string `json:"community"`
43+
Description string `json:"description"`
44+
InboundRouteMap int `json:"inboundRouteMap"`
45+
Internal string `json:"internal"`
46+
IPVersion string `json:"ip_version"`
47+
LocalIP string `json:"local_ip"`
48+
LocalPreference int `json:"local_preference"`
49+
Multihop int `json:"multihop"`
50+
Name string `json:"name"`
51+
NeighborAddress *string `json:"neighbor_address,omitempty"`
52+
NeighborAs int `json:"neighbor_as"`
53+
Originate string `json:"originate"`
54+
OutboundRouteMap int `json:"outboundRouteMap"`
55+
PrefixLength int `json:"prefix_length"`
56+
PrefixLimit string `json:"prefix_limit"`
57+
PrefixListInbound string `json:"prefix_list_inbound"`
58+
PrefixListOutbound string `json:"prefix_list_outbound"`
59+
PrependInbound int `json:"prepend_inbound"`
60+
PrependOutbound int `json:"prepend_outbound"`
61+
RemoteIP string `json:"remote_ip"`
62+
Status string `json:"status"`
63+
UpdateSource string `json:"update_source"`
64+
Vlan int `json:"vlan"`
65+
Weight int `json:"weight"`
7266
}
7367

7468
// BGPMetaStatus defines the observed state of BGPMeta

api/v1alpha1/vnetmeta_types.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ type VNetMetaSpec struct {
3333
Members []VNetMetaMember `json:"members"`
3434
Name string `json:"name"`
3535
VnetName string `json:"vnetName"`
36-
OwnerID int `json:"ownerid"`
3736
Owner string `json:"owner"`
3837
Provisioning int `json:"provisioning"`
3938
Sites []VNetMetaSite `json:"sites"`
4039
State string `json:"state"`
41-
Tenants []int `json:"tenants"`
40+
Tenants []string `json:"tenants"`
4241
VaMode bool `json:"vaMode"`
4342
VaNativeVLAN int `json:"vaNativeVlan"`
4443
VaVLANs string `json:"vaVlans"`

api/v1alpha1/zz_generated.deepcopy.go

+7-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

calicowatcher/main.go

+16-20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import (
3232
"github.com/netrisai/netris-operator/calicowatcher/calico"
3333
"github.com/netrisai/netris-operator/configloader"
3434
"github.com/netrisai/netris-operator/netrisstorage"
35-
api "github.com/netrisai/netrisapi"
35+
"github.com/netrisai/netriswebapi/v1/types/site"
36+
"github.com/netrisai/netriswebapi/v2/types/vnet"
3637
"github.com/r3labs/diff/v2"
3738
"go.uber.org/zap/zapcore"
3839
v1 "k8s.io/api/core/v1"
@@ -76,7 +77,7 @@ type data struct {
7677
switchName string
7778

7879
nodes *v1.NodeList
79-
site *api.APISite
80+
site *site.Site
8081
vnetGW string
8182
vnetGWIP string
8283
blockSize int
@@ -425,10 +426,7 @@ func (w *Watcher) generateBGPs() error {
425426
Spec: k8sv1alpha1.BGPSpec{
426427
Site: w.data.site.Name,
427428
NeighborAS: asn,
428-
TerminateOnSwitch: k8sv1alpha1.BGPTerminateOnSwitch{
429-
Enabled: true,
430-
SwitchName: w.data.switchName,
431-
},
429+
Hardware: w.data.switchName,
432430
Transport: v1alpha1.BGPTransport{
433431
Type: "vnet",
434432
Name: w.data.vnetName,
@@ -661,16 +659,15 @@ func (w *Watcher) fillNodesASNs() error {
661659
func (w *Watcher) nodesProcessing() error {
662660
var (
663661
siteName string
664-
site *api.APISite
662+
site *site.Site
665663
vnetName string
666664
vnetGW string
667-
switchName string
665+
switchName string = ""
668666
vnetGWIP string
669667
)
670668

671-
siteID := 0
672669
subnet := ""
673-
vnet := &api.APIVNet{}
670+
vnet := &vnet.VNet{}
674671

675672
nodesMap := make(map[string]*nodeIP)
676673

@@ -713,7 +710,6 @@ func (w *Watcher) nodesProcessing() error {
713710
var ok bool
714711
if site, ok = w.NStorage.SitesStorage.FindByID(id); ok {
715712
siteName = site.Name
716-
siteID = site.ID
717713
}
718714
subnet = gateway
719715
if vn, ok := w.NStorage.VNetStorage.FindByGateway(gateway); ok {
@@ -731,20 +727,20 @@ func (w *Watcher) nodesProcessing() error {
731727
if vnet == nil {
732728
return fmt.Errorf("Couldn't find vnet")
733729
}
734-
735-
if spine := w.NStorage.HWsStorage.FindSpineBySite(siteID); spine != nil {
736-
switchName = spine.SwitchName
737-
} else {
738-
return fmt.Errorf("Couldn't find spine swtich for site %s", siteName)
730+
if vnet.ID == 0 {
731+
return fmt.Errorf("Couldn't find vnet")
739732
}
740733

741734
vnetName = vnet.Name
742735
for _, gw := range vnet.Gateways {
743-
gateway := fmt.Sprintf("%s/%d", gw.Gateway, gw.GwLength)
744-
_, gwNet, _ := net.ParseCIDR(gateway)
736+
gateway := strings.Split(gw.Prefix, "/")[0]
737+
_, gwNet, err := net.ParseCIDR(gw.Prefix)
738+
if err != nil {
739+
return fmt.Errorf("invalid vnet gateway %s", gw.Prefix)
740+
}
745741
if gwNet.String() == subnet {
746-
vnetGW = gateway
747-
vnetGWIP = gw.Gateway
742+
vnetGW = gw.Prefix
743+
vnetGWIP = gateway
748744
}
749745
}
750746
w.data.nodesMap = nodesMap

calicowatcher/utils.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,29 @@ package calicowatcher
1919
import (
2020
"fmt"
2121
"net"
22-
"strconv"
2322

24-
api "github.com/netrisai/netrisapi"
23+
"github.com/netrisai/netriswebapi/v2/types/ipam"
2524
)
2625

2726
func (w *Watcher) findSiteByIP(ip string) (int, string, error) {
2827
siteID := 0
2928
subnets := w.NStorage.SubnetsStorage.GetAll()
3029

31-
subnetChilds := []api.APISubnetChild{}
30+
subnetChilds := []*ipam.IPAM{}
3231
for _, subnet := range subnets {
3332
subnetChilds = append(subnetChilds, subnet.Children...)
3433
}
3534

3635
for _, subnet := range subnetChilds {
3736
ipAddr := net.ParseIP(ip)
38-
_, ipNet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", subnet.Prefix, subnet.Length))
37+
_, ipNet, err := net.ParseCIDR(subnet.Prefix)
3938
if err != nil {
4039
return siteID, "", err
4140
}
4241
if ipNet.Contains(ipAddr) {
43-
sID, _ := strconv.Atoi(subnet.SiteID)
44-
if err != nil {
45-
return siteID, "", err
42+
if len(subnet.Sites) > 0 {
43+
return subnet.Sites[0].ID, ipNet.String(), nil
4644
}
47-
return sID, ipNet.String(), nil
4845
}
4946
}
5047

0 commit comments

Comments
 (0)