diff --git a/.golangci.yml b/.golangci.yml index f5746a1..4724b4f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -37,7 +37,7 @@ linters-settings: threshold: 150 funlen: Lines: 175 - Statements: 90 + Statements: 100 goconst: min-len: 2 min-occurrences: 2 diff --git a/internal/pkg/imports/imports_linux.go b/internal/pkg/imports/imports_linux.go index 1c9204c..2b6974d 100644 --- a/internal/pkg/imports/imports_linux.go +++ b/internal/pkg/imports/imports_linux.go @@ -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" diff --git a/main.go b/main.go index 33e79e1..9aaacda 100644 --- a/main.go +++ b/main.go @@ -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" @@ -111,21 +110,30 @@ type Config struct { PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` } -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 @@ -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(),