Skip to content

Commit abe360f

Browse files
VNet - New Structure (#76)
* use site's v2 api * refactor site deletion logic * feat: vnet: add global vlanId support * fix: exit in case of auth error * feat: vnet: add dhcp support for gateways * uncapitalize error strings * remove redundant imports * remove unused function findTenantByIP * fix: vnet: use dhcp optionset id in vnetmeta * update samples --------- Co-authored-by: Artashes Balabekyan <[email protected]>
1 parent 6bae407 commit abe360f

31 files changed

+344
-190
lines changed

api/v1alpha1/vnet_types.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,21 @@ type VNetSite struct {
9292
SwitchPorts []VNetSwitchPort `json:"switchPorts,omitempty"`
9393
}
9494

95-
// +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]))?$)`
96-
9795
// VNetGateway .
98-
type VNetGateway string
96+
type VNetGateway struct {
97+
// +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]))?$)`
98+
Prefix string `json:"prefix"`
9999

100-
func (v *VNetGateway) String() string {
101-
if v == nil {
102-
return ""
103-
}
104-
return string(*v)
100+
// +kubebuilder:validation:Enum=enabled;disabled
101+
DHCP string `json:"dhcp,omitempty"`
102+
103+
DHCPOptionSet string `json:"dhcpOptionSet,omitempty"`
104+
105+
// +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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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]))?$)`
106+
DHCPStartIP string `json:"dhcpStartIP,omitempty"`
107+
108+
// +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]))?$)`
109+
DHCPEndIP string `json:"dhcpEndIP,omitempty"`
105110
}
106111

107112
// VNetSwitchPort .
@@ -125,7 +130,7 @@ func (vnet *VNet) GatewaysString() string {
125130
strArr := []string{}
126131
for _, site := range vnet.Spec.Sites {
127132
for _, gateway := range site.Gateways {
128-
strArr = append(strArr, gateway.String())
133+
strArr = append(strArr, gateway.Prefix)
129134
}
130135
}
131136
str = strings.Join(strArr, ", ")

api/v1alpha1/vnetmeta_types.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ type VNetMetaMember struct {
6262

6363
// VNetMetaGateway .
6464
type VNetMetaGateway struct {
65-
Gateway string `json:"gateway"`
66-
GwLength int `json:"gwLength"`
67-
ID int `json:"id,omitempty"`
68-
VaVLANID int `json:"vaVlanId,omitempty"`
69-
Nos string `json:"nos,omitempty"`
70-
Version string `json:"version,omitempty"`
65+
Gateway string `json:"gateway"`
66+
GwLength int `json:"gwLength"`
67+
ID int `json:"id,omitempty"`
68+
VaVLANID int `json:"vaVlanId,omitempty"`
69+
Nos string `json:"nos,omitempty"`
70+
Version string `json:"version,omitempty"`
71+
DHCP bool `json:"dhcp,omitempty"`
72+
DHCPOptionSetID int `json:"dhcpOptionSetID,omitempty"`
73+
DHCPStartIP string `json:"dhcpStartIP,omitempty"`
74+
DHCPEndIP string `json:"dhcpEndIP,omitempty"`
7175
}
7276

7377
// VNetMetaStatus defines the observed state of VNetMeta

api/v1alpha1/zz_generated.deepcopy.go

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

calicowatcher/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/netrisai/netris-operator/calicowatcher/calico"
3232
"github.com/netrisai/netris-operator/configloader"
3333
"github.com/netrisai/netris-operator/netrisstorage"
34-
"github.com/netrisai/netriswebapi/v1/types/site"
34+
"github.com/netrisai/netriswebapi/v2/types/site"
3535
"github.com/netrisai/netriswebapi/v2/types/vnet"
3636
"github.com/r3labs/diff/v2"
3737
"go.uber.org/zap/zapcore"
@@ -236,7 +236,7 @@ func (w *Watcher) process() error {
236236
}
237237

238238
debugLogger.Info("Generating netris-controller peer", "deleteMode", w.data.deleteMode)
239-
peer := w.Calico.GenerateBGPPeer("netris-controller", "", w.data.vnetGWIP, w.data.site.ASN)
239+
peer := w.Calico.GenerateBGPPeer("netris-controller", "", w.data.vnetGWIP, w.data.site.PublicAsn)
240240

241241
if netrisPeer == nil {
242242
debugLogger.Info("Creating netris-controller peer", "deleteMode", w.data.deleteMode)

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

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ spec:
4040
items:
4141
description: VNetMetaGateway .
4242
properties:
43+
dhcp:
44+
type: boolean
45+
dhcpEndIP:
46+
type: string
47+
dhcpOptionSetID:
48+
type: integer
49+
dhcpStartIP:
50+
type: string
4351
gateway:
4452
type: string
4553
gwLength:

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,26 @@ spec:
7676
gateways:
7777
items:
7878
description: VNetGateway .
79-
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]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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]))?$)
80-
type: string
79+
properties:
80+
dhcp:
81+
enum:
82+
- enabled
83+
- disabled
84+
type: string
85+
dhcpEndIP:
86+
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]))?$)
87+
type: string
88+
dhcpOptionSet:
89+
type: string
90+
dhcpStartIP:
91+
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}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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]))?$)
95+
type: string
96+
required:
97+
- prefix
98+
type: object
8199
type: array
82100
name:
83101
type: string

controllers/bgp_translations.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (r *BGPReconciler) BGPToBGPMeta(bgp *k8sv1alpha1.BGP) (*k8sv1alpha1.BGPMeta
6464
if port, ok := r.NStorage.PortsStorage.FindByName(bgp.Spec.Transport.Name); ok {
6565
portID = port.ID
6666
} else if bgp.Spec.Transport.Name != "" {
67-
return nil, fmt.Errorf("Coundn't find port %s", bgp.Spec.Transport.Name)
67+
return nil, fmt.Errorf("coundn't find port %s", bgp.Spec.Transport.Name)
6868
}
6969
vlanID = 1
7070
} else {

controllers/controller_translations.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ func (r *ControllerReconciler) ControllerToControllerMeta(controller *k8sv1alpha
4242
if site, ok := r.NStorage.SitesStorage.FindByName(controller.Spec.Site); ok {
4343
siteID = site.ID
4444
} else {
45-
return nil, fmt.Errorf("Invalid site '%s'", controller.Spec.Site)
45+
return nil, fmt.Errorf("invalid site '%s'", controller.Spec.Site)
4646
}
4747

4848
tenantID := 0
4949
if tenant, ok := r.NStorage.TenantsStorage.FindByName(controller.Spec.Tenant); ok {
5050
tenantID = tenant.ID
5151
} else {
52-
return nil, fmt.Errorf("Invalid tenant '%s'", controller.Spec.Tenant)
52+
return nil, fmt.Errorf("invalid tenant '%s'", controller.Spec.Tenant)
5353
}
5454

5555
controllerMeta := &k8sv1alpha1.ControllerMeta{

controllers/controllermeta_controller.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"sigs.k8s.io/controller-runtime/pkg/client"
2929

3030
"github.com/go-logr/logr"
31-
"github.com/netrisai/netris-operator/api/v1alpha1"
3231
k8sv1alpha1 "github.com/netrisai/netris-operator/api/v1alpha1"
3332
"github.com/netrisai/netris-operator/netrisstorage"
3433
"github.com/netrisai/netriswebapi/http"
@@ -251,7 +250,7 @@ func (r *ControllerMetaReconciler) SetupWithManager(mgr ctrl.Manager) error {
251250
Complete(r)
252251
}
253252

254-
func (u *uniReconciler) updateControllerIfNeccesarry(controllerCR *v1alpha1.Controller, controllerMeta v1alpha1.ControllerMeta) (ctrl.Result, error) {
253+
func (u *uniReconciler) updateControllerIfNeccesarry(controllerCR *k8sv1alpha1.Controller, controllerMeta k8sv1alpha1.ControllerMeta) (ctrl.Result, error) {
255254
shouldUpdateCR := false
256255
if controllerCR.Spec.MainIP == "" && controllerCR.Spec.MainIP != controllerMeta.Spec.MainIP {
257256
controllerCR.Spec.MainIP = controllerMeta.Spec.MainIP

controllers/l4lb_translations.go

+2-28
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (r *L4LBReconciler) L4LBToL4LBMeta(l4lb *k8sv1alpha1.L4LB) (*k8sv1alpha1.L4
7474
if tenantID == 0 {
7575
tenant, ok := r.NStorage.TenantsStorage.FindByName(l4lb.Spec.OwnerTenant)
7676
if !ok {
77-
return nil, fmt.Errorf("Tenant '%s' not found", l4lb.Spec.OwnerTenant)
77+
return nil, fmt.Errorf("tenant '%s' not found", l4lb.Spec.OwnerTenant)
7878
}
7979
tenantID = tenant.ID
8080
}
@@ -389,32 +389,6 @@ func l4lbUpdateDefaultAnnotations(l4lb *k8sv1alpha1.L4LB) {
389389
l4lb.SetAnnotations(annotations)
390390
}
391391

392-
func (r *L4LBReconciler) findTenantByIP(ip string) (int, error) {
393-
tenantID := 0
394-
subnets, err := r.Cred.IPAM().Get()
395-
if err != nil {
396-
return tenantID, err
397-
}
398-
399-
subnetChilds := []*ipam.IPAM{}
400-
for _, subnet := range subnets {
401-
subnetChilds = append(subnetChilds, subnet.Children...)
402-
}
403-
404-
for _, subnet := range subnetChilds {
405-
ipAddr := net.ParseIP(ip)
406-
_, ipNet, err := net.ParseCIDR(subnet.Prefix)
407-
if err != nil {
408-
return tenantID, err
409-
}
410-
if ipNet.Contains(ipAddr) {
411-
return subnet.Tenant.ID, nil
412-
}
413-
}
414-
415-
return tenantID, fmt.Errorf("There are no subnets for specified IP address %s", ip)
416-
}
417-
418392
func (r *L4LBReconciler) findSiteByIP(ip string) (int, error) {
419393
siteID := 0
420394
subnets, err := r.Cred.IPAM().Get()
@@ -440,5 +414,5 @@ func (r *L4LBReconciler) findSiteByIP(ip string) (int, error) {
440414
}
441415
}
442416

443-
return siteID, fmt.Errorf("There are no sites for specified IP address %s", ip)
417+
return siteID, fmt.Errorf("there are no sites for specified IP address %s", ip)
444418
}

controllers/l4lbmeta_controller.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
ctrl "sigs.k8s.io/controller-runtime"
3030
"sigs.k8s.io/controller-runtime/pkg/client"
3131

32-
"github.com/netrisai/netris-operator/api/v1alpha1"
3332
k8sv1alpha1 "github.com/netrisai/netris-operator/api/v1alpha1"
3433
"github.com/netrisai/netris-operator/netrisstorage"
3534
"github.com/netrisai/netriswebapi/http"
@@ -281,7 +280,7 @@ func (r *L4LBMetaReconciler) SetupWithManager(mgr ctrl.Manager) error {
281280
Complete(r)
282281
}
283282

284-
func (u *uniReconciler) updateL4LBIfNeccesarry(l4lbCR *v1alpha1.L4LB, l4lbMeta v1alpha1.L4LBMeta) (ctrl.Result, error) {
283+
func (u *uniReconciler) updateL4LBIfNeccesarry(l4lbCR *k8sv1alpha1.L4LB, l4lbMeta k8sv1alpha1.L4LBMeta) (ctrl.Result, error) {
285284
shouldUpdateCR := false
286285
if l4lbCR.Spec.Frontend.IP != l4lbMeta.Spec.IP {
287286
l4lbCR.Spec.Frontend.IP = l4lbMeta.Spec.IP

0 commit comments

Comments
 (0)