Skip to content

Commit

Permalink
Operator v1 for netris-controller 3.x (#41)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
pogossian and artashesbalabekyan authored Nov 1, 2021
1 parent 631db98 commit b39bdd6
Show file tree
Hide file tree
Showing 43 changed files with 742 additions and 805 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bin

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
k8s

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

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ You can also use [Helm charts](./deploy/charts/netris-operator) to deploy Netris
## Documentation
Netris Operator managing resources samples are available in the `samples/` [folder](./samples/).

## Compatibility with Netris-Controller
| Operator version | Controller version |
| -----------------| -------------------|
| `v0.X` | `v2.9.X` |
| `v1.X` | `v3.X` |

## Features
* Managing Netris Controller via CRD
* Automatically creating `L4LB` resource for `type: load-balancer` services
Expand Down
39 changes: 16 additions & 23 deletions api/v1alpha1/bgp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type BGPSpec struct {
// Important: Run "make" to regenerate code after modifying this file

Site string `json:"site"`
Softgate string `json:"softgate,omitempty"`
NeighborAS int `json:"neighborAs"`
Transport BGPTransport `json:"transport"`
Hardware string `json:"hardware,omitempty"`

// +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]))?$)`
LocalIP string `json:"localIP"`
Expand All @@ -58,28 +58,21 @@ type BGPSpec struct {
Description string `json:"description,omitempty"`

// +kubebuilder:validation:Enum=enabled;disabled
State string `json:"state,omitempty"`
TerminateOnSwitch BGPTerminateOnSwitch `json:"terminateOnSwitch,omitempty"`
Multihop BGPMultihop `json:"multihop,omitempty"`
BGPPassword string `json:"bgpPassword,omitempty"`
AllowAsIn int `json:"allowAsIn,omitempty"`
DefaultOriginate bool `json:"defaultOriginate,omitempty"`
PrefixInboundMax int `json:"prefixInboundMax,omitempty"`
InboundRouteMap string `json:"inboundRouteMap,omitempty"`
OutboundRouteMap string `json:"outboundRouteMap,omitempty"`
LocalPreference int `json:"localPreference,omitempty"`
Weight int `json:"weight,omitempty"`
PrependInbound int `json:"prependInbound,omitempty"`
PrependOutbound int `json:"prependOutbound,omitempty"`
PrefixListInbound []string `json:"prefixListInbound,omitempty"`
PrefixListOutbound []string `json:"prefixListOutbound,omitempty"`
SendBGPCommunity []string `json:"sendBGPCommunity,omitempty"`
}

// BGPTerminateOnSwitch .
type BGPTerminateOnSwitch struct {
Enabled bool `json:"enabled"`
SwitchName string `json:"switchName,omitempty"`
State string `json:"state,omitempty"`
Multihop BGPMultihop `json:"multihop,omitempty"`
BGPPassword string `json:"bgpPassword,omitempty"`
AllowAsIn int `json:"allowAsIn,omitempty"`
DefaultOriginate bool `json:"defaultOriginate,omitempty"`
PrefixInboundMax int `json:"prefixInboundMax,omitempty"`
InboundRouteMap string `json:"inboundRouteMap,omitempty"`
OutboundRouteMap string `json:"outboundRouteMap,omitempty"`
LocalPreference int `json:"localPreference,omitempty"`
Weight int `json:"weight,omitempty"`
PrependInbound int `json:"prependInbound,omitempty"`
PrependOutbound int `json:"prependOutbound,omitempty"`
PrefixListInbound []string `json:"prefixListInbound,omitempty"`
PrefixListOutbound []string `json:"prefixListOutbound,omitempty"`
SendBGPCommunity []string `json:"sendBGPCommunity,omitempty"`
}

// BGPMultihop .
Expand Down
66 changes: 30 additions & 36 deletions api/v1alpha1/bgpmeta_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,36 @@ type BGPMetaSpec struct {
ID int `json:"id"`
BGPName string `json:"bgpName"`

AllowasIn int `json:"allowas_in"`
BgpPassword string `json:"bgp_password"`
Community string `json:"community"`
Description string `json:"description"`
InboundRouteMap int `json:"inboundRouteMap"`
Internal string `json:"internal"`
IPVersion string `json:"ip_version"`
LocalIP string `json:"local_ip"`
LocalPreference int `json:"local_preference"`
Multihop int `json:"multihop"`
Name string `json:"name"`
NeighborAddress string `json:"neighbor_address"`
NeighborAs int `json:"neighbor_as"`
NfvID int `json:"nfv_id"`
NfvPortID int `json:"nfv_port_id"`
Originate string `json:"originate"`
OutboundRouteMap int `json:"outboundRouteMap"`
PrefixLength int `json:"prefix_length"`
PrefixLimit int `json:"prefix_limit"`
PrefixListInbound string `json:"prefix_list_inbound"`
PrefixListOutbound string `json:"prefix_list_outbound"`
PrependInbound int `json:"prepend_inbound"`
PrependOutbound int `json:"prepend_outbound"`
RcircuitID int `json:"rcircuit_id"`
RemoteIP string `json:"remote_ip"`
SiteID int `json:"site_id"`
Status string `json:"status"`
SwitchID int `json:"switch_id"`
SwitchName string `json:"switch_name"`
SwitchPortID int `json:"switch_port_id"`
TermSwitchID int `json:"term_switch_id"`
TermSwitchName string `json:"term_switch_name"`
TerminateOnSwitch string `json:"terminate_on_switch"`
UpdateSource string `json:"update_source"`
Vlan int `json:"vlan"`
Weight int `json:"weight"`
AllowasIn int `json:"allowas_in"`
HWID int `json:"hwid"`
Port string `json:"port"`
VnetID int `json:"vnet"`
Site string `json:"site"`
BgpPassword string `json:"bgp_password"`
Community string `json:"community"`
Description string `json:"description"`
InboundRouteMap int `json:"inboundRouteMap"`
Internal string `json:"internal"`
IPVersion string `json:"ip_version"`
LocalIP string `json:"local_ip"`
LocalPreference int `json:"local_preference"`
Multihop int `json:"multihop"`
Name string `json:"name"`
NeighborAddress *string `json:"neighbor_address,omitempty"`
NeighborAs int `json:"neighbor_as"`
Originate string `json:"originate"`
OutboundRouteMap int `json:"outboundRouteMap"`
PrefixLength int `json:"prefix_length"`
PrefixLimit string `json:"prefix_limit"`
PrefixListInbound string `json:"prefix_list_inbound"`
PrefixListOutbound string `json:"prefix_list_outbound"`
PrependInbound int `json:"prepend_inbound"`
PrependOutbound int `json:"prepend_outbound"`
RemoteIP string `json:"remote_ip"`
Status string `json:"status"`
UpdateSource string `json:"update_source"`
Vlan int `json:"vlan"`
Weight int `json:"weight"`
}

// BGPMetaStatus defines the observed state of BGPMeta
Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/vnetmeta_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ type VNetMetaSpec struct {
Members []VNetMetaMember `json:"members"`
Name string `json:"name"`
VnetName string `json:"vnetName"`
OwnerID int `json:"ownerid"`
Owner string `json:"owner"`
Provisioning int `json:"provisioning"`
Sites []VNetMetaSite `json:"sites"`
State string `json:"state"`
Tenants []int `json:"tenants"`
Tenants []string `json:"tenants"`
VaMode bool `json:"vaMode"`
VaNativeVLAN int `json:"vaNativeVlan"`
VaVLANs string `json:"vaVlans"`
Expand Down
25 changes: 7 additions & 18 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 16 additions & 20 deletions calicowatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import (
"github.com/netrisai/netris-operator/calicowatcher/calico"
"github.com/netrisai/netris-operator/configloader"
"github.com/netrisai/netris-operator/netrisstorage"
api "github.com/netrisai/netrisapi"
"github.com/netrisai/netriswebapi/v1/types/site"
"github.com/netrisai/netriswebapi/v2/types/vnet"
"github.com/r3labs/diff/v2"
"go.uber.org/zap/zapcore"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -76,7 +77,7 @@ type data struct {
switchName string

nodes *v1.NodeList
site *api.APISite
site *site.Site
vnetGW string
vnetGWIP string
blockSize int
Expand Down Expand Up @@ -425,10 +426,7 @@ func (w *Watcher) generateBGPs() error {
Spec: k8sv1alpha1.BGPSpec{
Site: w.data.site.Name,
NeighborAS: asn,
TerminateOnSwitch: k8sv1alpha1.BGPTerminateOnSwitch{
Enabled: true,
SwitchName: w.data.switchName,
},
Hardware: w.data.switchName,
Transport: v1alpha1.BGPTransport{
Type: "vnet",
Name: w.data.vnetName,
Expand Down Expand Up @@ -661,16 +659,15 @@ func (w *Watcher) fillNodesASNs() error {
func (w *Watcher) nodesProcessing() error {
var (
siteName string
site *api.APISite
site *site.Site
vnetName string
vnetGW string
switchName string
switchName string = ""
vnetGWIP string
)

siteID := 0
subnet := ""
vnet := &api.APIVNet{}
vnet := &vnet.VNet{}

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

Expand Down Expand Up @@ -713,7 +710,6 @@ func (w *Watcher) nodesProcessing() error {
var ok bool
if site, ok = w.NStorage.SitesStorage.FindByID(id); ok {
siteName = site.Name
siteID = site.ID
}
subnet = gateway
if vn, ok := w.NStorage.VNetStorage.FindByGateway(gateway); ok {
Expand All @@ -731,20 +727,20 @@ func (w *Watcher) nodesProcessing() error {
if vnet == nil {
return fmt.Errorf("Couldn't find vnet")
}

if spine := w.NStorage.HWsStorage.FindSpineBySite(siteID); spine != nil {
switchName = spine.SwitchName
} else {
return fmt.Errorf("Couldn't find spine swtich for site %s", siteName)
if vnet.ID == 0 {
return fmt.Errorf("Couldn't find vnet")
}

vnetName = vnet.Name
for _, gw := range vnet.Gateways {
gateway := fmt.Sprintf("%s/%d", gw.Gateway, gw.GwLength)
_, gwNet, _ := net.ParseCIDR(gateway)
gateway := strings.Split(gw.Prefix, "/")[0]
_, gwNet, err := net.ParseCIDR(gw.Prefix)
if err != nil {
return fmt.Errorf("invalid vnet gateway %s", gw.Prefix)
}
if gwNet.String() == subnet {
vnetGW = gateway
vnetGWIP = gw.Gateway
vnetGW = gw.Prefix
vnetGWIP = gateway
}
}
w.data.nodesMap = nodesMap
Expand Down
13 changes: 5 additions & 8 deletions calicowatcher/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,29 @@ package calicowatcher
import (
"fmt"
"net"
"strconv"

api "github.com/netrisai/netrisapi"
"github.com/netrisai/netriswebapi/v2/types/ipam"
)

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

subnetChilds := []api.APISubnetChild{}
subnetChilds := []*ipam.IPAM{}
for _, subnet := range subnets {
subnetChilds = append(subnetChilds, subnet.Children...)
}

for _, subnet := range subnetChilds {
ipAddr := net.ParseIP(ip)
_, ipNet, err := net.ParseCIDR(fmt.Sprintf("%s/%d", subnet.Prefix, subnet.Length))
_, ipNet, err := net.ParseCIDR(subnet.Prefix)
if err != nil {
return siteID, "", err
}
if ipNet.Contains(ipAddr) {
sID, _ := strconv.Atoi(subnet.SiteID)
if err != nil {
return siteID, "", err
if len(subnet.Sites) > 0 {
return subnet.Sites[0].ID, ipNet.String(), nil
}
return sID, ipNet.String(), nil
}
}

Expand Down
Loading

0 comments on commit b39bdd6

Please sign in to comment.