func (r *rangeAllocator) AllocateOrOccupyCIDR(node *v1.Node) error {
	if node == nil {
		return nil
	}
	if !r.insertNodeToProcessing(node.Name) {
		klog.V(2).Infof("Node %v is already in a process of CIDR assignment.", node.Name)
		return nil
	}

	if len(node.Spec.PodCIDRs) > 0 {
		return r.occupyCIDRs(node)
	}
	// allocate and queue the assignment
	allocated := nodeReservedCIDRs{
		nodeName:       node.Name,
		allocatedCIDRs: make([]*net.IPNet, len(r.cidrSets)),
	}

	for idx := range r.cidrSets {
		podCIDR, err := r.cidrSets[idx].AllocateNext()
		if err != nil {
			r.removeNodeFromProcessing(node.Name)
			nodeutil.RecordNodeStatusChange(r.recorder, node, "CIDRNotAvailable")
			return fmt.Errorf("failed to allocate cidr from cluster cidr at idx:%v: %v", idx, err)
		}
		allocated.allocatedCIDRs[idx] = podCIDR
	}

	//queue the assignment
	klog.V(4).Infof("Putting node %s with CIDR %v into the work queue", node.Name, allocated.allocatedCIDRs)
	r.nodeCIDRUpdateChannel <- allocated
	return nil
}
// WARNING: If you're adding any return calls or defer any more work from this
// function you have to make sure to update nodesInProcessing properly with the
// disposition of the node when the work is done.
If you're adding any return calls or defer any more work from this
function you have to make sure to update nodesInProcessing properly with the
disposition of the node when the work is done.
// WARNING : If you ' re adding any return calls or defer any more work from this // function you have to make sure to update nodesInProcessing properly with the // disposition of the node when the work is done .
func (r *rangeAllocator) AllocateOrOccupyCIDR(node *v1.Node) error {
	if node == nil {
		return nil
	}
	if !r.insertNodeToProcessing(node.Name) {
		klog.V(2).Infof("Node %v is already in a process of CIDR assignment.", node.Name)
		return nil
	}
	if len(node.Spec.PodCIDRs) > 0 {
		return r.occupyCIDRs(node)
	}
	allocated := nodeReservedCIDRs{
		nodeName:       node.Name,
		allocatedCIDRs: make([]*net.IPNet, len(r.cidrSets)),
	}
	for idx := range r.cidrSets {
		podCIDR, err := r.cidrSets[idx].AllocateNext()
		if err != nil {
			r.removeNodeFromProcessing(node.Name)
			nodeutil.RecordNodeStatusChange(r.recorder, node, "CIDRNotAvailable")
			return fmt.Errorf("failed to allocate cidr from cluster cidr at idx:%v: %v", idx, err)
		}
		allocated.allocatedCIDRs[idx] = podCIDR
	}
	klog.V(4).Infof("Putting node %s with CIDR %v into the work queue", node.Name, allocated.allocatedCIDRs)
	r.nodeCIDRUpdateChannel <- allocated
	return nil
}
func ( r * rangeAllocator ) AllocateOrOccupyCIDR ( node * v1 . Node ) error { if node == nil { return nil } if ! r . insertNodeToProcessing ( node . Name ) { klog . V ( 2 ) . Infof ( " " , node . Name ) return nil } if len ( node . Spec . PodCIDRs ) > 0 { return r . occupyCIDRs ( node ) } allocated := nodeReservedCIDRs { nodeName : node . Name , allocatedCIDRs : make ( [ ] * net . IPNet , len ( r . cidrSets ) ) , } for idx := range r . cidrSets { podCIDR , err := r . cidrSets [ idx ] . AllocateNext ( ) if err != nil { r . removeNodeFromProcessing ( node . Name ) nodeutil . RecordNodeStatusChange ( r . recorder , node , " " ) return fmt . Errorf ( " " , idx , err ) } allocated . allocatedCIDRs [ idx ] = podCIDR } klog . V ( 4 ) . Infof ( " " , node . Name , allocated . allocatedCIDRs ) r . nodeCIDRUpdateChannel <- allocated return nil }
If you're adding any return calls or defer any more work from this
function you have to make sure to update nodesInProcessing properly with the
disposition of the node when the work is done.
If you ' re adding any return calls or defer any more work from this function you have to make sure to update nodesInProcessing properly with the disposition of the node when the work is done .
// allocate and queue the assignment //queue the assignment