-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Static Route Controller #435
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
Open
sven-rosenzweig
wants to merge
2
commits into
main
Choose a base branch
from
feat/static_routes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and IronCore contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "sync" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| ) | ||
|
|
||
| // StaticRouteSpec defines the desired state of StaticRoute | ||
| // Static routes are used to define explicit paths for network traffic. They can be categorized into different types based on their characteristics and use cases: | ||
| // Directly Connected Routes: Only output interfaces are specified, and the next hop is directly reachable through those interfaces. | ||
| // Recursive Static Routes: In a recursive static route, only the next hop is specified. The output interface is derived from the next hop. | ||
| // Fully Specified Static Routes: Specifies both the output interfaces and the next hop, providing a complete path for the traffic. | ||
| // Floating Static Routes: These routes have a higher administrative distance than dynamic routes, allowing them to serve as backup routes that are only used when the primary route is unavailable. | ||
| type StaticRouteSpec struct { | ||
| // DeviceName is the name of the Device this object belongs to. The Device object must exist in the same namespace. | ||
| // Immutable. | ||
| // +required | ||
| // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="DeviceRef is immutable" | ||
| DeviceRef LocalObjectReference `json:"deviceRef"` | ||
|
|
||
| // ProviderConfigRef is a reference to a resource holding the provider-specific configuration of this interface. | ||
| // This reference is used to link the Interface to its provider-specific configuration. | ||
| // +optional | ||
| ProviderConfigRef *TypedLocalObjectReference `json:"providerConfigRef,omitempty"` | ||
|
|
||
| // Name is the name of the static route. | ||
| // +required | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=255 | ||
| // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Name is immutable" | ||
| Name string `json:"name"` | ||
|
|
||
| // Description is an optional human-readable description for this static route. | ||
| // +optional | ||
| // +kubebuilder:validation:MaxLength=255 | ||
| Description string `json:"description,omitempty"` | ||
|
|
||
| // VrfRef is a reference to the VRF resource that this static route belongs to. | ||
| // If not specified, the static route will be part of the default VRF. | ||
| // The referenced VRF must exist in the same namespace. | ||
| // +optional | ||
| VrfRef *LocalObjectReference `json:"vrfRef,omitempty"` | ||
|
|
||
| // IPPrefix is the destination IP prefix for the static route. | ||
| // +required | ||
| Prefix IPPrefix `json:"prefix"` | ||
|
|
||
| // +required | ||
| // +kubebuilder:validation:MinItems=1 | ||
| NextHops []*NextHop `json:"nextHops,omitempty"` | ||
| } | ||
|
|
||
| type NextHop struct { | ||
| // TODO(sven-rosenzweig): It is possible to point an a static route in a VRF to an Interface. For now this is not needed. | ||
| // InterfaceRef is a reference to the Interface resource that this static route is associated with. | ||
| // The referenced Interface must exist in the same namespace. | ||
| // +optional | ||
| // InterfaceRef *LocalObjectReference `json:"interfaceRef,omitempty"` | ||
|
|
||
| // Address is the IP address of the next hop for the static route. | ||
| // +required | ||
| Address string `json:"address,omitempty"` | ||
|
|
||
| // Metric assigns a priority to the static route. Lower values indicate higher priority. | ||
| // +optional | ||
| Metric *int32 `json:"metric,omitempty"` | ||
| } | ||
|
|
||
| // StaticRouteStatus defines the observed state of StaticRoute. | ||
| type StaticRouteStatus struct { | ||
| // The conditions are a list of status objects that describe the state of the StaticRoute. | ||
| // +listType=map | ||
| // +listMapKey=type | ||
| // +patchStrategy=merge | ||
| // +patchMergeKey=type | ||
| // +optional | ||
| Conditions []metav1.Condition `json:"conditions,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:printcolumn:name="Device",type=string,JSONPath=`.spec.deviceRef.name` | ||
| // +kubebuilder:printcolumn:name="VRF",type=string,JSONPath=`.spec.vrfRef.name` | ||
| // +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` | ||
| // +kubebuilder:printcolumn:name="Paused",type=string,JSONPath=`.status.conditions[?(@.type=="Paused")].status`,priority=1 | ||
| // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" | ||
|
|
||
| // StaticRoute is the Schema for the staticroutes API | ||
| type StaticRoute struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
|
|
||
| // metadata is a standard object metadata | ||
| // +optional | ||
| metav1.ObjectMeta `json:"metadata,omitzero"` | ||
|
|
||
| // spec defines the desired state of StaticRoute | ||
| // +required | ||
| Spec StaticRouteSpec `json:"spec"` | ||
|
|
||
| // status defines the observed state of StaticRoute | ||
| // +optional | ||
| Status StaticRouteStatus `json:"status,omitzero"` | ||
| } | ||
|
|
||
| // GetConditions implements conditions.Getter. | ||
| func (sr *StaticRoute) GetConditions() []metav1.Condition { | ||
| return sr.Status.Conditions | ||
| } | ||
|
|
||
| // SetConditions implements conditions.Setter. | ||
| func (sr *StaticRoute) SetConditions(conditions []metav1.Condition) { | ||
| sr.Status.Conditions = conditions | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // StaticRouteList contains a list of StaticRoute | ||
| type StaticRouteList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitzero"` | ||
| Items []StaticRoute `json:"items"` | ||
| } | ||
|
|
||
| var ( | ||
| StaticRouteDependencies []schema.GroupVersionKind | ||
| staticRouteDependenciesMu sync.Mutex | ||
| ) | ||
|
|
||
| func RegisterStaticRouteDependency(gvk schema.GroupVersionKind) { | ||
| staticRouteDependenciesMu.Lock() | ||
| defer staticRouteDependenciesMu.Unlock() | ||
| StaticRouteDependencies = append(StaticRouteDependencies, gvk) | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(func(s *runtime.Scheme) error { | ||
| s.AddKnownTypes(GroupVersion, &StaticRoute{}, &StaticRouteList{}) | ||
| return nil | ||
| }) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have a very brief comment, as all other fields.