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

[IPAM] integration tests #2864

Merged
merged 2 commits into from
Dec 12, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ token

# test generated files
coverage*
*.report

# example kubeconfig generates by examples
liqo_kubeconf*
Expand Down
9 changes: 4 additions & 5 deletions cmd/ipam/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ func main() {
cmd.Flags().DurationVar(&options.ServerOpts.SyncGracePeriod, "sync-graceperiod", consts.SyncGracePeriod,
"The grace period the sync routine wait before releasing an ip or a network.")
cmd.Flags().BoolVar(&options.ServerOpts.GraphvizEnabled, "enable-graphviz", false, "Enable the graphviz output for the IPAM.")
cmd.Flags().StringSliceVar(&options.ServerOpts.Pools, "pools",
[]string{"10.0.0.0/8", "192.168.0.0/16", "172.16.0.0/12"},
"The pools used by the IPAM to acquire Networks and IPs from. Default: private addesses range.",
cmd.Flags().StringSliceVar(&options.ServerOpts.Pools, "pools", consts.PrivateAddressSpace,
"The pools used by the IPAM to acquire Networks and IPs from. Default: private addesses space.",
)

// Leader election flags.
Expand Down Expand Up @@ -145,7 +144,7 @@ func run(cmd *cobra.Command, _ []string) error {
}
}

liqoIPAM, err := ipam.New(ctx, cl, options.ServerOpts.Pools, &options.ServerOpts)
liqoIPAM, err := ipam.New(ctx, cl, &options.ServerOpts)
if err != nil {
return err
}
Expand All @@ -163,7 +162,7 @@ func run(cmd *cobra.Command, _ []string) error {
// Register IPAM service
ipam.RegisterIPAMServer(server, liqoIPAM)

if err := server.Serve(lis); err != nil {
if err := server.Serve(lis); err != nil { // we do not need to close the listener as Serve will close it when returning
klog.Errorf("failed to serve: %v", err)
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/consts/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ const (
// DefaultCIDRValue is the default value for a string that contains a CIDR.
DefaultCIDRValue = "None"
)

var (
// PrivateAddressSpace contains all the ranges for private addresses as defined in RFC1918.
PrivateAddressSpace = []string{"10.0.0.0/8", "192.168.0.0/16", "172.16.0.0/12"}
)
4 changes: 2 additions & 2 deletions pkg/ipam/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (lipam *LiqoIPAM) initialize(ctx context.Context) error {

func (lipam *LiqoIPAM) initializeNetworks(ctx context.Context) error {
// List all networks present in the cluster.
nets, err := lipam.listNetworksOnCluster(ctx, lipam.Client)
nets, err := lipam.listNetworksOnCluster(ctx)
if err != nil {
return err
}
Expand All @@ -67,7 +67,7 @@ func (lipam *LiqoIPAM) initializeNetworks(ctx context.Context) error {

func (lipam *LiqoIPAM) initializeIPs(ctx context.Context) error {
// List all IPs present in the cluster.
ips, err := lipam.listIPsOnCluster(ctx, lipam.Client)
ips, err := lipam.listIPsOnCluster(ctx)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/ipam/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ var _ = Describe("Initialize routine tests", func() {
Expect(fakeIpamServer.networkIsAvailable(netip.MustParsePrefix("10.4.0.0/30"))).To(Equal(false))
Expect(fakeIpamServer.networkIsAvailable(netip.MustParsePrefix("10.3.0.0/16"))).To(Equal(false))
Expect(fakeIpamServer.networkIsAvailable(netip.MustParsePrefix("172.16.1.0/24"))).To(Equal(false))
available, err := fakeIpamServer.isIPAvailable(netip.MustParseAddr("10.3.0.0"), netip.MustParsePrefix("10.3.0.0/16"))
available, err := fakeIpamServer.ipIsAvailable(netip.MustParseAddr("10.3.0.0"), netip.MustParsePrefix("10.3.0.0/16"))
Expect(err).To(BeNil())
Expect(available).To(Equal(false))
available, err = fakeIpamServer.isIPAvailable(netip.MustParseAddr("10.3.0.1"), netip.MustParsePrefix("10.3.0.0/16"))
available, err = fakeIpamServer.ipIsAvailable(netip.MustParseAddr("10.3.0.1"), netip.MustParsePrefix("10.3.0.0/16"))
Expect(err).To(BeNil())
Expect(available).To(Equal(true))
available, err = fakeIpamServer.isIPAvailable(netip.MustParseAddr("10.3.0.2"), netip.MustParsePrefix("10.3.0.0/16"))
available, err = fakeIpamServer.ipIsAvailable(netip.MustParseAddr("10.3.0.2"), netip.MustParsePrefix("10.3.0.0/16"))
Expect(err).To(BeNil())
Expect(available).To(Equal(false))

Expand Down
6 changes: 3 additions & 3 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ type ServerOptions struct {
}

// New creates a new instance of the LiqoIPAM.
func New(ctx context.Context, cl client.Client, roots []string, opts *ServerOptions) (*LiqoIPAM, error) {
func New(ctx context.Context, cl client.Client, opts *ServerOptions) (*LiqoIPAM, error) {
hs := health.NewServer()
hs.SetServingStatus(IPAM_ServiceDesc.ServiceName, grpc_health_v1.HealthCheckResponse_NOT_SERVING)

prefixRoots := make([]netip.Prefix, len(roots))
for i, r := range roots {
prefixRoots := make([]netip.Prefix, len(opts.Pools))
for i, r := range opts.Pools {
p, err := netip.ParsePrefix(r)
if err != nil {
return nil, fmt.Errorf("failed to parse pool with prefix %q: %w", r, err)
Expand Down
Loading
Loading