feat: Static Route Controller - #435
Conversation
58dcad3 to
af25860
Compare
9a2e31b to
8545345
Compare
71deb30 to
b3977eb
Compare
Implement IOS-XR provider. Signed-off-by: Sven Rosenzweig <sven.rosenzweig@sap.com>
b3977eb to
4f36714
Compare
Merging this branch changes the coverage (1 decrease, 1 increase)
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
|
|
||
| // StaticRouteLabel is a label applied to VRFs to indicate | ||
| // the name of the StaticRoute that references them. | ||
| const StaticRouteLabel = "networking.metal.ironcore.dev/static-route-name" |
There was a problem hiding this comment.
How will this work when there are multiple StaticRoutes in a VRF? Based on the way we structure the StaticRoute CRD this would be possible, no?
| // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Name is immutable" | ||
| Name string `json:"name"` | ||
|
|
||
| // +optional |
There was a problem hiding this comment.
Should have a very brief comment, as all other fields.
|
|
||
| // StaticRouteStatus defines the observed state of StaticRoute. | ||
| type StaticRouteStatus struct { | ||
| // The conditions are a list of status objects that describe the state of the Interface. |
There was a problem hiding this comment.
| // The conditions are a list of status objects that describe the state of the Interface. | |
| // The conditions are a list of status objects that describe the state of the StaticRoute. |
copy+pasta
|
|
||
| // IPPrefix is the destination IP prefix for the static route. | ||
| // +required | ||
| Prefix IPPrefix `json:"prefix,omitempty"` |
There was a problem hiding this comment.
| Prefix IPPrefix `json:"prefix,omitempty"` | |
| Prefix IPPrefix `json:"prefix"` |
omitempty is unused if the field is required. Also applies to the NextHops.
| name: networking-staticroute-admin-role | ||
| rules: | ||
| - apiGroups: | ||
| - networking.networking.metal.ironcore.dev |
There was a problem hiding this comment.
| - networking.networking.metal.ironcore.dev | |
| - networking.metal.ironcore.dev |
This is wrong. Probably a grep over the codebase reveals other places that are also effected.
| if req.VRF != nil && req.VRF.Spec.Name != "" { | ||
| vrf := req.VRF.Spec.Name | ||
| prefix.VRFName = vrf | ||
| return p.client.Update(ctx, &prefix) | ||
| } | ||
| return p.client.Update(ctx, &prefix) |
There was a problem hiding this comment.
| if req.VRF != nil && req.VRF.Spec.Name != "" { | |
| vrf := req.VRF.Spec.Name | |
| prefix.VRFName = vrf | |
| return p.client.Update(ctx, &prefix) | |
| } | |
| return p.client.Update(ctx, &prefix) | |
| if req.VRF != nil && req.VRF.Spec.Name != "" { | |
| prefix.VRFName = req.VRF.Spec.Name | |
| } | |
| return p.client.Update(ctx, &prefix) |
Doesn't need to make it so complicated.
| if prefixIP.Addr().Is4() { | ||
| prefix = Prefix{ | ||
| PrefixAddress: prefixIP.Addr().String(), | ||
| PrefixLength: prefixIP.Bits(), | ||
| NextHopAddress: &nexthopAddress, | ||
| IsIpv4: true, | ||
| } | ||
| } else if prefixIP.Addr().Is6() { | ||
| prefix = Prefix{ | ||
| PrefixAddress: prefixIP.Addr().String(), | ||
| PrefixLength: prefixIP.Bits(), | ||
| NextHopAddress: &nexthopAddress, | ||
| IsIpv4: false, | ||
| } | ||
| } |
There was a problem hiding this comment.
| if prefixIP.Addr().Is4() { | |
| prefix = Prefix{ | |
| PrefixAddress: prefixIP.Addr().String(), | |
| PrefixLength: prefixIP.Bits(), | |
| NextHopAddress: &nexthopAddress, | |
| IsIpv4: true, | |
| } | |
| } else if prefixIP.Addr().Is6() { | |
| prefix = Prefix{ | |
| PrefixAddress: prefixIP.Addr().String(), | |
| PrefixLength: prefixIP.Bits(), | |
| NextHopAddress: &nexthopAddress, | |
| IsIpv4: false, | |
| } | |
| } | |
| prefix = Prefix{ | |
| PrefixAddress: prefixIP.Addr().String(), | |
| PrefixLength: prefixIP.Bits(), | |
| NextHopAddress: &nexthopAddress, | |
| IsIpv4: prefixIP.Addr().Is4(), | |
| } |
| basePath := "Cisco-IOS-XR-um-router-static-cfg:router/static/vrfs/vrf[vrf-name=" + s.VRFName + "]/address-family/" | ||
| if s.VRFName == "" { | ||
| basePath = "Cisco-IOS-XR-um-router-static-cfg:router/static/address-family/" | ||
| } |
There was a problem hiding this comment.
| basePath := "Cisco-IOS-XR-um-router-static-cfg:router/static/vrfs/vrf[vrf-name=" + s.VRFName + "]/address-family/" | |
| if s.VRFName == "" { | |
| basePath = "Cisco-IOS-XR-um-router-static-cfg:router/static/address-family/" | |
| } | |
| basePath := "Cisco-IOS-XR-um-router-static-cfg:router/static/address-family/" | |
| if s.VRFName != "" { | |
| basePath = "Cisco-IOS-XR-um-router-static-cfg:router/static/vrfs/vrf[vrf-name=" + s.VRFName + "]/address-family/" | |
| } |
nit: the other way around feels more logical to me.
| } | ||
|
|
||
| func (p *Provider) EnsureStaticRoute(ctx context.Context, req *provider.StaticRouteRequest) error { | ||
| // TODO(sven-rosenzweig): implement static route configuration |
There was a problem hiding this comment.
Is there an open Ticket for this? Otherwise I think leaving these methods out would be better, as the controller already checks if the provider implements this interface (which it now does, because it has these methods). Not having these functions means the controller sees that the provider doesn't implement the contract and correctly updates the kubernetes resource status.
| crdVersion: v1 | ||
| namespaced: true | ||
| domain: networking.metal.ironcore.dev | ||
| group: core |
There was a problem hiding this comment.
| group: core |
not correct.
| Watches( | ||
| &v1alpha1.VRF{}, | ||
| handler.EnqueueRequestsFromMapFunc(r.vrfToStaticRoute), | ||
| builder.WithPredicates(predicate.Funcs{ |
There was a problem hiding this comment.
I don't think we want to trigger reconcilation on updates to the vrf, as we are basically only interested in the .spec.name and that is immutable. So I would expect that we have a
UpdateFunc: func(e event.UpdateEvent) bool {
return false
},| ready := false | ||
| for _, cond := range resource.Status.Conditions { | ||
| if cond.Type == v1alpha1.ReadyCondition { | ||
| ready = true | ||
| g.Expect(cond.Status).To(Equal(metav1.ConditionFalse)) | ||
| } | ||
| } | ||
| g.Expect(ready).To(BeTrue(), "ReadyCondition should be present") |
There was a problem hiding this comment.
I would prefer to adhere to the same pattern for condition checks as in the other controller tests (e.g. to use the metav1.FindStatusCondition).
Implement IOS-XR provider.