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

Handled IPAM policy properly to fully support strict IPAM #619

Merged
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ linters-settings:
threshold: 150
funlen:
Lines: 175
Statements: 90
Statements: 100
goconst:
min-len: 2
min-occurrences: 2
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/policyroute"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/ipam/groupipam"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/ipam/strictipam"
_ "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
Expand Down
22 changes: 15 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/policyroute"
"github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/groupipam"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/strictipam"
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
registryauthorize "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
Expand Down Expand Up @@ -111,21 +110,30 @@ type Config struct {
PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"`
}

Copy link
Member

@denis-tingaikin denis-tingaikin Oct 16, 2024

Choose a reason for hiding this comment

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

Suggested change
type newIPAMFunc func(...*net.IPNet) networkservice.NetworkServiceServer
// Decode takes a string IPAM Policy and returns the IPAM Policy func
func (f *newIPAMFunc) Decode(policy string) error {
switch config.IPAMPolicy {
case "strict":
*f = func(cidrPrefix [][]*net.IPNet) {
var ipnetList []*net.IPNet
for _, group := range cidrPrefix {
ipnetList = append(ipnetList, group...)
}
return strictipam.NewServer(func(i ...*net.IPNet) networkservice.NetworkServiceServer {
return groupipam.NewServer(cidrPrefix)
}, ipnetList...)
case "polite":
*f = func(cidrPrefix [][]*net.IPNet) {
return groupipam.NewServer(cidrPrefix)
}
default:
logrus.Fatalf("not a valid IPAM Policy: %s", config.IPAMPolicy)
}
}

Copy link
Author

Choose a reason for hiding this comment

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

Done

type ipamPolicyFunc func(...*net.IPNet) networkservice.NetworkServiceServer
type ipamPolicyFunc func([][]*net.IPNet) networkservice.NetworkServiceServer

// Decode takes a string IPAM Policy and returns the IPAM Policy func
func (f *ipamPolicyFunc) Decode(policy string) error {
switch strings.ToLower(policy) {
case "strict":
*f = func(prefixes ...*net.IPNet) networkservice.NetworkServiceServer {
return strictipam.NewServer(point2pointipam.NewServer, prefixes...)
*f = func(cidrPrefix [][]*net.IPNet) networkservice.NetworkServiceServer {
var ipnetList []*net.IPNet
for _, group := range cidrPrefix {
ipnetList = append(ipnetList, group...)
}
return strictipam.NewServer(func(i ...*net.IPNet) networkservice.NetworkServiceServer {
return groupipam.NewServer(cidrPrefix)
}, ipnetList...)
}
return nil
case "polite":
*f = point2pointipam.NewServer
*f = func(cidrPrefix [][]*net.IPNet) networkservice.NetworkServiceServer {
return groupipam.NewServer(cidrPrefix)
}
return nil
default:
return errors.Errorf("not a valid IPAM Policy: %s", policy)
}
return errors.Errorf("not a valid IPAM Policy: %s", policy)
}

// Process prints and processes env to config
Expand Down Expand Up @@ -245,7 +253,7 @@ func main() {
endpoint.WithAuthorizeServer(authorize.NewServer()),
endpoint.WithAdditionalFunctionality(
onidle.NewServer(ctx, cancel, config.IdleTimeout),
groupipam.NewServer(config.CidrPrefix, groupipam.WithCustomIPAMServer(config.IPAMPolicy)),
config.IPAMPolicy(config.CidrPrefix),
policyroute.NewServer(newPolicyRoutesGetter(ctx, config.PBRConfigPath).Get),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernelmech.MECHANISM: kernel.NewServer(),
Expand Down
Loading