Skip to content

Commit bccd7f3

Browse files
Hotfixes for netris v3 api updates (#44)
* fix: update netrisapi package * fix: bgp: OutboundRouteMap field type * fix: calicowatcher: improve cni detection * fix: lbwatcher: detect side using pod host ip (#43) * fix: vnet: remove unused prints * fix: bgp: use portID instead of portName * fix: bgp: portID compare log * update crds * Preparation for a release Co-authored-by: Artashes Balabekyan <[email protected]>
1 parent c501dde commit bccd7f3

File tree

13 files changed

+134
-68
lines changed

13 files changed

+134
-68
lines changed

api/v1alpha1/bgpmeta_types.go

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

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"`
36+
AllowasIn int `json:"allowas_in"`
37+
HWID int `json:"hwid"`
38+
PortID int `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"`
6666
}
6767

6868
// BGPMetaStatus defines the observed state of BGPMeta

api/v1alpha1/zz_generated.deepcopy.go

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

calicowatcher/calico/bgpconfigurations.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ type ServiceClusterIPBlock struct {
7171
CIDR string `json:"cidr,omitempty" validate:"omitempty,net"`
7272
}
7373

74+
func IsCalicoNotDetected(err error) bool {
75+
return err.Error() == "Calico CNI not detected"
76+
}
77+
7478
// GetBGPConfiguration .
7579
func (c *Calico) GetBGPConfiguration(config *rest.Config) ([]*BGPConfiguration, error) {
7680
ctx, cancel := context.WithTimeout(cntxt, contextTimeout)
@@ -88,7 +92,7 @@ func (c *Calico) GetBGPConfiguration(config *rest.Config) ([]*BGPConfiguration,
8892

8993
list, err := dynClient.Resource(bgpConfigurationResource).List(ctx, metav1.ListOptions{})
9094
if err != nil {
91-
return nil, fmt.Errorf("{getBGPConfiguration} %s", err)
95+
return nil, fmt.Errorf("Calico CNI not detected")
9296
}
9397

9498
var bgpConfigurations []*BGPConfiguration

calicowatcher/main.go

+10
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,18 @@ func (w *Watcher) deleteProcess() error {
372372
func (w *Watcher) mainProcessing() error {
373373
var err error
374374
if w.data.bgpConfs, err = w.Calico.GetBGPConfiguration(w.restClient); err != nil {
375+
if calico.IsCalicoNotDetected(err) {
376+
logger.Info(err.Error())
377+
return nil
378+
}
375379
return err
376380
}
381+
382+
if len(w.data.bgpConfs) == 0 {
383+
logger.Info("bgpconfigurations.crd.projectcalico.org not found")
384+
return nil
385+
}
386+
377387
if !w.checkBGPConfigurations() {
378388
w.data.deleteMode = true
379389
}

config/crd/bases/k8s.netris.ai_bgpmeta.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ spec:
8080
outboundRouteMap:
8181
type: integer
8282
port:
83-
type: string
83+
type: integer
8484
prefix_length:
8585
type: integer
8686
prefix_limit:

controllers/bgp_translations.go

+17-15
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
3636
reclaim = false
3737
ipVersion = "ipv6"
3838
hwID = 0
39-
port = ""
39+
portID = 0
4040
vnetID = 0
4141
)
4242

@@ -60,7 +60,9 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
6060
}
6161

6262
if bgp.Spec.Transport.Type == "port" {
63-
port = bgp.Spec.Transport.Name
63+
if port, ok := r.NStorage.PortsStorage.FindByName(bgp.Spec.Transport.Name); ok {
64+
portID = port.ID
65+
}
6466
vlanID = 1
6567
} else {
6668
vnets, err := r.Cred.VNet().Get()
@@ -103,9 +105,10 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
103105
ipVersion = "ipv4"
104106
}
105107

106-
var neighborAddress *string
108+
var neighborAddress string
109+
107110
if bgp.Spec.Multihop.NeighborAddress != "" && bgp.Spec.Multihop.Hops > 0 {
108-
neighborAddress = &bgp.Spec.Multihop.NeighborAddress
111+
neighborAddress = bgp.Spec.Multihop.NeighborAddress
109112
}
110113

111114
bgpMeta = &k8sv1alpha1.BGPMeta{
@@ -120,7 +123,7 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
120123
Name: string(bgp.GetUID()),
121124
HWID: hwID,
122125
VnetID: vnetID,
123-
Port: port,
126+
PortID: portID,
124127
Site: bgp.Spec.Site,
125128
BGPName: bgp.Name,
126129
Vlan: vlanID,
@@ -207,13 +210,14 @@ func BGPMetaToNetris(bgpMeta *k8sv1alpha1.BGPMeta) (*bgp.EBGPAdd, error) {
207210
} else {
208211
hwID = "auto"
209212
}
213+
210214
bgpAdd := &bgp.EBGPAdd{
211215
AllowAsIn: bgpMeta.Spec.AllowasIn,
212216
BgpPassword: bgpMeta.Spec.BgpPassword,
213217
BgpCommunity: bgpMeta.Spec.Community,
214218
Hardware: bgp.IDNone{ID: hwID},
215219
Vnet: bgp.IDNone{ID: vnetID},
216-
Port: bgp.IDName{Name: bgpMeta.Spec.Port},
220+
Port: bgp.IDName{ID: bgpMeta.Spec.PortID},
217221
Description: bgpMeta.Spec.Description,
218222
InboundRouteMap: bgpMeta.Spec.InboundRouteMap,
219223
IPFamily: bgpMeta.Spec.IPVersion,
@@ -282,7 +286,7 @@ func BGPMetaToNetrisUpdate(bgpMeta *k8sv1alpha1.BGPMeta) (*bgp.EBGPUpdate, error
282286
Site: bgp.IDName{Name: bgpMeta.Spec.Site},
283287
State: bgpMeta.Spec.Status,
284288
Hardware: bgp.IDNone{ID: hwID},
285-
Port: bgp.IDName{Name: bgpMeta.Spec.Port},
289+
Port: bgp.IDName{ID: bgpMeta.Spec.PortID},
286290
Vnet: bgp.IDNone{ID: vnetID},
287291
UpdateSource: bgpMeta.Spec.UpdateSource,
288292
Vlan: bgpMeta.Spec.Vlan,
@@ -309,8 +313,7 @@ func compareBGPMetaAPIEBGP(bgpMeta *k8sv1alpha1.BGPMeta, apiBGP *bgp.EBGP, u uni
309313
u.DebugLogger.Info("Description changed", "netrisValue", apiBGP.Description, "k8sValue", bgpMeta.Spec.Description)
310314
return false
311315
}
312-
inboundRouteMap, _ := strconv.Atoi(apiBGP.InboundRouteMap)
313-
if inboundRouteMap != bgpMeta.Spec.InboundRouteMap {
316+
if apiBGP.InboundRouteMap != bgpMeta.Spec.InboundRouteMap {
314317
u.DebugLogger.Info("InboundRouteMap changed", "netrisValue", apiBGP.InboundRouteMap, "k8sValue", bgpMeta.Spec.InboundRouteMap)
315318
return false
316319
}
@@ -335,8 +338,8 @@ func compareBGPMetaAPIEBGP(bgpMeta *k8sv1alpha1.BGPMeta, apiBGP *bgp.EBGP, u uni
335338
return false
336339
}
337340
neighborAddress := ""
338-
if bgpMeta.Spec.NeighborAddress != nil {
339-
neighborAddress = *bgpMeta.Spec.NeighborAddress
341+
if bgpMeta.Spec.NeighborAddress != "" {
342+
neighborAddress = bgpMeta.Spec.NeighborAddress
340343
}
341344
if apiBGP.NeighborAddress != neighborAddress {
342345
u.DebugLogger.Info("NeighborAddress changed", "netrisValue", apiBGP.NeighborAddress, "k8sValue", neighborAddress)
@@ -347,17 +350,16 @@ func compareBGPMetaAPIEBGP(bgpMeta *k8sv1alpha1.BGPMeta, apiBGP *bgp.EBGP, u uni
347350
return false
348351
}
349352
if port, ok := u.NStorage.PortsStorage.FindByID(apiBGP.Port.ID); ok {
350-
if port.ShortName != bgpMeta.Spec.Port {
351-
u.DebugLogger.Info("Port changed", "netrisValue", port.ShortName, "k8sValue", bgpMeta.Spec.Port)
353+
if port.ID != bgpMeta.Spec.PortID {
354+
u.DebugLogger.Info("Port changed", "netrisValue", port.ID, "k8sValue", bgpMeta.Spec.PortID)
352355
return false
353356
}
354357
}
355358
if apiBGP.Originate != bgpMeta.Spec.Originate {
356359
u.DebugLogger.Info("Originate changed", "netrisValue", apiBGP.Originate, "k8sValue", bgpMeta.Spec.Originate)
357360
return false
358361
}
359-
outboundRouteMap, _ := strconv.Atoi(apiBGP.OutboundRouteMap)
360-
if outboundRouteMap != bgpMeta.Spec.OutboundRouteMap {
362+
if apiBGP.OutboundRouteMap != bgpMeta.Spec.OutboundRouteMap {
361363
u.DebugLogger.Info("OutboundRouteMap changed", "netrisValue", apiBGP.OutboundRouteMap, "k8sValue", bgpMeta.Spec.OutboundRouteMap)
362364
return false
363365
}

controllers/vnet_translations.go

-6
Original file line numberDiff line numberDiff line change
@@ -248,31 +248,25 @@ func compareVNetMetaAPIVnetSites(vnetMetaSites []k8sv1alpha1.VNetMetaSite, apiVn
248248

249249
func compareVNetMetaAPIVnet(vnetMeta *k8sv1alpha1.VNetMeta, apiVnet *vnet.VNetDetailed) bool {
250250
if ok := compareVNetMetaAPIVnetSites(vnetMeta.Spec.Sites, apiVnet.Sites); !ok {
251-
fmt.Println("apiVnet.Sites")
252251
return false
253252
}
254253
if ok := compareVNetMetaAPIVnetGateways(vnetMeta.Spec.Gateways, apiVnet.Gateways); !ok {
255-
fmt.Println("apiVnet.Gateways")
256254
return false
257255
}
258256
if ok := compareVNetMetaAPIVnetMembers(vnetMeta.Spec.Members, apiVnet.Ports); !ok {
259-
fmt.Println("apiVnet.Ports")
260257
return false
261258
}
262259

263260
if vnetMeta.Spec.VnetName != apiVnet.Name {
264-
fmt.Println("apiVnet.Name ")
265261
return false
266262
}
267263

268264
if vnetMeta.Spec.Owner != apiVnet.Tenant.Name {
269265
fmt.Println(vnetMeta.Spec.Owner, apiVnet.Tenant.Name)
270-
fmt.Println("Tenant.Name ")
271266
return false
272267
}
273268

274269
if ok := compareVNetMetaAPIVnetTenants(vnetMeta.Spec.Tenants, apiVnet.GuestTenants); !ok {
275-
fmt.Println("apiVnet.GuestTenants")
276270
return false
277271
}
278272

deploy/charts/netris-operator/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.4.1
18+
version: 0.4.2
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
23-
appVersion: v1.0.1
23+
appVersion: v1.0.2
2424
home: https://github.com/netrisai/netris-operator
2525
icon: https://www.netris.ai/wp-content/uploads/2021/01/logo-300.png # [todo] Change url to permalink
2626
keywords:

deploy/charts/netris-operator/crds/k8s.netris.ai_bgpmeta.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ spec:
8080
outboundRouteMap:
8181
type: integer
8282
port:
83-
type: string
83+
type: integer
8484
prefix_length:
8585
type: integer
8686
prefix_limit:

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/go-logr/logr v0.1.0
77
github.com/kelseyhightower/envconfig v1.4.0
88
github.com/kr/text v0.2.0 // indirect
9-
github.com/netrisai/netriswebapi v0.0.0-20211012100315-a14cd51ac872
9+
github.com/netrisai/netriswebapi v0.0.0-20220125103148-df073aedbe0f
1010
github.com/onsi/ginkgo v1.12.1
1111
github.com/onsi/gomega v1.10.1
1212
github.com/r3labs/diff/v2 v2.9.1

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ github.com/netrisai/netriswebapi v0.0.0-20211012092236-d9475f5b4c5f h1:VV4kJlTfn
275275
github.com/netrisai/netriswebapi v0.0.0-20211012092236-d9475f5b4c5f/go.mod h1:GLLz33Jc07/hIPwEYZDWEtNtHjX/QZjVzf9xLnfSiqs=
276276
github.com/netrisai/netriswebapi v0.0.0-20211012100315-a14cd51ac872 h1:vFh/DMYN1ZyvL+utdz4Nwo4e9Wl33nqLmhWOTk/YW/s=
277277
github.com/netrisai/netriswebapi v0.0.0-20211012100315-a14cd51ac872/go.mod h1:GLLz33Jc07/hIPwEYZDWEtNtHjX/QZjVzf9xLnfSiqs=
278+
github.com/netrisai/netriswebapi v0.0.0-20220124235811-1be709216ce0 h1:brlDNeDjuP/xBNTmVXO4bk9iv+PHwg+utQUbRvQ4qVQ=
279+
github.com/netrisai/netriswebapi v0.0.0-20220124235811-1be709216ce0/go.mod h1:GLLz33Jc07/hIPwEYZDWEtNtHjX/QZjVzf9xLnfSiqs=
280+
github.com/netrisai/netriswebapi v0.0.0-20220125103148-df073aedbe0f h1:L20UUY0zsLahHQbg4DJb4lwp+W7Z9Pc884r70xJv2DI=
281+
github.com/netrisai/netriswebapi v0.0.0-20220125103148-df073aedbe0f/go.mod h1:GLLz33Jc07/hIPwEYZDWEtNtHjX/QZjVzf9xLnfSiqs=
278282
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
279283
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
280284
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=

lbwatcher/lb_watcher.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,7 @@ func (w *Watcher) generateLoadBalancers(clientset *kubernetes.Clientset, autoIPs
367367
return lbList, fmt.Errorf("{generateLoadBalancers} %s", err)
368368
}
369369

370-
site, ok := w.NStorage.SitesStorage.FindByID(1)
371-
if !ok {
372-
return lbList, fmt.Errorf("{generateLoadBalancers} Default site not found")
373-
}
370+
var siteName string
374371

375372
for _, svc := range serviceList.Items {
376373
if svc.Spec.Type == "LoadBalancer" {
@@ -433,6 +430,13 @@ func (w *Watcher) generateLoadBalancers(clientset *kubernetes.Clientset, autoIPs
433430
}
434431
backends := []k8sv1alpha1.L4LBBackend{}
435432
for _, hostIP := range hostIPS {
433+
if siteName == "" {
434+
site, _, err := w.findSiteByIP(hostIP)
435+
if err != nil {
436+
fmt.Println(err)
437+
}
438+
siteName = site.Name
439+
}
436440
backend := fmt.Sprintf("%s:%d", hostIP, lbIP.NodePort)
437441
backends = append(backends, k8sv1alpha1.L4LBBackend(backend))
438442
}
@@ -448,7 +452,7 @@ func (w *Watcher) generateLoadBalancers(clientset *kubernetes.Clientset, autoIPs
448452
APIVersion: "k8s.netris.ai/v1alpha1",
449453
},
450454
Spec: k8sv1alpha1.L4LBSpec{
451-
Site: site.Name,
455+
Site: siteName,
452456
Protocol: strings.ToLower(lbIP.Protocol),
453457
Frontend: k8sv1alpha1.L4LBFrontend{
454458
Port: lbIP.Port,
@@ -476,3 +480,7 @@ func (w *Watcher) generateLoadBalancers(clientset *kubernetes.Clientset, autoIPs
476480
}
477481
return lbList, nil
478482
}
483+
484+
func findSiteByIP(hostIP string) {
485+
panic("unimplemented")
486+
}

0 commit comments

Comments
 (0)