Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tie up the API with the FRR configuration mechanism #4

Merged
merged 11 commits into from
Jun 28, 2023

Conversation

fedepaol
Copy link
Member

Here we recycle a good amount of what was done in MetalLB, wiring up the frr-k8s configuration with the intermediate one required to render the configuration.
We also add a basic command to spin up an external FRR and configure it.

}

var (
Namespace = "metallb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: frr-k8s?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 14 to 27
SessionUp = metric{
Name: "session_up",
Help: "BGP session state (1 is up, 0 is down)",
}

UpdatesSent = metric{
Name: "updates_total",
Help: "Number of BGP UPDATE messages sent",
}

Prefixes = metric{
Name: "announced_prefixes_total",
Help: "Number of prefixes currently being advertised on the BGP session",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be closer to the exporter or we're treating this package as the one containing all of the different metrics? if it's an option I think it makes more sense to separate the metrics the exporter is in charge of vs. the ones that actually relate to the "frr-k8s" controller (which we don't have any at this point?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, I copied from metallb but here we don't have the legacy bgp, so these can be moved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

internal/frr/api_to_config.go Outdated Show resolved Hide resolved
internal/frr/api_to_config.go Outdated Show resolved Hide resolved
internal/frr/config.go Outdated Show resolved Hide resolved
cmd/main.go Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
Comment on lines 31 to 34
if ip.To4() != nil {
return IPv4, nil
}
return IPv6, nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can call ForAddress here.

Comment on lines 13 to 17
type Family string

func (f Family) String() string {
return string(f)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use type alias here instead (type Family = string)
and remove the String() func.


var (
sessionUpDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, Subsystem, SessionUp.Name),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we missing here the Namespace const definition and SessiopUp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I moved the file but forgot to commit it. Let me fix

Comment on lines 10 to 28
var (
Namespace = "frr-k8s"
Subsystem = "bgp"

SessionUp = metric{
Name: "session_up",
Help: "BGP session state (1 is up, 0 is down)",
}

UpdatesSent = metric{
Name: "updates_total",
Help: "Number of BGP UPDATE messages sent",
}

Prefixes = metric{
Name: "announced_prefixes_total",
Help: "Number of prefixes currently being advertised on the BGP session",
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still use those variables

@fedepaol fedepaol force-pushed the withfrr branch 9 times, most recently from 6007f37 to 5f0394c Compare June 26, 2023 14:27
Copy link

@liornoy liornoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found some nits in function comments, error logs, etc.
all the rest looks good

delete(expected, d)
}
if len(expected) > 0 {
logger.Log("daemons not running. got: ", res, "missing: ", res)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this log, we want to have the expected map's keys after the "missing"

empty := frrk8sv1beta1.FRRConfiguration{}
config, err := apiToFRR(empty)
if err != nil {
level.Error(r.Logger).Log("controller", "FRRConfigurationReconciler", "failed to translate the empty config", req.NamespacedName.String())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this log and the ones below are not printing the error


lastReloadStatus := strings.Fields(string(bytes))
if len(lastReloadStatus) != 2 {
level.Error(l).Log("op", "reload-validate", "error", err, "cause", "Fields", "bytes", string(bytes))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to re-write this one. err is nil here. it's more of an invalid format error.

internal/frr/parse.go Show resolved Hide resolved
Comment on lines 181 to 182
// parseRoute takes the result of a show bgp neighbor
// and parses the informations related to all the neighbours.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy-paste from the function above

return ForAddresses(ipsStrings...)
}

// ForCIDR returns the address family from a given CIDR.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ForCIDR returns the address family from a given CIDR.
// ForCIDRString returns the address family from a given CIDR string.

family: IPv6,
},
{
desc: "ipv4 and ipv6 addresse",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
desc: "ipv4 and ipv6 addresse",
desc: "ipv4 and ipv6 addresses",

family: IPv6,
},
{
desc: "ipv4 and ipv6 addresse",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
desc: "ipv4 and ipv6 addresse",
desc: "ipv4 and ipv6 addresses",

))

})

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newline

Routers: []*frr.RouterConfig{},
},
))

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newline

Adding various utility packages stolen form metallb

Signed-off-by: Federico Paolinelli <[email protected]>
The FRR module is implemented the same way (copied) as MetalLB. The only
difference is the starting point, which is the frr-k8s api.

We have a translation layer that takes the FRR-K8s config, then
translates it, and then generate the FRR configuration and calls the
reloader script.

Signed-off-by: Federico Paolinelli <[email protected]>
Here we add the same containers we had in MetalLB and we change the
dockerfile accordingly.

Signed-off-by: Federico Paolinelli <[email protected]>
Add a dev-env like script that configures both the external container
and the frr-k8s configuration.

Signed-off-by: Federico Paolinelli <[email protected]>
Signed-off-by: Federico Paolinelli <[email protected]>
This will make easier to test the controller by injecting a mock frr
handler.

Signed-off-by: Federico Paolinelli <[email protected]>
This is meant to test only the controller behaviour, to see if it reacts
correctly to the events. Testing of the conversion of the api should not
depend on the api server.

Signed-off-by: Federico Paolinelli <[email protected]>
Here we unit test the conversion function.

Signed-off-by: Federico Paolinelli <[email protected]>
The flag was not implemented, here we cover with a test and support it.

Signed-off-by: Federico Paolinelli <[email protected]>
@fedepaol
Copy link
Member Author

@liornoy I think I fixed all the suggestions

@liornoy
Copy link

liornoy commented Jun 28, 2023

/lgtm

@fedepaol fedepaol merged commit 874ea25 into metallb:main Jun 28, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants