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

Network: gateway routes #2282

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apis/networking/v1alpha1/internalfabric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ type InternalFabricSpecInterfaceNode struct {
Name string `json:"name"`
}

// InternalFabricSpecInterfaceGateway contains the information about the gateway interface.
type InternalFabricSpecInterfaceGateway struct {
// IP is the IP of the interface added to the gateway.
IP IP `json:"ip"`
}

// InternalFabricSpecInterface contains the information about network interfaces.
type InternalFabricSpecInterface struct {
// Node contains the information about the node interface.
// The node interface is created on every node to connect them to the gateway related with the internalfabric.
Node InternalFabricSpecInterfaceNode `json:"node"`
// Gateway contains the information about the gateway interface.
Gateway InternalFabricSpecInterfaceGateway `json:"gateway"`
}

// InternalFabricSpec defines the desired state of InternalFabric.
Expand Down
8 changes: 8 additions & 0 deletions apis/networking/v1alpha1/internalnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ type InternalNodeSpecInterfaceGateway struct {
Name string `json:"name"`
}

// InternalNodeSpecInterfaceNode contains the information about the node interface.
type InternalNodeSpecInterfaceNode struct {
// IP is the IP of the interface added to the node.
IP IP `json:"ip"`
}

// InternalNodeSpecInterface contains the information about network interfaces.
type InternalNodeSpecInterface struct {
// Gateway contains the information about the gateway interface.
// The gateway interface is created on every gateway to connect them to the node related with the internalnode.
Gateway InternalNodeSpecInterfaceGateway `json:"gateway"`
// Node contains the information about the node interface.
Node InternalNodeSpecInterfaceNode `json:"node"`
}

// InternalNodeSpec defines the desired state of InternalNode.
Expand Down
29 changes: 29 additions & 0 deletions apis/networking/v1alpha1/routeconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand All @@ -34,6 +35,22 @@ var RouteConfigurationGroupResource = schema.GroupResource{Group: GroupVersion.G
// RouteConfigurationGroupVersionResource is groupResourceVersion used to register these objects.
var RouteConfigurationGroupVersionResource = GroupVersion.WithResource(RouteConfigurationResource)

// Scope is the scope of the route.
type Scope string

const (
// GlobalScope is the global scope of the RouteConfiguration.
GlobalScope Scope = "global"
// LinkScope is the link scope of the RouteConfiguration.
LinkScope Scope = "link"
// HostScope is the host scope of the RouteConfiguration.
HostScope Scope = "host"
// SiteScope is the site scope of the RouteConfiguration.
SiteScope Scope = "site"
// NowhereScope is the nowhere scope of the RouteConfiguration.
NowhereScope Scope = "nowhere"
)

// Route is the route of the RouteConfiguration.
type Route struct {
// Dst is the destination of the RouteConfiguration.
Expand All @@ -46,6 +63,12 @@ type Route struct {
Dev *string `json:"dev,omitempty"`
// Onlink enables the onlink falg inside the route.
Onlink *bool `json:"onlink,omitempty"`
// Scope is the scope of the RouteConfiguration.
// +kubebuilder:validation:Enum=global;link;host;site;nowhere
Scope *Scope `json:"scope,omitempty"`
// TargetRef is the reference to the target object of the route.
// It is optional and it can be used for custom purposes.
TargetRef *corev1.ObjectReference `json:"targetRef,omitempty"`
}

// Rule is the rule of the RouteConfiguration.
Expand All @@ -61,6 +84,9 @@ type Rule struct {
// Routes is the list of routes of the Rule.
// +kubebuilder:validation:MinItems=1
Routes []Route `json:"routes"`
// TargetRef is the reference to the target object of the rule.
// It is optional and it can be used for custom purposes.
TargetRef *corev1.ObjectReference `json:"targetRef,omitempty"`
}

// Table is the table of the RouteConfiguration.
Expand All @@ -70,6 +96,9 @@ type Table struct {
// Rules is the list of rules of the RouteConfiguration.
// +kubebuilder:validation:MinItems=1
Rules []Rule `json:"rules"`
// TargetRef is the reference to the target object of the table.
// It is optional and it can be used for custom purposes.
TargetRef *corev1.ObjectReference `json:"targetRef,omitempty"`
}

// RouteConfigurationSpec defines the desired state of RouteConfiguration.
Expand Down
52 changes: 52 additions & 0 deletions apis/networking/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/fabric/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func run(cmd *cobra.Command, _ []string) error {
mgr.GetClient(),
mgr.GetScheme(),
mgr.GetEventRecorderFor("route-controller"),
fabric.ForgeRouteTargetLabels(),
[]labels.Set{fabric.ForgeRouteTargetLabels()},
)
if err != nil {
return fmt.Errorf("unable to create route configuration reconciler: %w", err)
Expand Down
22 changes: 4 additions & 18 deletions cmd/gateway/geneve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ import (

networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
"github.com/liqotech/liqo/pkg/gateway"
"github.com/liqotech/liqo/pkg/gateway/fabric"
"github.com/liqotech/liqo/pkg/gateway/fabric/geneve"
"github.com/liqotech/liqo/pkg/route"
flagsutils "github.com/liqotech/liqo/pkg/utils/flags"
"github.com/liqotech/liqo/pkg/utils/mapper"
"github.com/liqotech/liqo/pkg/utils/restcfg"
)

var (
scheme = runtime.NewScheme()
options = geneve.NewOptions(gateway.NewOptions())
options = fabric.NewOptions(gateway.NewOptions())
)

func init() {
Expand All @@ -62,8 +62,8 @@ func main() {
klog.InitFlags(legacyflags)
flagsutils.FromFlagToPflag(legacyflags, cmd.Flags())

geneve.InitFlags(cmd.Flags(), options)
if err := geneve.MarkFlagsRequired(&cmd); err != nil {
fabric.InitFlags(cmd.Flags(), options)
if err := fabric.MarkFlagsRequired(&cmd); err != nil {
klog.Error(err)
os.Exit(1)
}
Expand Down Expand Up @@ -113,20 +113,6 @@ func run(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("unable to create manager: %w", err)
}

rcr, err := route.NewRouteConfigurationReconcilerWithoutFinalizer(
mgr.GetClient(),
mgr.GetScheme(),
mgr.GetEventRecorderFor("routeconfiguration-controller"),
geneve.ForgeRouteTargetLabels(options.GwOptions.Name),
)
if err != nil {
return fmt.Errorf("unable to create routeconfiguration reconciler: %w", err)
}

if err := rcr.SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to setup routeconfiguration reconciler: %w", err)
}

inr, err := geneve.NewInternalNodeReconciler(
mgr.GetClient(),
mgr.GetScheme(),
Expand Down
32 changes: 26 additions & 6 deletions cmd/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (

"github.com/spf13/cobra"
"github.com/vishvananda/netlink"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
Expand All @@ -37,8 +37,11 @@ import (
"github.com/liqotech/liqo/pkg/gateway"
"github.com/liqotech/liqo/pkg/gateway/connection"
"github.com/liqotech/liqo/pkg/gateway/connection/conncheck"
"github.com/liqotech/liqo/pkg/gateway/fabric"
"github.com/liqotech/liqo/pkg/gateway/remapping"
"github.com/liqotech/liqo/pkg/route"
flagsutils "github.com/liqotech/liqo/pkg/utils/flags"
"github.com/liqotech/liqo/pkg/utils/kernel"
"github.com/liqotech/liqo/pkg/utils/mapper"
"github.com/liqotech/liqo/pkg/utils/restcfg"
)
Expand Down Expand Up @@ -98,6 +101,11 @@ func main() {
func run(cmd *cobra.Command, _ []string) error {
var err error

// Enable ip_forwarding.
if err = kernel.EnableIPForwarding(); err != nil {
return err
}

// Set controller-runtime logger.
log.SetLogger(klog.NewKlogr())

Expand All @@ -108,11 +116,6 @@ func run(cmd *cobra.Command, _ []string) error {
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
MapperProvider: mapper.LiqoMapperProvider(scheme),
Scheme: scheme,
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{
connoptions.GwOptions.Namespace: {},
},
},
Metrics: server.Options{
BindAddress: "0", // Metrics are exposed by "connection" container.
},
Expand Down Expand Up @@ -151,6 +154,23 @@ func run(cmd *cobra.Command, _ []string) error {
}
}

rcr, err := route.NewRouteConfigurationReconcilerWithoutFinalizer(
mgr.GetClient(),
mgr.GetScheme(),
mgr.GetEventRecorderFor("routeconfiguration-controller"),
[]labels.Set{
fabric.ForgeRouteExternalTargetLabels(connoptions.GwOptions.RemoteClusterID),
fabric.ForgeRouteInternalTargetLabels(),
},
)
if err != nil {
return fmt.Errorf("unable to create routeconfiguration reconciler: %w", err)
}

if err := rcr.SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to setup routeconfiguration reconciler: %w", err)
}

// Setup the firewall configuration controller.
fwcr, err := firewall.NewFirewallConfigurationReconcilerWithoutFinalizer(
mgr.GetClient(),
Expand Down
Loading
Loading