Skip to content

Commit e791c65

Browse files
Added BGP resource (#32)
* refactor: make netris storage as a seperate package * feat: netris storage: add functions for ebgp additional types * feat: ebgp: EBGPToEBGPMeta convert * feat: ebgp: EBGPToEBGPMeta type translation * feat: ebgp: add, update funtionality * feat: ebgp: get prefix length from localIP * fix: ebgp: fix fields * refactor: rename ebgp to bgp * feat: bgp: add comparison functionality * fix: bgp: terminateOnSwitch value should be 'yes/no' only * fix: bgp: compare nfvID with termSwitchID if termOnSwitch is disabled * fix: bgp: fill switchTermID field * fix: bgp: compare rcircuidID field * fix: bgp: don't compare termSwitchName * fix: bgp: don't compare prefixLimit * update bgp sample * feat: bgp: change terminateOnSwitch field structure * fix: bgp: set vlanID to 1 as untagged * feat: bgp: add additional printed columns * fix: bgp: improve vlanID handling * update dockerfile and increase app version * Added bgp crds Co-authored-by: Artashes Balabekyan <[email protected]>
1 parent 47a68dc commit e791c65

Some content is hidden

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

44 files changed

+2344
-1292
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ COPY api/ api/
2121
COPY controllers/ controllers/
2222
COPY configloader/ configloader/
2323
COPY lbwatcher/ lbwatcher/
24+
COPY netrisstorage/ netrisstorage/
2425

2526
# Build
2627
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager main.go

PROJECT

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ resources:
1010
kind: VNetMeta
1111
version: v1alpha1
1212
- group: k8s
13-
kind: EBGP
13+
kind: BGP
1414
version: v1alpha1
1515
- group: k8s
16-
kind: EBGPMeta
16+
kind: BGPMeta
1717
version: v1alpha1
1818
- group: k8s
1919
kind: L4LB

api/v1alpha1/ebgp_types.go renamed to api/v1alpha1/bgp_types.go

+63-40
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,30 @@ import (
2323
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2424
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2525

26-
// EBGPStatus defines the observed state of EBGP
27-
type EBGPStatus struct {
26+
// BGPStatus defines the observed state of BGP
27+
type BGPStatus struct {
2828
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
2929
// Important: Run "make" to regenerate code after modifying this file
3030

31-
Status string `json:"status,omitempty"`
32-
Message string `json:"message,omitempty"`
31+
Status string `json:"status,omitempty"`
32+
State string `json:"state,omitempty"`
33+
ModifiedDate metav1.Time `json:"modified,omitempty"`
34+
Message string `json:"message,omitempty"`
35+
BGPState string `json:"bgpstate,omitempty"`
36+
PortState string `json:"portstate,omitempty"`
37+
TerminateOnSwitch string `json:"terminateOnSwitch,omitempty"`
38+
VLANID string `json:"vlanID,omitempty"`
3339
}
3440

35-
// EBGPSpec defines the desired state of EBGP
36-
type EBGPSpec struct {
41+
// BGPSpec defines the desired state of BGP
42+
type BGPSpec struct {
3743
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3844
// Important: Run "make" to regenerate code after modifying this file
3945

40-
Site string `json:"site"`
41-
Softgate string `json:"softgate"`
42-
NeighborAS int `json:"neighborAs"`
43-
Transport EBGPTransport `json:"transport"`
46+
Site string `json:"site"`
47+
Softgate string `json:"softgate,omitempty"`
48+
NeighborAS int `json:"neighborAs"`
49+
Transport BGPTransport `json:"transport"`
4450

4551
// +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]))?$)`
4652
LocalIP string `json:"localIP"`
@@ -50,26 +56,32 @@ type EBGPSpec struct {
5056
Description string `json:"description,omitempty"`
5157

5258
// +kubebuilder:validation:Enum=enabled;disabled
53-
State string `json:"state,omitempty"`
54-
TerminateOnSwitch bool `json:"terminateOnSwitch,omitempty"`
55-
Multihop EBGPMultihop `json:"multihop,omitempty"`
56-
BGPPassword string `json:"bgpPassword,omitempty"`
57-
AllowAsIn int `json:"allowAsIn,omitempty"`
58-
DefaultOriginate bool `json:"defaultOriginate,omitempty"`
59-
PrefixInboundMax int `json:"prefixInboundMax,omitempty"`
60-
InboundRouteMap string `json:"inboundRouteMap,omitempty"`
61-
OutboundRouteMap string `json:"outboundRouteMap,omitempty"`
62-
LocalPreference int `json:"localPreference,omitempty"`
63-
Weight int `json:"weight,omitempty"`
64-
PrependInbound int `json:"prependInbound,omitempty"`
65-
PrependOutbound int `json:"prependOutbound,omitempty"`
66-
PrefixListInbound []string `json:"prefixListInbound,omitempty"`
67-
PrefixListOutbound []string `json:"prefixListOutbound,omitempty"`
68-
SendBGPCommunity []string `json:"sendBGPCommunity,omitempty"`
59+
State string `json:"state,omitempty"`
60+
TerminateOnSwitch BGPTerminateOnSwitch `json:"terminateOnSwitch,omitempty"`
61+
Multihop BGPMultihop `json:"multihop,omitempty"`
62+
BGPPassword string `json:"bgpPassword,omitempty"`
63+
AllowAsIn int `json:"allowAsIn,omitempty"`
64+
DefaultOriginate bool `json:"defaultOriginate,omitempty"`
65+
PrefixInboundMax int `json:"prefixInboundMax,omitempty"`
66+
InboundRouteMap string `json:"inboundRouteMap,omitempty"`
67+
OutboundRouteMap string `json:"outboundRouteMap,omitempty"`
68+
LocalPreference int `json:"localPreference,omitempty"`
69+
Weight int `json:"weight,omitempty"`
70+
PrependInbound int `json:"prependInbound,omitempty"`
71+
PrependOutbound int `json:"prependOutbound,omitempty"`
72+
PrefixListInbound []string `json:"prefixListInbound,omitempty"`
73+
PrefixListOutbound []string `json:"prefixListOutbound,omitempty"`
74+
SendBGPCommunity []string `json:"sendBGPCommunity,omitempty"`
6975
}
7076

71-
// EBGPMultihop .
72-
type EBGPMultihop struct {
77+
// BGPTerminateOnSwitch .
78+
type BGPTerminateOnSwitch struct {
79+
Enabled bool `json:"enabled"`
80+
SwitchName string `json:"switchName,omitempty"`
81+
}
82+
83+
// BGPMultihop .
84+
type BGPMultihop struct {
7385
// +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]))?$)`
7486
NeighborAddress string `json:"neighborAddress,omitempty"`
7587

@@ -78,36 +90,47 @@ type EBGPMultihop struct {
7890
Hops int `json:"hops,omitempty"`
7991
}
8092

81-
// EBGPTransport .
82-
type EBGPTransport struct {
93+
// BGPTransport .
94+
type BGPTransport struct {
8395
// +kubebuilder:validation:Enum=port;vnet
8496
Type string `json:"type,omitempty"`
85-
// +kubebuilder:validation:Pattern=`(^[a-zA-Z0-9]+@[a-zA-Z0-9-]+$)|(^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$)`
97+
// +kubebuilder:validation:Pattern=`(^[a-zA-Z0-9]+@[a-zA-Z0-9-]+$)|(^[a-zA-Z0-9]([-a-zA-Z0-9]*[a-z0-9])?(\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?)*$)`
8698
Name string `json:"name"`
8799
VlanID int `json:"vlanId,omitempty"`
88100
}
89101

90102
// +kubebuilder:object:root=true
91103
// +kubebuilder:subresource:status
92-
93-
// EBGP is the Schema for the ebgps API
94-
type EBGP struct {
104+
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
105+
// +kubebuilder:printcolumn:name="BGP State",type=string,JSONPath=`.status.bgpstate`
106+
// +kubebuilder:printcolumn:name="Port State",type=string,JSONPath=`.status.portstate`
107+
// +kubebuilder:printcolumn:name="NeighborAS",type=string,JSONPath=`.spec.neighborAs`
108+
// +kubebuilder:printcolumn:name="Local address",type=string,JSONPath=`.spec.localIP`
109+
// +kubebuilder:printcolumn:name="Remote address",type=string,JSONPath=`.spec.remoteIP`
110+
// +kubebuilder:printcolumn:name="Port",type=string,JSONPath=`.spec.transport.name`,priority=1
111+
// +kubebuilder:printcolumn:name="VLANID",type=string,JSONPath=`.status.vlanID`,priority=1
112+
// +kubebuilder:printcolumn:name="TerminatedOn",type=string,JSONPath=`.status.terminateOnSwitch`,priority=1
113+
// +kubebuilder:printcolumn:name="Modified",type=date,JSONPath=`.status.modified`,priority=1
114+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
115+
116+
// BGP is the Schema for the bgps API
117+
type BGP struct {
95118
metav1.TypeMeta `json:",inline"`
96119
metav1.ObjectMeta `json:"metadata,omitempty"`
97120

98-
Spec EBGPSpec `json:"spec,omitempty"`
99-
Status EBGPStatus `json:"status,omitempty"`
121+
Spec BGPSpec `json:"spec,omitempty"`
122+
Status BGPStatus `json:"status,omitempty"`
100123
}
101124

102125
// +kubebuilder:object:root=true
103126

104-
// EBGPList contains a list of EBGP
105-
type EBGPList struct {
127+
// BGPList contains a list of BGP
128+
type BGPList struct {
106129
metav1.TypeMeta `json:",inline"`
107130
metav1.ListMeta `json:"metadata,omitempty"`
108-
Items []EBGP `json:"items"`
131+
Items []BGP `json:"items"`
109132
}
110133

111134
func init() {
112-
SchemeBuilder.Register(&EBGP{}, &EBGPList{})
135+
SchemeBuilder.Register(&BGP{}, &BGPList{})
113136
}

api/v1alpha1/ebgpmeta_types.go renamed to api/v1alpha1/bgpmeta_types.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import (
2323
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2424
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2525

26-
// EBGPMetaSpec defines the desired state of EBGPMeta
27-
type EBGPMetaSpec struct {
26+
// BGPMetaSpec defines the desired state of BGPMeta
27+
type BGPMetaSpec struct {
2828
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2929
// Important: Run "make" to regenerate code after modifying this file
30-
Imported bool `json:"imported"`
31-
Reclaim bool `json:"reclaimPolicy"`
32-
EBGPCRGeneration int64 `json:"ebgpGeneration"`
33-
ID int `json:"id"`
34-
EBGPName string `json:"ebgpName"`
30+
Imported bool `json:"imported"`
31+
Reclaim bool `json:"reclaimPolicy"`
32+
BGPCRGeneration int64 `json:"bgpGeneration"`
33+
ID int `json:"id"`
34+
BGPName string `json:"bgpName"`
3535

3636
AllowasIn int `json:"allowas_in"`
3737
BgpPassword string `json:"bgp_password"`
@@ -71,32 +71,32 @@ type EBGPMetaSpec struct {
7171
Weight int `json:"weight"`
7272
}
7373

74-
// EBGPMetaStatus defines the observed state of EBGPMeta
75-
type EBGPMetaStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
74+
// BGPMetaStatus defines the observed state of BGPMeta
75+
type BGPMetaStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
7676
// Important: Run "make" to regenerate code after modifying this file
7777
}
7878

7979
// +kubebuilder:object:root=true
8080
// +kubebuilder:subresource:status
8181

82-
// EBGPMeta is the Schema for the ebgpmeta API
83-
type EBGPMeta struct {
82+
// BGPMeta is the Schema for the bgpmeta API
83+
type BGPMeta struct {
8484
metav1.TypeMeta `json:",inline"`
8585
metav1.ObjectMeta `json:"metadata,omitempty"`
8686

87-
Spec EBGPMetaSpec `json:"spec,omitempty"`
88-
Status EBGPMetaStatus `json:"status,omitempty"`
87+
Spec BGPMetaSpec `json:"spec,omitempty"`
88+
Status BGPMetaStatus `json:"status,omitempty"`
8989
}
9090

9191
// +kubebuilder:object:root=true
9292

93-
// EBGPMetaList contains a list of EBGPMeta
94-
type EBGPMetaList struct {
93+
// BGPMetaList contains a list of BGPMeta
94+
type BGPMetaList struct {
9595
metav1.TypeMeta `json:",inline"`
9696
metav1.ListMeta `json:"metadata,omitempty"`
97-
Items []EBGPMeta `json:"items"`
97+
Items []BGPMeta `json:"items"`
9898
}
9999

100100
func init() {
101-
SchemeBuilder.Register(&EBGPMeta{}, &EBGPMetaList{})
101+
SchemeBuilder.Register(&BGPMeta{}, &BGPMetaList{})
102102
}

0 commit comments

Comments
 (0)