legacyprovider.go 2.0 KB

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