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