Skip to content

Commit

Permalink
ipam, vendor: move github.com/cilium/ipam packages to main repo
Browse files Browse the repository at this point in the history
Instead of keeping a separate repo for these packages move them to the
main cilium repo which makes this easier to maintain and iterate on.

The code was originally forked from
k8s.io/kubernetes/pkg/registry/core/service and has since been extended
and changed to fit Cilium's needs.

This is a copy of the github.com/cilium/ipam repo at commit
cilium/ipam@fd66eae
This corresponds to the version that is currently vendored.
Additionally, the test files are copied and unnecessry BUILD files
(stemming from upstream k8s) were removed. Some modifications to the
lock and rand types used within the packages needed to be made:

 * Use mutex types from pkg/lock for deadlock detection
 * Use pkg/rand for concurrency safe PRNG
 * Change the license/copyright format in file headers to conform to Cilium
   project requirements.

Otherwise linters would complain about the use of the Go stdlib types.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
  • Loading branch information
tklauser committed May 12, 2023
1 parent 5a3ad8d commit 60a769e
Show file tree
Hide file tree
Showing 25 changed files with 873 additions and 425 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/cilium/customvet v0.0.0-20221207181232-aa8731fa2d27
github.com/cilium/deepequal-gen v0.0.0-20230330134849-754271daeec2
github.com/cilium/ebpf v0.10.0
github.com/cilium/ipam v0.0.0-20230509084518-fd66eae7909b
github.com/cilium/kafka v0.0.0-20180809090225-01ce283b732b
github.com/cilium/lumberjack/v2 v2.3.0
github.com/cilium/proxy v0.0.0-20230420184820-797bea843de1
Expand Down
2 changes: 0 additions & 2 deletions go.sum

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

2 changes: 1 addition & 1 deletion operator/cmd/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"testing"
"time"

"github.com/cilium/ipam/cidrset"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/cilium/cilium/pkg/ipam/allocator/clusterpool/cidralloc"
"github.com/cilium/cilium/pkg/ipam/allocator/podcidr"
"github.com/cilium/cilium/pkg/ipam/cidrset"
"github.com/cilium/cilium/pkg/ipam/types"
cilium_api_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/lbipam/lbipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"
"time"

"github.com/cilium/ipam/service/ipallocator"
"github.com/sirupsen/logrus"
"go.uber.org/multierr"
"golang.org/x/exp/slices"
Expand All @@ -24,6 +23,7 @@ import (

"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/job"
"github.com/cilium/cilium/pkg/ipam/service/ipallocator"
"github.com/cilium/cilium/pkg/k8s"
cilium_api_v2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
cilium_client_v2alpha1 "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1"
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/lbipam/range_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"fmt"
"net"

"github.com/cilium/ipam/service/ipallocator"
"golang.org/x/exp/slices"

"github.com/cilium/cilium/pkg/ipam/service/ipallocator"
cilium_api_v2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/alibabacloud/api/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"fmt"
"net"

"github.com/cilium/ipam/service/ipallocator"
"github.com/google/uuid"

eniTypes "github.com/cilium/cilium/pkg/alibabacloud/eni/types"
"github.com/cilium/cilium/pkg/alibabacloud/types"
"github.com/cilium/cilium/pkg/ipam/service/ipallocator"
ipamTypes "github.com/cilium/cilium/pkg/ipam/types"
"github.com/cilium/cilium/pkg/lock"
)
Expand Down
5 changes: 2 additions & 3 deletions pkg/aws/ec2/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import (
"net"
"time"

"github.com/cilium/ipam/cidrset"
"github.com/cilium/ipam/service/ipallocator"

"github.com/cilium/cilium/pkg/api/helpers"
eniTypes "github.com/cilium/cilium/pkg/aws/eni/types"
"github.com/cilium/cilium/pkg/aws/types"
"github.com/cilium/cilium/pkg/ip"
"github.com/cilium/cilium/pkg/ipam/cidrset"
"github.com/cilium/cilium/pkg/ipam/option"
"github.com/cilium/cilium/pkg/ipam/service/ipallocator"
ipamTypes "github.com/cilium/cilium/pkg/ipam/types"
"github.com/cilium/cilium/pkg/lock"

Expand Down
2 changes: 1 addition & 1 deletion pkg/aws/ec2/mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"net"
"testing"

"github.com/cilium/ipam/cidrset"
"gopkg.in/check.v1"

"github.com/cilium/cilium/pkg/aws/types"
"github.com/cilium/cilium/pkg/checker"
"github.com/cilium/cilium/pkg/ip"
"github.com/cilium/cilium/pkg/ipam/cidrset"
ipamTypes "github.com/cilium/cilium/pkg/ipam/types"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/azure/api/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"net"
"time"

"github.com/cilium/ipam/service/ipallocator"
"golang.org/x/time/rate"

"github.com/cilium/cilium/pkg/api/helpers"
"github.com/cilium/cilium/pkg/azure/types"
"github.com/cilium/cilium/pkg/ipam/service/ipallocator"
ipamTypes "github.com/cilium/cilium/pkg/ipam/types"
"github.com/cilium/cilium/pkg/lock"
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/ipam/allocator/clusterpool/cidralloc/cidralloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"fmt"
"net"

"github.com/cilium/ipam/cidrset"

"github.com/cilium/cilium/pkg/ip"
"github.com/cilium/cilium/pkg/ipam/cidrset"
)

type CIDRAllocator interface {
Expand Down
3 changes: 1 addition & 2 deletions pkg/ipam/allocator/pool_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"fmt"
"net"

"github.com/cilium/ipam/service/ipallocator"

"github.com/cilium/cilium/pkg/cidr"
"github.com/cilium/cilium/pkg/ipam/service/ipallocator"
"github.com/cilium/cilium/pkg/ipam/types"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
/*
Copyright 2020 Authors of Cilium.
Copyright 2016 The Kubernetes 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.
*/
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
// Copyright The Kubernetes Authors.

package cidrset

Expand All @@ -24,13 +11,14 @@ import (
"math/big"
"math/bits"
"net"
"sync"

"github.com/cilium/cilium/pkg/lock"
)

// CidrSet manages a set of CIDR ranges from which blocks of IPs can
// be allocated from.
type CidrSet struct {
sync.Mutex
lock.Mutex
// clusterCIDR is the CIDR assigned to the cluster
clusterCIDR *net.IPNet
// clusterMaskSize is the mask size, in bits, assigned to the cluster
Expand Down

0 comments on commit 60a769e

Please sign in to comment.