Skip to content

Commit

Permalink
Merge pull request #52 from telekom/fix/party-created-l3s
Browse files Browse the repository at this point in the history
Fix partly created L3VNIs & Reload before Reconcile
  • Loading branch information
schrej committed Sep 12, 2023
2 parents 7e1d958 + cb304f3 commit 38cb9eb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
17 changes: 12 additions & 5 deletions pkg/config/config.go
Expand Up @@ -28,21 +28,28 @@ type VRFConfig struct {
func LoadConfig() (*Config, error) {
config := &Config{}

if err := config.ReloadConfig(); err != nil {
return nil, err
}

return config, nil
}

func (c *Config) ReloadConfig() error {
vniFile := vniMapFile
if val := os.Getenv("OPERATOR_CONFIG"); val != "" {
vniFile = val
}

read, err := os.ReadFile(vniFile)
if err != nil {
return nil, fmt.Errorf("error reading config file: %w", err)
return fmt.Errorf("error reading config file: %w", err)
}
err = yaml.Unmarshal(read, &config)
err = yaml.Unmarshal(read, c)
if err != nil {
return nil, fmt.Errorf("error unmarshalling config file: %w", err)
return fmt.Errorf("error unmarshalling config file: %w", err)
}

return config, nil
return nil
}

func (c *Config) ShouldSkipVRFConfig(vrf string) bool {
Expand Down
7 changes: 1 addition & 6 deletions pkg/frr/configure.go
Expand Up @@ -24,7 +24,6 @@ type templateConfig struct {

Hostname string
UnderlayRouterID string
HostRouterID string
}

func (m *Manager) Configure(in Configuration) (bool, error) {
Expand Down Expand Up @@ -59,10 +58,7 @@ func renderSubtemplates(in Configuration) (*templateConfig, error) {
if err != nil {
return nil, fmt.Errorf("error getting underlay IP: %w", err)
}
hostRouterID, err := (&nl.NetlinkManager{}).GetHostRouterID()
if err != nil {
return nil, fmt.Errorf("error getting host router ID: %w", err)
}

hostname := os.Getenv(healthcheck.NodenameEnv)
if hostname == "" {
return nil, fmt.Errorf("error getting node's name")
Expand Down Expand Up @@ -115,7 +111,6 @@ func renderSubtemplates(in Configuration) (*templateConfig, error) {
PrefixLists: string(prefixlists),
RouteMaps: string(routemaps),
UnderlayRouterID: vrfRouterID.String(),
HostRouterID: hostRouterID.String(),
Hostname: hostname,
}, nil
}
2 changes: 2 additions & 0 deletions pkg/nl/layer3.go
Expand Up @@ -18,6 +18,8 @@ type VRFInformation struct {
table int
bridgeID int
vrfID int

MarkForDelete bool
}

// Create will create a VRF and all interfaces necessary to operate the EVPN and leaking.
Expand Down
25 changes: 10 additions & 15 deletions pkg/nl/list.go
Expand Up @@ -70,32 +70,27 @@ func (n *NetlinkManager) ListL3() ([]VRFInformation, error) {
info.Name = link.Attrs().Name[3:]
info.vrfID = vrf.Attrs().Index

err := n.updateL3Indices(&info)
if err != nil {
return nil, err
}
n.updateL3Indices(&info)

infos = append(infos, info)
}

return infos, nil
}

func (*NetlinkManager) updateL3Indices(info *VRFInformation) error {
func (*NetlinkManager) updateL3Indices(info *VRFInformation) {
bridgeLink, err := netlink.LinkByName(bridgePrefix + info.Name)
if err != nil {
return fmt.Errorf("error getting link by name: %w", err)
if err == nil {
info.bridgeID = bridgeLink.Attrs().Index
} else {
info.MarkForDelete = true
}
vxlanLink, err := netlink.LinkByName(vxlanPrefix + info.Name)
if err != nil {
return fmt.Errorf("error getting link by name: %w", err)
if err == nil {
info.VNI = vxlanLink.(*netlink.Vxlan).VxlanId
} else {
info.MarkForDelete = true
}
netlinkBridge := bridgeLink.(*netlink.Bridge)
netlinkVXLAN := vxlanLink.(*netlink.Vxlan)

info.bridgeID = netlinkBridge.Attrs().Index
info.VNI = netlinkVXLAN.VxlanId
return nil
}

func (*NetlinkManager) updateL2Indices(info *Layer2Information, links []netlink.Link) error {
Expand Down
6 changes: 0 additions & 6 deletions pkg/nl/manager.go
Expand Up @@ -18,7 +18,6 @@ const (
vethL2Prefix = "l2v."

underlayLoopback = "dum.underlay"
nodeLoopback = "br.cluster"

vxlanPort = 4789
defaultMtu = 9000
Expand All @@ -33,8 +32,3 @@ func (*NetlinkManager) GetUnderlayIP() (net.IP, error) {
_, ip, err := getInterfaceAndIP(underlayLoopback)
return ip, err
}

func (*NetlinkManager) GetHostRouterID() (net.IP, error) {
_, ip, err := getInterfaceAndIP(nodeLoopback)
return ip, err
}
4 changes: 2 additions & 2 deletions pkg/reconciler/layer3.go
Expand Up @@ -173,7 +173,7 @@ func (r *reconcile) reconcileL3Netlink(vrfConfigs []frr.VRFConfiguration) ([]nl.
break
}
}
if !stillExists {
if !stillExists || cfg.MarkForDelete {
toDelete = append(toDelete, cfg)
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func prepareVRFsToCreate(vrfConfigs []frr.VRFConfiguration, existing []nl.VRFInf
}
alreadyExists := false
for _, cfg := range existing {
if vrfConfigs[i].Name == cfg.Name && vrfConfigs[i].VNI == cfg.VNI {
if vrfConfigs[i].Name == cfg.Name && vrfConfigs[i].VNI == cfg.VNI && !cfg.MarkForDelete {
alreadyExists = true
break
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/reconciler/reconciler.go
Expand Up @@ -86,6 +86,11 @@ func (reconciler *Reconciler) reconcileDebounced(ctx context.Context) error {
Logger: log.FromContext(ctx),
}

r.Logger.Info("Reloading config")
if err := r.config.ReloadConfig(); err != nil {
return fmt.Errorf("error reloading network-operator config: %w", err)
}

l3vnis, err := r.fetchLayer3(ctx)
if err != nil {
return err
Expand Down

0 comments on commit 38cb9eb

Please sign in to comment.