Skip to content

Commit 06b5846

Browse files
author
Rahul Sharma
committed
use ipv6 range allocated to node to calculate /112 for node ipam
1 parent 1cbbb40 commit 06b5846

File tree

13 files changed

+223
-125
lines changed

13 files changed

+223
-125
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fmt:
8080
.PHONY: test
8181
# we say code is not worth testing unless it's formatted
8282
test: fmt codegen
83-
go test -v -coverpkg=./sentry,./cloud/linode/client,./cloud/linode/firewall,./cloud/linode -coverprofile ./coverage.out -cover ./sentry/... ./cloud/... $(TEST_ARGS)
83+
go test -v -coverpkg=./sentry,./cloud/linode/client,./cloud/linode/firewall,./cloud/linode,.cloud/nodeipam,.cloud/nodeipam/ipam -coverprofile ./coverage.out -cover ./sentry/... ./cloud/... $(TEST_ARGS)
8484

8585
.PHONY: build-linux
8686
build-linux: codegen

cloud/linode/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Client interface {
2626
GetInstance(context.Context, int) (*linodego.Instance, error)
2727
ListInstances(context.Context, *linodego.ListOptions) ([]linodego.Instance, error)
2828
CreateInstance(ctx context.Context, opts linodego.InstanceCreateOptions) (*linodego.Instance, error)
29+
ListInstanceConfigs(ctx context.Context, linodeID int, opts *linodego.ListOptions) ([]linodego.InstanceConfig, error)
2930

3031
GetInstanceIPAddresses(context.Context, int) (*linodego.InstanceIPAddressResponse, error)
3132
AddInstanceIPAddress(ctx context.Context, linodeID int, public bool) (*linodego.InstanceIP, error)

cloud/linode/client/client_with_metrics.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/linode/client/mocks/mock_client.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/linode/cloud_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestNewCloudRouteControllerDisabled(t *testing.T) {
2020
t.Setenv("LINODE_API_TOKEN", "dummyapitoken")
2121
t.Setenv("LINODE_REGION", "us-east")
2222
t.Setenv("LINODE_REQUEST_TIMEOUT_SECONDS", "10")
23+
t.Setenv("LINODE_URL", "https://api.linode.com/v4")
2324

2425
t.Run("should not fail if vpc is empty and routecontroller is disabled", func(t *testing.T) {
2526
Options.VPCName = ""
@@ -44,6 +45,7 @@ func TestNewCloud(t *testing.T) {
4445
t.Setenv("LINODE_REGION", "us-east")
4546
t.Setenv("LINODE_REQUEST_TIMEOUT_SECONDS", "10")
4647
t.Setenv("LINODE_ROUTES_CACHE_TTL_SECONDS", "60")
48+
t.Setenv("LINODE_URL", "https://api.linode.com/v4")
4749
Options.LinodeGoDebug = true
4850

4951
t.Run("should fail if api token is empty", func(t *testing.T) {

cloud/linode/nodeipamcontroller.go

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"k8s.io/apimachinery/pkg/util/wait"
2828
v1 "k8s.io/client-go/informers/core/v1"
2929
"k8s.io/client-go/kubernetes"
30-
cloudprovider "k8s.io/cloud-provider"
3130
netutils "k8s.io/utils/net"
3231

3332
nodeipamcontroller "github.com/linode/linode-cloud-controller-manager/cloud/nodeipam"
@@ -45,7 +44,7 @@ var (
4544
defaultNodeMaskCIDRIPv6 = 112
4645
)
4746

48-
func startNodeIpamController(stopCh <-chan struct{}, cloud cloudprovider.Interface, nodeInformer v1.NodeInformer, kubeclient kubernetes.Interface) error {
47+
func startNodeIpamController(stopCh <-chan struct{}, cloud *linodeCloud, nodeInformer v1.NodeInformer, kubeclient kubernetes.Interface) error {
4948
var serviceCIDR *net.IPNet
5049
var secondaryServiceCIDR *net.IPNet
5150

@@ -72,35 +71,6 @@ func startNodeIpamController(stopCh <-chan struct{}, cloud cloudprovider.Interfa
7271
return fmt.Errorf("clusterCIDR %s is not ipv4", clusterCIDRs[0].String())
7372
}
7473

75-
/* TODO: uncomment and fix if we want to support service cidr overlap with nodecidr
76-
// service cidr processing
77-
if len(strings.TrimSpace(nodeIPAMConfig.ServiceCIDR)) != 0 {
78-
_, serviceCIDR, err = netutils.ParseCIDRSloppy(nodeIPAMConfig.ServiceCIDR)
79-
if err != nil {
80-
klog.ErrorS(err, "Unsuccessful parsing of service CIDR", "CIDR", nodeIPAMConfig.ServiceCIDR)
81-
}
82-
}
83-
84-
if len(strings.TrimSpace(nodeIPAMConfig.SecondaryServiceCIDR)) != 0 {
85-
_, secondaryServiceCIDR, err = netutils.ParseCIDRSloppy(nodeIPAMConfig.SecondaryServiceCIDR)
86-
if err != nil {
87-
klog.ErrorS(err, "Unsuccessful parsing of service CIDR", "CIDR", nodeIPAMConfig.SecondaryServiceCIDR)
88-
}
89-
}
90-
91-
// the following checks are triggered if both serviceCIDR and secondaryServiceCIDR are provided
92-
if serviceCIDR != nil && secondaryServiceCIDR != nil {
93-
// should be dual stack (from different IPFamilies)
94-
dualstackServiceCIDR, err := netutils.IsDualStackCIDRs([]*net.IPNet{serviceCIDR, secondaryServiceCIDR})
95-
if err != nil {
96-
return nil, false, fmt.Errorf("failed to perform dualstack check on serviceCIDR and secondaryServiceCIDR error:%v", err)
97-
}
98-
if !dualstackServiceCIDR {
99-
return nil, false, fmt.Errorf("serviceCIDR and secondaryServiceCIDR are not dualstack (from different IPfamiles)")
100-
}
101-
}
102-
*/
103-
10474
nodeCIDRMaskSizes := setNodeCIDRMaskSizes()
10575

10676
ctx := wait.ContextForChannel(stopCh)
@@ -109,6 +79,7 @@ func startNodeIpamController(stopCh <-chan struct{}, cloud cloudprovider.Interfa
10979
ctx,
11080
nodeInformer,
11181
cloud,
82+
cloud.client,
11283
kubeclient,
11384
clusterCIDRs,
11485
serviceCIDR,

cloud/linode/nodeipamcontroller_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
v1 "k8s.io/client-go/informers/core/v1"
2929
"k8s.io/client-go/kubernetes"
3030
"k8s.io/client-go/kubernetes/fake"
31-
cloudprovider "k8s.io/cloud-provider"
3231
)
3332

3433
func Test_setNodeCIDRMaskSizes(t *testing.T) {
@@ -127,7 +126,7 @@ func Test_processCIDRs(t *testing.T) {
127126
func Test_startNodeIpamController(t *testing.T) {
128127
type args struct {
129128
stopCh <-chan struct{}
130-
cloud cloudprovider.Interface
129+
cloud linodeCloud
131130
nodeInformer v1.NodeInformer
132131
kubeclient kubernetes.Interface
133132
allocateNodeCIDRs bool
@@ -143,7 +142,7 @@ func Test_startNodeIpamController(t *testing.T) {
143142
name: "allocate-node-cidrs not set",
144143
args: args{
145144
stopCh: make(<-chan struct{}),
146-
cloud: nil,
145+
cloud: linodeCloud{},
147146
nodeInformer: nil,
148147
kubeclient: nil,
149148
allocateNodeCIDRs: false,
@@ -155,7 +154,7 @@ func Test_startNodeIpamController(t *testing.T) {
155154
name: "allocate-node-cidrs set but cluster-cidr not set",
156155
args: args{
157156
stopCh: make(<-chan struct{}),
158-
cloud: nil,
157+
cloud: linodeCloud{},
159158
nodeInformer: nil,
160159
kubeclient: nil,
161160
allocateNodeCIDRs: true,
@@ -167,7 +166,7 @@ func Test_startNodeIpamController(t *testing.T) {
167166
name: "incorrect cluster-cidr specified",
168167
args: args{
169168
stopCh: make(<-chan struct{}),
170-
cloud: nil,
169+
cloud: linodeCloud{},
171170
nodeInformer: nil,
172171
kubeclient: nil,
173172
allocateNodeCIDRs: true,
@@ -179,7 +178,7 @@ func Test_startNodeIpamController(t *testing.T) {
179178
name: "ipv6 cidr specified",
180179
args: args{
181180
stopCh: make(<-chan struct{}),
182-
cloud: nil,
181+
cloud: linodeCloud{},
183182
nodeInformer: nil,
184183
kubeclient: nil,
185184
allocateNodeCIDRs: true,
@@ -191,7 +190,7 @@ func Test_startNodeIpamController(t *testing.T) {
191190
name: "more than one cidr specified",
192191
args: args{
193192
stopCh: make(<-chan struct{}),
194-
cloud: nil,
193+
cloud: linodeCloud{},
195194
nodeInformer: nil,
196195
kubeclient: nil,
197196
allocateNodeCIDRs: true,
@@ -203,7 +202,7 @@ func Test_startNodeIpamController(t *testing.T) {
203202
name: "correct cidrs specified",
204203
args: args{
205204
stopCh: make(<-chan struct{}),
206-
cloud: nil,
205+
cloud: linodeCloud{},
207206
nodeInformer: informers.NewSharedInformerFactory(kubeClient, 0).Core().V1().Nodes(),
208207
kubeclient: kubeClient,
209208
allocateNodeCIDRs: true,
@@ -222,7 +221,7 @@ func Test_startNodeIpamController(t *testing.T) {
222221
Options.AllocateNodeCIDRs = tt.args.allocateNodeCIDRs
223222
Options.ClusterCIDRIPv4 = tt.args.clusterCIDR
224223
t.Run(tt.name, func(t *testing.T) {
225-
if err := startNodeIpamController(tt.args.stopCh, tt.args.cloud, tt.args.nodeInformer, tt.args.kubeclient); (err != nil) != tt.wantErr {
224+
if err := startNodeIpamController(tt.args.stopCh, &tt.args.cloud, tt.args.nodeInformer, tt.args.kubeclient); (err != nil) != tt.wantErr {
226225
t.Errorf("startNodeIpamController() error = %v, wantErr %v", err, tt.wantErr)
227226
}
228227
})

cloud/nodeipam/ipam/cidr_allocator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
cloudprovider "k8s.io/cloud-provider"
3333
"k8s.io/klog/v2"
3434
"k8s.io/kubernetes/pkg/controller/nodeipam/ipam/cidrset"
35+
36+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
3537
)
3638

3739
// CIDRAllocatorType is the type of the allocator to use.
@@ -94,15 +96,15 @@ type CIDRAllocatorParams struct {
9496
}
9597

9698
// New creates a new CIDR range allocator.
97-
func New(ctx context.Context, kubeClient clientset.Interface, cloud cloudprovider.Interface, nodeInformer informers.NodeInformer, allocatorType CIDRAllocatorType, allocatorParams CIDRAllocatorParams) (CIDRAllocator, error) {
99+
func New(ctx context.Context, linodeClient client.Client, kubeClient clientset.Interface, cloud cloudprovider.Interface, nodeInformer informers.NodeInformer, allocatorType CIDRAllocatorType, allocatorParams CIDRAllocatorParams) (CIDRAllocator, error) {
98100
nodeList, err := listNodes(ctx, kubeClient)
99101
if err != nil {
100102
return nil, err
101103
}
102104

103105
switch allocatorType {
104106
case CloudAllocatorType:
105-
return NewLinodeCIDRAllocator(ctx, kubeClient, nodeInformer, allocatorParams, nodeList)
107+
return NewLinodeCIDRAllocator(ctx, linodeClient, kubeClient, nodeInformer, allocatorParams, nodeList)
106108
case RangeAllocatorType:
107109
return nil, fmt.Errorf("RangeAllocatorType is not supported")
108110
default:

0 commit comments

Comments
 (0)