1// +build !providerless
2
3/*
4Copyright 2019 The Kubernetes Authors.
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17*/
18
19package nodeipam
20
21import (
22	"net"
23
24	coreinformers "k8s.io/client-go/informers/core/v1"
25	clientset "k8s.io/client-go/kubernetes"
26	cloudprovider "k8s.io/cloud-provider"
27	"k8s.io/klog/v2"
28
29	"k8s.io/kubernetes/pkg/controller/nodeipam/ipam"
30	nodesync "k8s.io/kubernetes/pkg/controller/nodeipam/ipam/sync"
31)
32
33func startLegacyIPAM(
34	ic *Controller,
35	nodeInformer coreinformers.NodeInformer,
36	cloud cloudprovider.Interface,
37	kubeClient clientset.Interface,
38	clusterCIDRs []*net.IPNet,
39	serviceCIDR *net.IPNet,
40	nodeCIDRMaskSizes []int,
41) {
42	cfg := &ipam.Config{
43		Resync:       ipamResyncInterval,
44		MaxBackoff:   ipamMaxBackoff,
45		InitialRetry: ipamInitialBackoff,
46	}
47	switch ic.allocatorType {
48	case ipam.IPAMFromClusterAllocatorType:
49		cfg.Mode = nodesync.SyncFromCluster
50	case ipam.IPAMFromCloudAllocatorType:
51		cfg.Mode = nodesync.SyncFromCloud
52	}
53
54	// we may end up here with no cidr at all in case of FromCloud/FromCluster
55	var cidr *net.IPNet
56	if len(clusterCIDRs) > 0 {
57		cidr = clusterCIDRs[0]
58	}
59	if len(clusterCIDRs) > 1 {
60		klog.Warningf("Multiple cidrs were configured with FromCluster or FromCloud. cidrs except first one were discarded")
61	}
62	ipamc, err := ipam.NewController(cfg, kubeClient, cloud, cidr, serviceCIDR, nodeCIDRMaskSizes[0])
63	if err != nil {
64		klog.Fatalf("Error creating ipam controller: %v", err)
65	}
66	if err := ipamc.Start(nodeInformer); err != nil {
67		klog.Fatalf("Error trying to Init(): %v", err)
68	}
69}
70