k8s.io/registry.k8s.io@v0.3.1/pkg/net/cloudcidrs/ipmapper.go (about)

     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 cloudcidrs
    18  
    19  import "k8s.io/registry.k8s.io/pkg/net/cidrs"
    20  
    21  // NewIPMapper returns cidrs.IPMapper populated with cloud region info
    22  // for the clouds we have resources for, currently GCP and AWS
    23  func NewIPMapper() cidrs.IPMapper[IPInfo] {
    24  	t := cidrs.NewTrieMap[IPInfo]()
    25  	for info, cidrs := range regionToRanges {
    26  		for _, cidr := range cidrs {
    27  			t.Insert(cidr, info)
    28  		}
    29  	}
    30  	return t
    31  }
    32  
    33  // AllIPInfos returns a slice of all known results that a NewIPMapper could
    34  // return
    35  func AllIPInfos() []IPInfo {
    36  	r := make([]IPInfo, 0, len(regionToRanges))
    37  	for v := range regionToRanges {
    38  		r = append(r, v)
    39  	}
    40  	return r
    41  }