Skip to content

Commit c687a3b

Browse files
BGP resource fixes (#33)
* fix: bgp: additional printed columns improvement * fix: bgp: rename 'port' to 'port/vnet' in k8s printed columns * fix: bgp: detect ip version * fix: bgp: default originate default value * refactor: update go version to 1.16 * refactor: update netrisapi package and fix appropriate field types * refactor: update netrisapi package and fix neighborAddress field type * fix: bgp struct generated deepcopy * fix: bgp: neighbor address field type * fix: bgp: compare terminateOnSwitch field * helm chart crd update Co-authored-by: Artashes Balabekyan <[email protected]>
1 parent e791c65 commit c687a3b

File tree

9 files changed

+39
-20
lines changed

9 files changed

+39
-20
lines changed

api/v1alpha1/bgp_types.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ type BGPTransport struct {
104104
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
105105
// +kubebuilder:printcolumn:name="BGP State",type=string,JSONPath=`.status.bgpstate`
106106
// +kubebuilder:printcolumn:name="Port State",type=string,JSONPath=`.status.portstate`
107-
// +kubebuilder:printcolumn:name="NeighborAS",type=string,JSONPath=`.spec.neighborAs`
107+
// +kubebuilder:printcolumn:name="Neighbor AS",type=string,JSONPath=`.spec.neighborAs`
108108
// +kubebuilder:printcolumn:name="Local address",type=string,JSONPath=`.spec.localIP`
109109
// +kubebuilder:printcolumn:name="Remote address",type=string,JSONPath=`.spec.remoteIP`
110-
// +kubebuilder:printcolumn:name="Port",type=string,JSONPath=`.spec.transport.name`,priority=1
110+
// +kubebuilder:printcolumn:name="Port/Vnet",type=string,JSONPath=`.spec.transport.name`,priority=1
111111
// +kubebuilder:printcolumn:name="VLANID",type=string,JSONPath=`.status.vlanID`,priority=1
112-
// +kubebuilder:printcolumn:name="TerminatedOn",type=string,JSONPath=`.status.terminateOnSwitch`,priority=1
112+
// +kubebuilder:printcolumn:name="Terminated On",type=string,JSONPath=`.status.terminateOnSwitch`,priority=1
113113
// +kubebuilder:printcolumn:name="Modified",type=date,JSONPath=`.status.modified`,priority=1
114114
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
115115

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spec:
1919
name: Port State
2020
type: string
2121
- JSONPath: .spec.neighborAs
22-
name: NeighborAS
22+
name: Neighbor AS
2323
type: string
2424
- JSONPath: .spec.localIP
2525
name: Local address
@@ -28,15 +28,15 @@ spec:
2828
name: Remote address
2929
type: string
3030
- JSONPath: .spec.transport.name
31-
name: Port
31+
name: Port/Vnet
3232
priority: 1
3333
type: string
3434
- JSONPath: .status.vlanID
3535
name: VLANID
3636
priority: 1
3737
type: string
3838
- JSONPath: .status.terminateOnSwitch
39-
name: TerminatedOn
39+
name: Terminated On
4040
priority: 1
4141
type: string
4242
- JSONPath: .status.modified

controllers/bgp_translations.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
4242
vnetID int
4343
imported = false
4444
reclaim = false
45+
ipVersion = "ipv6"
4546
)
4647

47-
originate := ""
48+
originate := "disabled"
4849
localPreference := 100
4950
if site, ok := NStorage.SitesStorage.FindByName(bgp.Spec.Site); ok {
5051
siteID = site.ID
@@ -53,7 +54,7 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
5354
}
5455

5556
if bgp.Spec.DefaultOriginate {
56-
originate = "true"
57+
originate = "enabled"
5758
}
5859

5960
if bgp.Spec.Transport.VlanID > 1 {
@@ -115,6 +116,9 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
115116
localIP, cidr, _ := net.ParseCIDR(bgp.Spec.LocalIP)
116117
remoteIP, _, _ := net.ParseCIDR(bgp.Spec.RemoteIP)
117118
prefixLength, _ := cidr.Mask.Size()
119+
if localIP.To4() != nil {
120+
ipVersion = "ipv4"
121+
}
118122

119123
bgpMeta = &k8sv1alpha1.BGPMeta{
120124
ObjectMeta: metav1.ObjectMeta{
@@ -152,6 +156,7 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
152156
AllowasIn: bgp.Spec.AllowAsIn,
153157
Originate: originate,
154158
PrefixLimit: bgp.Spec.PrefixInboundMax, // ?
159+
IPVersion: ipVersion,
155160
InboundRouteMap: bgpMeta.Spec.InboundRouteMap,
156161
LocalPreference: localPreference,
157162
Weight: bgp.Spec.Weight,
@@ -218,7 +223,7 @@ func BGPMetaToNetris(bgpMeta *k8sv1alpha1.BGPMeta) (*api.APIEBGPAdd, error) {
218223
LocalPreference: bgpMeta.Spec.LocalPreference,
219224
Multihop: bgpMeta.Spec.Multihop,
220225
Name: bgpMeta.Spec.BGPName,
221-
NeighborAddress: bgpMeta.Spec.NeighborAddress,
226+
NeighborAddress: stringOrNull(bgpMeta.Spec.NeighborAddress),
222227
NeighborAs: strconv.Itoa(bgpMeta.Spec.NeighborAs),
223228
NfvID: bgpMeta.Spec.NfvID,
224229
NfvPortID: bgpMeta.Spec.NfvPortID,
@@ -262,14 +267,14 @@ func BGPMetaToNetrisUpdate(bgpMeta *k8sv1alpha1.BGPMeta) (*api.APIEBGPUpdate, er
262267
LocalPreference: bgpMeta.Spec.LocalPreference,
263268
Multihop: bgpMeta.Spec.Multihop,
264269
Name: bgpMeta.Spec.BGPName,
265-
NeighborAddress: bgpMeta.Spec.NeighborAddress,
270+
NeighborAddress: stringOrNull(bgpMeta.Spec.NeighborAddress),
266271
NeighborAs: strconv.Itoa(bgpMeta.Spec.NeighborAs),
267272
NfvID: bgpMeta.Spec.NfvID,
268273
NfvPortID: bgpMeta.Spec.NfvPortID,
269274
Originate: bgpMeta.Spec.Originate,
270275
OutboundRouteMap: bgpMeta.Spec.OutboundRouteMap,
271276
PrefixLength: bgpMeta.Spec.PrefixLength,
272-
PrefixLimit: bgpMeta.Spec.PrefixLimit,
277+
PrefixLimit: strconv.Itoa(bgpMeta.Spec.PrefixLimit),
273278
PrefixListInbound: bgpMeta.Spec.PrefixListInbound,
274279
PrefixListOutbound: bgpMeta.Spec.PrefixListOutbound,
275280
PrependInbound: bgpMeta.Spec.PrependInbound,
@@ -330,8 +335,11 @@ func compareBGPMetaAPIEBGP(bgpMeta *k8sv1alpha1.BGPMeta, apiBGP *api.APIEBGP) bo
330335
return false
331336
}
332337

338+
if bgpMeta.Spec.TerminateOnSwitch != apiBGP.TerminateOnSwitch {
339+
return false
340+
}
341+
333342
if bgpMeta.Spec.TerminateOnSwitch != "yes" && bgpMeta.Spec.NfvID != apiBGP.TermSwitchID {
334-
fmt.Println("TermSwitchID")
335343
return false
336344
}
337345
// if apiBGP.NfvID != bgpMeta.Spec.NfvID {

controllers/utils.go

+7
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ func regParser(valueMatch []string, subexpNames []string) map[string]string {
5555
}
5656
return result
5757
}
58+
59+
func stringOrNull(s string) *string {
60+
if len(s) > 0 {
61+
return &s
62+
}
63+
return nil
64+
}

deploy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ All resources are included in a single YAML manifest file:
1111
1) Install the CustomResourceDefinitions and netris-operator itself:
1212

1313
```
14-
kubectl apply -f https://github.com/netrisai/netris-operator/releases/download/v0.4.1/netris-operator.yaml
14+
kubectl apply -f https://github.com/netrisai/netris-operator/releases/download/v0.4.2/netris-operator.yaml
1515
```
1616

1717

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.3.3
18+
version: 0.3.4
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: v0.4.1
23+
appVersion: v0.4.2
2424
home: https://github.com/netrisai/netris-operator
2525
icon: https://www.netris.ai/wp-content/uploads/2020/05/logo-600.png # [todo] Change url to permalink
2626
keywords:

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spec:
1919
name: Port State
2020
type: string
2121
- JSONPath: .spec.neighborAs
22-
name: NeighborAS
22+
name: Neighbor AS
2323
type: string
2424
- JSONPath: .spec.localIP
2525
name: Local address
@@ -28,15 +28,15 @@ spec:
2828
name: Remote address
2929
type: string
3030
- JSONPath: .spec.transport.name
31-
name: Port
31+
name: Port/Vnet
3232
priority: 1
3333
type: string
3434
- JSONPath: .status.vlanID
3535
name: VLANID
3636
priority: 1
3737
type: string
3838
- JSONPath: .status.terminateOnSwitch
39-
name: TerminatedOn
39+
name: Terminated On
4040
priority: 1
4141
type: string
4242
- JSONPath: .status.modified

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module github.com/netrisai/netris-operator
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/go-logr/logr v0.1.0
77
github.com/kelseyhightower/envconfig v1.4.0
88
github.com/mitchellh/mapstructure v1.4.1 // indirect
9-
github.com/netrisai/netrisapi v0.0.0-20210401135324-2d43003b1f89
9+
github.com/netrisai/netrisapi v0.0.0-20210610175837-ededc2c4cd4b
1010
github.com/onsi/ginkgo v1.12.1
1111
github.com/onsi/gomega v1.10.1
1212
github.com/prometheus/common v0.4.1

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ github.com/netrisai/netrisapi v0.0.0-20210401135108-e8ab0d6a45f7 h1:rfgrZT5y7u7a
279279
github.com/netrisai/netrisapi v0.0.0-20210401135108-e8ab0d6a45f7/go.mod h1:IqkB+A4amKw4jG8dgAWjcWE0W7rvIbSl4K+E3v332ZM=
280280
github.com/netrisai/netrisapi v0.0.0-20210401135324-2d43003b1f89 h1:aJSD17vqty2loV+jrDK7xes+lgzOBJFJZaJA1U/ZhI8=
281281
github.com/netrisai/netrisapi v0.0.0-20210401135324-2d43003b1f89/go.mod h1:IqkB+A4amKw4jG8dgAWjcWE0W7rvIbSl4K+E3v332ZM=
282+
github.com/netrisai/netrisapi v0.0.0-20210609193230-8881eda50f3a h1:x0piXuyEZm/NFIAr4px2MNyzFvOKaNN33Um6szHm0jg=
283+
github.com/netrisai/netrisapi v0.0.0-20210609193230-8881eda50f3a/go.mod h1:IqkB+A4amKw4jG8dgAWjcWE0W7rvIbSl4K+E3v332ZM=
284+
github.com/netrisai/netrisapi v0.0.0-20210610175837-ededc2c4cd4b h1:Esz09GWT+Gf6HJxEeVuHk9SQkjhVaZLs2AiMeG+3JFA=
285+
github.com/netrisai/netrisapi v0.0.0-20210610175837-ededc2c4cd4b/go.mod h1:IqkB+A4amKw4jG8dgAWjcWE0W7rvIbSl4K+E3v332ZM=
282286
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
283287
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
284288
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=

0 commit comments

Comments
 (0)