...

Source file src/k8s.io/kubernetes/pkg/registry/core/service/ipallocator/interfaces.go

Documentation: k8s.io/kubernetes/pkg/registry/core/service/ipallocator

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     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  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ipallocator
    18  
    19  import (
    20  	"errors"
    21  	"fmt"
    22  	"net"
    23  
    24  	api "k8s.io/kubernetes/pkg/apis/core"
    25  )
    26  
    27  // Interface manages the allocation of IP addresses out of a range. Interface
    28  // should be threadsafe.
    29  type Interface interface {
    30  	Allocate(net.IP) error
    31  	AllocateNext() (net.IP, error)
    32  	Release(net.IP) error
    33  	ForEach(func(net.IP))
    34  	CIDR() net.IPNet
    35  	IPFamily() api.IPFamily
    36  	Has(ip net.IP) bool
    37  	Destroy()
    38  	EnableMetrics()
    39  
    40  	// DryRun offers a way to try operations without persisting them.
    41  	DryRun() Interface
    42  }
    43  
    44  var (
    45  	ErrFull              = errors.New("range is full")
    46  	ErrAllocated         = errors.New("provided IP is already allocated")
    47  	ErrMismatchedNetwork = errors.New("the provided network does not match the current range")
    48  	ErrNotReady          = errors.New("allocator not ready")
    49  )
    50  
    51  type ErrNotInRange struct {
    52  	IP         net.IP
    53  	ValidRange string
    54  }
    55  
    56  func (e *ErrNotInRange) Error() string {
    57  	return fmt.Sprintf("the provided IP (%v) is not in the valid range. The range of valid IPs is %s", e.IP, e.ValidRange)
    58  }
    59  

View as plain text