-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,081 additions
and
262 deletions.
There are no files selected for viewing
This file contains 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,48 @@ | ||
digraph G { | ||
"10.0.0.0/8" -> "10.0.0.0/9"; | ||
"10.0.0.0/9" -> "10.0.0.0/10"; | ||
"10.0.0.0/9" -> "10.64.0.0/10"; | ||
"10.64.0.0/10" -> "10.64.0.0/11"; | ||
"10.64.0.0/11" -> "10.64.0.0/12"; | ||
"10.64.0.0/12" -> "10.64.0.0/13"; | ||
"10.64.0.0/13" -> "10.64.0.0/14"; | ||
"10.64.0.0/13" -> "10.68.0.0/14"; | ||
"10.68.0.0/14" -> "10.68.0.0/15"; | ||
"10.68.0.0/14" -> "10.70.0.0/15"; | ||
"10.70.0.0/15" -> "10.70.0.0/16"; | ||
"10.70.0.0/16" [label="10.70.0.0/16\n10.70.0.0\n10.70.0.1", style=filled, color="#57cc99"]; | ||
"10.70.0.0/15" -> "10.71.0.0/16"; | ||
"10.64.0.0/12" -> "10.72.0.0/13"; | ||
"10.64.0.0/11" -> "10.80.0.0/12"; | ||
"10.80.0.0/12" -> "10.80.0.0/13"; | ||
"10.80.0.0/13" -> "10.80.0.0/14"; | ||
"10.80.0.0/14" -> "10.80.0.0/15"; | ||
"10.80.0.0/15" -> "10.80.0.0/16"; | ||
"10.80.0.0/16" [label="10.80.0.0/16", style=filled, color="#57cc99"]; | ||
"10.80.0.0/15" -> "10.81.0.0/16"; | ||
"10.80.0.0/14" -> "10.82.0.0/15"; | ||
"10.80.0.0/13" -> "10.84.0.0/14"; | ||
"10.80.0.0/12" -> "10.88.0.0/13"; | ||
"10.64.0.0/10" -> "10.96.0.0/11"; | ||
"10.96.0.0/11" -> "10.96.0.0/12"; | ||
"10.96.0.0/12" -> "10.96.0.0/13"; | ||
"10.96.0.0/12" -> "10.104.0.0/13"; | ||
"10.104.0.0/13" -> "10.104.0.0/14"; | ||
"10.104.0.0/13" -> "10.108.0.0/14"; | ||
"10.108.0.0/14" -> "10.108.0.0/15"; | ||
"10.108.0.0/14" -> "10.110.0.0/15"; | ||
"10.110.0.0/15" -> "10.110.0.0/16"; | ||
"10.110.0.0/15" -> "10.111.0.0/16"; | ||
"10.111.0.0/16" [label="10.111.0.0/16", style=filled, color="#57cc99"]; | ||
"10.96.0.0/11" -> "10.112.0.0/12"; | ||
"10.112.0.0/12" -> "10.112.0.0/13"; | ||
"10.112.0.0/13" -> "10.112.0.0/14"; | ||
"10.112.0.0/14" -> "10.112.0.0/15"; | ||
"10.112.0.0/15" -> "10.112.0.0/16"; | ||
"10.112.0.0/16" [label="10.112.0.0/16", style=filled, color="#57cc99"]; | ||
"10.112.0.0/15" -> "10.113.0.0/16"; | ||
"10.112.0.0/14" -> "10.114.0.0/15"; | ||
"10.112.0.0/13" -> "10.116.0.0/14"; | ||
"10.112.0.0/12" -> "10.120.0.0/13"; | ||
"10.0.0.0/8" -> "10.128.0.0/9"; | ||
} |
This file contains 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,2 @@ | ||
digraph G { | ||
} |
This file contains 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 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 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 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,63 @@ | ||
digraph G { | ||
"10.0.0.0/8" -> "10.0.0.0/9"; | ||
"10.0.0.0/9" -> "10.0.0.0/10"; | ||
"10.0.0.0/9" -> "10.64.0.0/10"; | ||
"10.64.0.0/10" -> "10.64.0.0/11"; | ||
"10.64.0.0/11" -> "10.64.0.0/12"; | ||
"10.64.0.0/12" -> "10.64.0.0/13"; | ||
"10.64.0.0/13" -> "10.64.0.0/14"; | ||
"10.64.0.0/13" -> "10.68.0.0/14"; | ||
"10.68.0.0/14" -> "10.68.0.0/15"; | ||
"10.68.0.0/14" -> "10.70.0.0/15"; | ||
"10.70.0.0/15" -> "10.70.0.0/16"; | ||
"10.70.0.0/16" [label="10.70.0.0/16\n10.70.0.1\n10.70.0.0\n10.70.0.2", style=filled, color="#57cc99"]; | ||
"10.70.0.0/15" -> "10.71.0.0/16"; | ||
"10.64.0.0/12" -> "10.72.0.0/13"; | ||
"10.64.0.0/11" -> "10.80.0.0/12"; | ||
"10.80.0.0/12" -> "10.80.0.0/13"; | ||
"10.80.0.0/13" -> "10.80.0.0/14"; | ||
"10.80.0.0/14" -> "10.80.0.0/15"; | ||
"10.80.0.0/15" -> "10.80.0.0/16"; | ||
"10.80.0.0/16" [label="10.80.0.0/16", style=filled, color="#57cc99"]; | ||
"10.80.0.0/15" -> "10.81.0.0/16"; | ||
"10.80.0.0/14" -> "10.82.0.0/15"; | ||
"10.80.0.0/13" -> "10.84.0.0/14"; | ||
"10.80.0.0/12" -> "10.88.0.0/13"; | ||
"10.64.0.0/10" -> "10.96.0.0/11"; | ||
"10.96.0.0/11" -> "10.96.0.0/12"; | ||
"10.96.0.0/12" -> "10.96.0.0/13"; | ||
"10.96.0.0/12" -> "10.104.0.0/13"; | ||
"10.104.0.0/13" -> "10.104.0.0/14"; | ||
"10.104.0.0/13" -> "10.108.0.0/14"; | ||
"10.108.0.0/14" -> "10.108.0.0/15"; | ||
"10.108.0.0/14" -> "10.110.0.0/15"; | ||
"10.110.0.0/15" -> "10.110.0.0/16"; | ||
"10.110.0.0/15" -> "10.111.0.0/16"; | ||
"10.111.0.0/16" [label="10.111.0.0/16", style=filled, color="#57cc99"]; | ||
"10.96.0.0/11" -> "10.112.0.0/12"; | ||
"10.112.0.0/12" -> "10.112.0.0/13"; | ||
"10.112.0.0/13" -> "10.112.0.0/14"; | ||
"10.112.0.0/14" -> "10.112.0.0/15"; | ||
"10.112.0.0/15" -> "10.112.0.0/16"; | ||
"10.112.0.0/16" [label="10.112.0.0/16", style=filled, color="#57cc99"]; | ||
"10.112.0.0/15" -> "10.113.0.0/16"; | ||
"10.112.0.0/14" -> "10.114.0.0/15"; | ||
"10.112.0.0/13" -> "10.116.0.0/14"; | ||
"10.112.0.0/12" -> "10.120.0.0/13"; | ||
"10.0.0.0/8" -> "10.128.0.0/9"; | ||
"10.128.0.0/9" -> "10.128.0.0/10"; | ||
"10.128.0.0/10" -> "10.128.0.0/11"; | ||
"10.128.0.0/11" -> "10.128.0.0/12"; | ||
"10.128.0.0/12" -> "10.128.0.0/13"; | ||
"10.128.0.0/13" -> "10.128.0.0/14"; | ||
"10.128.0.0/13" -> "10.132.0.0/14"; | ||
"10.132.0.0/14" -> "10.132.0.0/15"; | ||
"10.132.0.0/15" -> "10.132.0.0/16"; | ||
"10.132.0.0/16" [label="10.132.0.0/16", style=filled, color="#57cc99"]; | ||
"10.132.0.0/15" -> "10.133.0.0/16"; | ||
"10.132.0.0/14" -> "10.134.0.0/15"; | ||
"10.128.0.0/12" -> "10.136.0.0/13"; | ||
"10.128.0.0/11" -> "10.144.0.0/12"; | ||
"10.128.0.0/10" -> "10.160.0.0/11"; | ||
"10.128.0.0/9" -> "10.192.0.0/10"; | ||
} |
This file contains 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,2 @@ | ||
digraph G { | ||
} |
This file contains 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,150 @@ | ||
// Copyright 2019-2024 The Liqo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/pflag" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
"google.golang.org/grpc/health/grpc_health_v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
"github.com/liqotech/liqo/pkg/consts" | ||
"github.com/liqotech/liqo/pkg/ipam" | ||
"github.com/liqotech/liqo/pkg/utils/restcfg" | ||
) | ||
|
||
func flags(options *ipam.Options) { | ||
pflag.IntVar(&options.ServerOpts.Port, "port", consts.IpamPort, "The port on which to listen for incoming gRPC requests.") | ||
pflag.DurationVar(&options.ServerOpts.SyncFrequency, "interval", consts.SyncFrequency, | ||
"The interval at which the IPAM will synchronize the IPAM storage.") | ||
|
||
// Leader election flags. | ||
pflag.BoolVar(&options.EnableLeaderElection, "leader-election", false, "Enable leader election for IPAM. "+ | ||
"Enabling this will ensure there is only one active IPAM.") | ||
pflag.StringVar(&options.LeaderElectionNamespace, "leader-election-namespace", consts.DefaultLiqoNamespace, | ||
"The namespace in which the leader election lease will be created.") | ||
pflag.StringVar(&options.LeaderElectionName, "leader-election-name", "liqo-ipam-leaderelection", | ||
"The name of the leader election lease.") | ||
pflag.DurationVar(&options.LeaseDuration, "lease-duration", 15*time.Second, | ||
"The duration that non-leader candidates will wait to force acquire leadership.") | ||
pflag.DurationVar(&options.RenewDeadline, "renew-deadline", 10*time.Second, | ||
"The duration that the acting IPAM will retry refreshing leadership before giving up.") | ||
pflag.DurationVar(&options.RetryPeriod, "retry-period", 5*time.Second, | ||
"The duration the LeaderElector clients should wait between tries of actions.") | ||
pflag.StringVar(&options.PodName, "pod-name", "", | ||
"The name of the pod running the IPAM service.") | ||
pflag.Parse() | ||
} | ||
|
||
func startServer(ctx context.Context, options *ipam.Options) { | ||
scheme := runtime.NewScheme() | ||
|
||
// Set controller-runtime logger. | ||
log.SetLogger(klog.NewKlogr()) | ||
|
||
// Get the rest config. | ||
cfg := restcfg.SetRateLimiter(ctrl.GetConfigOrDie()) | ||
|
||
// Get the client. | ||
cl, err := client.New(cfg, client.Options{ | ||
Scheme: scheme, | ||
}) | ||
if err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
liqoIPAM, err := ipam.New(ctx, cl, []string{ | ||
"10.0.0.0/8", "192.168.0.0/16", | ||
}, &options.ServerOpts) | ||
if err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", options.ServerOpts.Port)) | ||
if err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
server := grpc.NewServer() | ||
|
||
// Register health service | ||
grpc_health_v1.RegisterHealthServer(server, liqoIPAM.HealthServer) | ||
|
||
// Register IPAM service | ||
ipam.RegisterIPAMServer(server, liqoIPAM) | ||
|
||
klog.Infof("starting the IPAM server") | ||
go func() { | ||
if err := server.Serve(lis); err != nil { | ||
klog.Errorf("failed to serve: %v", err) | ||
os.Exit(1) | ||
} | ||
}() | ||
} | ||
|
||
func main() { | ||
ctx := context.Background() | ||
var options ipam.Options | ||
|
||
flags(&options) | ||
|
||
startServer(ctx, &options) | ||
|
||
time.Sleep(2 * time.Second) | ||
|
||
klog.Infof("connecting to the IPAM server") | ||
conn, err := grpc.NewClient("localhost:6000", grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
klog.Errorf("failed to establish a connection to the IPAM") | ||
os.Exit(1) | ||
} | ||
defer conn.Close() | ||
cl := ipam.NewIPAMClient(conn) | ||
|
||
resultnet, err := cl.NetworkAcquire(ctx, &ipam.NetworkAcquireRequest{ | ||
Immutable: true, | ||
Cidr: "10.0.0.0/24", | ||
}) | ||
if err != nil { | ||
klog.Errorf("failed to acquire the network: %v", err) | ||
os.Exit(1) | ||
} | ||
klog.Infof("acquired network: %v", resultnet.Cidr) | ||
|
||
resultip, err := cl.IPAcquire(ctx, &ipam.IPAcquireRequest{ | ||
Cidr: "10.0.0.0/24", | ||
}) | ||
|
||
if err != nil { | ||
klog.Errorf("failed to acquire the IP: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
klog.Infof("acquired IP: %v", resultip.Ip) | ||
} |
This file contains 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,16 @@ | ||
// Copyright 2019-2024 The Liqo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package ipamcore provides the core functionality for the IPAM service. | ||
package ipamcore |
Oops, something went wrong.