kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/network/calicov3/ippool_types.go (about) 1 // Copyright (c) 2017-2020 Tigera, Inc. All rights reserved. 2 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package calicov3 16 17 import ( 18 cnet "github.com/projectcalico/calico/libcalico-go/lib/net" 19 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 21 v3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3" 22 ) 23 24 // +genclient 25 // +kubebuilder:object:root=true 26 // +genclient:nonNamespaced 27 // +k8s:openapi-gen=true 28 // +kubebuilder:resource:scope=Cluster 29 type IPPool struct { 30 metav1.TypeMeta `json:",inline"` 31 metav1.ObjectMeta `json:"metadata,omitempty"` 32 Spec v3.IPPoolSpec `json:"spec,omitempty"` 33 } 34 35 // +kubebuilder:object:root=true 36 37 // IPPoolList contains a list of IPPool resources. 38 type IPPoolList struct { 39 metav1.TypeMeta `json:",inline"` 40 metav1.ListMeta `json:"metadata"` 41 Items []IPPool `json:"items"` 42 } 43 44 func (p IPPool) NumAddresses() int { 45 _, cidr, _ := cnet.ParseCIDR(p.Spec.CIDR) 46 ones, size := cidr.Mask.Size() 47 numAddresses := 1 << uint(size-ones) 48 return numAddresses 49 }