use klog.InfoS instead of klog.V(0),Info
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package nodeipam
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@@ -50,7 +51,7 @@ const (
|
||||
// legacy mode. It is needed to ensure correct building for
|
||||
// both provider-specific and providerless environments.
|
||||
type ipamController interface {
|
||||
Run(<-chan struct{})
|
||||
Run(ctx context.Context)
|
||||
}
|
||||
|
||||
// Controller is the controller that manages node ipam state.
|
||||
@@ -79,6 +80,7 @@ type Controller struct {
|
||||
// podCIDRs it has already allocated to nodes. Since we don't allow podCIDR changes
|
||||
// currently, this should be handled as a fatal error.
|
||||
func NewNodeIpamController(
|
||||
ctx context.Context,
|
||||
nodeInformer coreinformers.NodeInformer,
|
||||
clusterCIDRInformer networkinginformers.ClusterCIDRInformer,
|
||||
cloud cloudprovider.Interface,
|
||||
@@ -89,20 +91,24 @@ func NewNodeIpamController(
|
||||
nodeCIDRMaskSizes []int,
|
||||
allocatorType ipam.CIDRAllocatorType) (*Controller, error) {
|
||||
|
||||
logger := klog.FromContext(ctx)
|
||||
if kubeClient == nil {
|
||||
klog.Fatalf("kubeClient is nil when starting Controller")
|
||||
logger.Error(nil, "kubeClient is nil when starting Controller")
|
||||
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
|
||||
}
|
||||
|
||||
// Cloud CIDR allocator does not rely on clusterCIDR or nodeCIDRMaskSize for allocation.
|
||||
if allocatorType != ipam.CloudAllocatorType {
|
||||
if len(clusterCIDRs) == 0 {
|
||||
klog.Fatal("Controller: Must specify --cluster-cidr if --allocate-node-cidrs is set")
|
||||
logger.Error(nil, "Controller: Must specify --cluster-cidr if --allocate-node-cidrs is set")
|
||||
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
|
||||
}
|
||||
|
||||
for idx, cidr := range clusterCIDRs {
|
||||
mask := cidr.Mask
|
||||
if maskSize, _ := mask.Size(); maskSize > nodeCIDRMaskSizes[idx] {
|
||||
klog.Fatal("Controller: Invalid --cluster-cidr, mask size of cluster CIDR must be less than or equal to --node-cidr-mask-size configured for CIDR family")
|
||||
logger.Error(nil, "Controller: Invalid --cluster-cidr, mask size of cluster CIDR must be less than or equal to --node-cidr-mask-size configured for CIDR family")
|
||||
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +126,7 @@ func NewNodeIpamController(
|
||||
|
||||
// TODO: Abstract this check into a generic controller manager should run method.
|
||||
if ic.allocatorType == ipam.IPAMFromClusterAllocatorType || ic.allocatorType == ipam.IPAMFromCloudAllocatorType {
|
||||
ic.legacyIPAM = createLegacyIPAM(ic, nodeInformer, cloud, kubeClient, clusterCIDRs, serviceCIDR, nodeCIDRMaskSizes)
|
||||
ic.legacyIPAM = createLegacyIPAM(logger, ic, nodeInformer, cloud, kubeClient, clusterCIDRs, serviceCIDR, nodeCIDRMaskSizes)
|
||||
} else {
|
||||
var err error
|
||||
|
||||
@@ -131,7 +137,7 @@ func NewNodeIpamController(
|
||||
NodeCIDRMaskSizes: nodeCIDRMaskSizes,
|
||||
}
|
||||
|
||||
ic.cidrAllocator, err = ipam.New(kubeClient, cloud, nodeInformer, clusterCIDRInformer, ic.allocatorType, allocatorParams)
|
||||
ic.cidrAllocator, err = ipam.New(ctx, kubeClient, cloud, nodeInformer, clusterCIDRInformer, ic.allocatorType, allocatorParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,33 +150,32 @@ func NewNodeIpamController(
|
||||
}
|
||||
|
||||
// Run starts an asynchronous loop that monitors the status of cluster nodes.
|
||||
func (nc *Controller) Run(stopCh <-chan struct{}) {
|
||||
func (nc *Controller) Run(ctx context.Context) {
|
||||
defer utilruntime.HandleCrash()
|
||||
|
||||
// Start event processing pipeline.
|
||||
nc.eventBroadcaster.StartStructuredLogging(0)
|
||||
nc.eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: nc.kubeClient.CoreV1().Events("")})
|
||||
defer nc.eventBroadcaster.Shutdown()
|
||||
klog.FromContext(ctx).Info("Starting ipam controller")
|
||||
defer klog.FromContext(ctx).Info("Shutting down ipam controller")
|
||||
|
||||
klog.Infof("Starting ipam controller")
|
||||
defer klog.Infof("Shutting down ipam controller")
|
||||
|
||||
if !cache.WaitForNamedCacheSync("node", stopCh, nc.nodeInformerSynced) {
|
||||
if !cache.WaitForNamedCacheSync("node", ctx.Done(), nc.nodeInformerSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
if nc.allocatorType == ipam.IPAMFromClusterAllocatorType || nc.allocatorType == ipam.IPAMFromCloudAllocatorType {
|
||||
go nc.legacyIPAM.Run(stopCh)
|
||||
go nc.legacyIPAM.Run(ctx)
|
||||
} else {
|
||||
go nc.cidrAllocator.Run(stopCh)
|
||||
go nc.cidrAllocator.Run(ctx)
|
||||
}
|
||||
|
||||
<-stopCh
|
||||
<-ctx.Done()
|
||||
}
|
||||
|
||||
// RunWithMetrics is a wrapper for Run that also tracks starting and stopping of the nodeipam controller with additional metric
|
||||
func (nc *Controller) RunWithMetrics(stopCh <-chan struct{}, controllerManagerMetrics *controllersmetrics.ControllerManagerMetrics) {
|
||||
func (nc *Controller) RunWithMetrics(ctx context.Context, controllerManagerMetrics *controllersmetrics.ControllerManagerMetrics) {
|
||||
controllerManagerMetrics.ControllerStarted("nodeipam")
|
||||
defer controllerManagerMetrics.ControllerStopped("nodeipam")
|
||||
nc.Run(stopCh)
|
||||
nc.Run(ctx)
|
||||
}
|
||||
|
Reference in New Issue
Block a user