diff --git a/Makefile b/Makefile index 05f496becc..34aa0e8681 100644 --- a/Makefile +++ b/Makefile @@ -162,7 +162,6 @@ generate-groups: # Generate gRPC files grpc: protoc $(PROTOC) --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pkg/ipam/ipam.proto - $(PROTOC) --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pkg/ipamold/ipam.proto protoc: ifeq (, $(shell which protoc)) diff --git a/apis/ipam/v1alpha1/ipamstorage_types.go b/apis/ipam/v1alpha1/ipamstorage_types.go deleted file mode 100644 index a4152af2f7..0000000000 --- a/apis/ipam/v1alpha1/ipamstorage_types.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -var ( - // IpamStorageKind is the kind name used to register the IpamStorage CRD. - IpamStorageKind = "IpamStorage" - - // IpamStorageResource is the resource name used to register the IpamStorage CRD. - IpamStorageResource = "ipamstorages" - - // IpamStorageGroupVersionResource is the group version resource used to register IpamStorage CRD. - IpamStorageGroupVersionResource = SchemeGroupVersion.WithResource(IpamStorageResource) - - // IpamStorageGroupResource is the group resource used to register IpamStorage CRD. - IpamStorageGroupResource = schema.GroupResource{Group: SchemeGroupVersion.Group, Resource: IpamStorageResource} -) - -// Subnets type contains relevant networks related to a remote cluster. -type Subnets struct { - // Network used in the remote cluster for local Pods. Default is "None": this means remote cluster uses local cluster PodCIDR. - LocalNATPodCIDR string `json:"localNATPodCIDR"` - // Network used for Pods in the remote cluster. - RemotePodCIDR string `json:"remotePodCIDR"` - // Network used in remote cluster for local service endpoints. Default is "None": this means remote cluster uses local cluster ExternalCIDR. - LocalNATExternalCIDR string `json:"localNATExternalCIDR"` - // Network used in local cluster for remote service endpoints. - RemoteExternalCIDR string `json:"remoteExternalCIDR"` -} - -// ClusterMapping is an empty struct. -type ClusterMapping struct { - // ExternalCIDRNattedIP belonging to cluster ExtenalCIDR assigned to this endpoint. - ExternalCIDRNattedIP string `json:"ExternalCIDRNattedIP"` -} - -// EndpointMapping describes a relation between an enpoint IP and an IP belonging to ExternalCIDR. -type EndpointMapping struct { - // IP belonging to cluster LocalExternalCIDR assigned to this endpoint. - ExternalCIDROriginalIP string `json:"ExternalCIDROriginalIP"` - // Set of clusters to which this endpoint has been reflected. Only the key, which is the ClusterID, is useful. - ClusterMappings map[string]ClusterMapping `json:"clusterMappings"` -} - -// IpamSpec defines the desired state of Ipam. -type IpamSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file - // Map consumed by go-ipam module. Key is prefic cidr, value is a Prefix. - Prefixes map[string][]byte `json:"prefixes"` - // Network pools. - Pools []string `json:"pools"` - // Reserved Networks. Subnets listed in this field are excluded from the list of possible subnets used for natting POD CIDR. - ReservedSubnets []string `json:"reservedSubnets"` - // Map used to keep track of networks assigned to clusters. Key is the remote cluster ID, value is a the set of - // networks used by the remote cluster. - ClusterSubnets map[string]Subnets `json:"clusterSubnets"` - // Cluster ExternalCIDR - ExternalCIDR string `json:"externalCIDR"` - // Endpoint IP mappings. Key is the IP address of the local endpoint, value is an EndpointMapping struct - // that contains the related IP belonging to the ExternalCIDR and also the list of clusters - // on which this mapping is active - EndpointMappings map[string]EndpointMapping `json:"endpointMappings"` - // Cluster PodCIDR - PodCIDR string `json:"podCIDR"` - // ServiceCIDR - ServiceCIDR string `json:"serviceCIDR"` -} - -// +kubebuilder:object:root=true -// +kubebuilder:resource:scope=Namespaced,categories=liqo - -// IpamStorage is the Schema for the ipams API. -type IpamStorage struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec IpamSpec `json:"spec,omitempty"` -} - -// +kubebuilder:object:root=true - -// IpamStorageList contains a list of Ipam. -type IpamStorageList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []IpamStorage `json:"items"` -} - -func init() { - SchemeBuilder.Register(&IpamStorage{}, &IpamStorageList{}) -} diff --git a/apis/ipam/v1alpha1/zz_generated.deepcopy.go b/apis/ipam/v1alpha1/zz_generated.deepcopy.go index 7affb37385..ca7c6974d4 100644 --- a/apis/ipam/v1alpha1/zz_generated.deepcopy.go +++ b/apis/ipam/v1alpha1/zz_generated.deepcopy.go @@ -23,43 +23,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterMapping) DeepCopyInto(out *ClusterMapping) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterMapping. -func (in *ClusterMapping) DeepCopy() *ClusterMapping { - if in == nil { - return nil - } - out := new(ClusterMapping) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *EndpointMapping) DeepCopyInto(out *EndpointMapping) { - *out = *in - if in.ClusterMappings != nil { - in, out := &in.ClusterMappings, &out.ClusterMappings - *out = make(map[string]ClusterMapping, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointMapping. -func (in *EndpointMapping) DeepCopy() *EndpointMapping { - if in == nil { - return nil - } - out := new(EndpointMapping) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IP) DeepCopyInto(out *IP) { *out = *in @@ -164,119 +127,6 @@ func (in *IPStatus) DeepCopy() *IPStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *IpamSpec) DeepCopyInto(out *IpamSpec) { - *out = *in - if in.Prefixes != nil { - in, out := &in.Prefixes, &out.Prefixes - *out = make(map[string][]byte, len(*in)) - for key, val := range *in { - var outVal []byte - if val == nil { - (*out)[key] = nil - } else { - inVal := (*in)[key] - in, out := &inVal, &outVal - *out = make([]byte, len(*in)) - copy(*out, *in) - } - (*out)[key] = outVal - } - } - if in.Pools != nil { - in, out := &in.Pools, &out.Pools - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ReservedSubnets != nil { - in, out := &in.ReservedSubnets, &out.ReservedSubnets - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ClusterSubnets != nil { - in, out := &in.ClusterSubnets, &out.ClusterSubnets - *out = make(map[string]Subnets, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.EndpointMappings != nil { - in, out := &in.EndpointMappings, &out.EndpointMappings - *out = make(map[string]EndpointMapping, len(*in)) - for key, val := range *in { - (*out)[key] = *val.DeepCopy() - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IpamSpec. -func (in *IpamSpec) DeepCopy() *IpamSpec { - if in == nil { - return nil - } - out := new(IpamSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *IpamStorage) DeepCopyInto(out *IpamStorage) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IpamStorage. -func (in *IpamStorage) DeepCopy() *IpamStorage { - if in == nil { - return nil - } - out := new(IpamStorage) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *IpamStorage) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *IpamStorageList) DeepCopyInto(out *IpamStorageList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]IpamStorage, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IpamStorageList. -func (in *IpamStorageList) DeepCopy() *IpamStorageList { - if in == nil { - return nil - } - out := new(IpamStorageList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *IpamStorageList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Network) DeepCopyInto(out *Network) { *out = *in @@ -382,18 +232,3 @@ func (in *ServiceTemplate) DeepCopy() *ServiceTemplate { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Subnets) DeepCopyInto(out *Subnets) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subnets. -func (in *Subnets) DeepCopy() *Subnets { - if in == nil { - return nil - } - out := new(Subnets) - in.DeepCopyInto(out) - return out -} diff --git a/cmd/uninstaller/main.go b/cmd/uninstaller/main.go index 06b94a575a..a7ccce3bff 100644 --- a/cmd/uninstaller/main.go +++ b/cmd/uninstaller/main.go @@ -61,7 +61,6 @@ func init() { // +kubebuilder:rbac:groups=networking.liqo.io,resources=internalnodes,verbs=get;list;watch;patch;update;delete; // +kubebuilder:rbac:groups=ipam.liqo.io,resources=networks,verbs=get;list;watch;patch;update;delete; // +kubebuilder:rbac:groups=ipam.liqo.io,resources=ips,verbs=get;list;watch;patch;update;delete; -// +kubebuilder:rbac:groups=ipam.liqo.io,resources=ipamstorages,verbs=get;list;watch;patch;update;delete; // +kubebuilder:rbac:groups=networking.liqo.io,resources=configurations,verbs=get;list;watch;patch;update;delete; // +kubebuilder:rbac:groups=authentication.liqo.io,resources=resourceslices,verbs=get;list;watch;patch;update;delete; @@ -134,11 +133,6 @@ func main() { os.Exit(1) } - if err := uninstaller.DeleteIpamStorage(ctx, dynClient); err != nil { - klog.Errorf("Unable to delete IpamStorage: %s", err) - os.Exit(1) - } - // Wait for resources to be effectively deleted, to allow releasing possible finalizers. if err := uninstaller.WaitForResources(dynClient, uninstaller.PhaseCleanup); err != nil { klog.Errorf("Unable to wait deletion of objects: %s", err) diff --git a/deployments/liqo/charts/liqo-crds/crds/ipam.liqo.io_ipamstorages.yaml b/deployments/liqo/charts/liqo-crds/crds/ipam.liqo.io_ipamstorages.yaml deleted file mode 100644 index d7d3a81b79..0000000000 --- a/deployments/liqo/charts/liqo-crds/crds/ipam.liqo.io_ipamstorages.yaml +++ /dev/null @@ -1,149 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.16.3 - name: ipamstorages.ipam.liqo.io -spec: - group: ipam.liqo.io - names: - categories: - - liqo - kind: IpamStorage - listKind: IpamStorageList - plural: ipamstorages - singular: ipamstorage - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: IpamStorage is the Schema for the ipams API. - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: IpamSpec defines the desired state of Ipam. - properties: - clusterSubnets: - additionalProperties: - description: Subnets type contains relevant networks related to - a remote cluster. - properties: - localNATExternalCIDR: - description: 'Network used in remote cluster for local service - endpoints. Default is "None": this means remote cluster uses - local cluster ExternalCIDR.' - type: string - localNATPodCIDR: - description: 'Network used in the remote cluster for local Pods. - Default is "None": this means remote cluster uses local cluster - PodCIDR.' - type: string - remoteExternalCIDR: - description: Network used in local cluster for remote service - endpoints. - type: string - remotePodCIDR: - description: Network used for Pods in the remote cluster. - type: string - required: - - localNATExternalCIDR - - localNATPodCIDR - - remoteExternalCIDR - - remotePodCIDR - type: object - description: |- - Map used to keep track of networks assigned to clusters. Key is the remote cluster ID, value is a the set of - networks used by the remote cluster. - type: object - endpointMappings: - additionalProperties: - description: EndpointMapping describes a relation between an enpoint - IP and an IP belonging to ExternalCIDR. - properties: - ExternalCIDROriginalIP: - description: IP belonging to cluster LocalExternalCIDR assigned - to this endpoint. - type: string - clusterMappings: - additionalProperties: - description: ClusterMapping is an empty struct. - properties: - ExternalCIDRNattedIP: - description: ExternalCIDRNattedIP belonging to cluster - ExtenalCIDR assigned to this endpoint. - type: string - required: - - ExternalCIDRNattedIP - type: object - description: Set of clusters to which this endpoint has been - reflected. Only the key, which is the ClusterID, is useful. - type: object - required: - - ExternalCIDROriginalIP - - clusterMappings - type: object - description: |- - Endpoint IP mappings. Key is the IP address of the local endpoint, value is an EndpointMapping struct - that contains the related IP belonging to the ExternalCIDR and also the list of clusters - on which this mapping is active - type: object - externalCIDR: - description: Cluster ExternalCIDR - type: string - podCIDR: - description: Cluster PodCIDR - type: string - pools: - description: Network pools. - items: - type: string - type: array - prefixes: - additionalProperties: - format: byte - type: string - description: |- - INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - Important: Run "make" to regenerate code after modifying this file - Map consumed by go-ipam module. Key is prefic cidr, value is a Prefix. - type: object - reservedSubnets: - description: Reserved Networks. Subnets listed in this field are excluded - from the list of possible subnets used for natting POD CIDR. - items: - type: string - type: array - serviceCIDR: - description: ServiceCIDR - type: string - required: - - clusterSubnets - - endpointMappings - - externalCIDR - - podCIDR - - pools - - prefixes - - reservedSubnets - - serviceCIDR - type: object - type: object - served: true - storage: true diff --git a/deployments/liqo/files/liqo-pre-delete-ClusterRole.yaml b/deployments/liqo/files/liqo-pre-delete-ClusterRole.yaml index 77fd159d06..a6c195ee16 100644 --- a/deployments/liqo/files/liqo-pre-delete-ClusterRole.yaml +++ b/deployments/liqo/files/liqo-pre-delete-ClusterRole.yaml @@ -50,7 +50,6 @@ rules: - apiGroups: - ipam.liqo.io resources: - - ipamstorages - ips - networks verbs: diff --git a/go.mod b/go.mod index ca52f30798..9d658420b0 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/gruntwork-io/terratest v0.47.2 github.com/julienschmidt/httprouter v1.3.0 github.com/mattn/go-isatty v0.0.20 - github.com/metal-stack/go-ipam v1.11.3 github.com/miekg/dns v1.1.57 github.com/mittwald/go-helm-client v0.12.14 github.com/onsi/ginkgo/v2 v2.19.0 @@ -31,7 +30,6 @@ require ( github.com/spf13/pflag v1.0.5 github.com/virtual-kubelet/virtual-kubelet v1.11.0 github.com/vishvananda/netlink v1.2.1-beta.2 - go4.org/netipx v0.0.0-20220925034521-797b0c90d8ab golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc golang.org/x/mod v0.21.0 golang.org/x/sync v0.8.0 @@ -90,7 +88,6 @@ require ( github.com/Microsoft/hcsshim v0.12.0 // indirect github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect - github.com/avast/retry-go/v4 v4.3.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/boombuler/barcode v1.0.1 // indirect @@ -100,12 +97,9 @@ require ( github.com/containerd/console v1.0.3 // indirect github.com/containerd/containerd v1.7.12 // indirect github.com/containerd/log v0.1.0 // indirect - github.com/coreos/go-semver v0.3.1 // indirect - github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/cyphar/filepath-securejoin v0.3.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dimchansky/utfbom v1.1.1 // indirect github.com/distribution/reference v0.5.0 // indirect github.com/docker/cli v25.0.1+incompatible // indirect @@ -133,7 +127,6 @@ require ( github.com/go-openapi/jsonpointer v0.20.2 // indirect github.com/go-openapi/jsonreference v0.20.4 // indirect github.com/go-openapi/swag v0.22.7 // indirect - github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/gobwas/glob v0.2.3 // indirect @@ -142,7 +135,6 @@ require ( github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect - github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect @@ -188,13 +180,11 @@ require ( github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/moby/locker v1.0.1 // indirect - github.com/moby/patternmatcher v0.5.0 // indirect github.com/moby/spdystream v0.4.0 // indirect github.com/moby/term v0.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect - github.com/montanaflynn/stats v0.6.6 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect github.com/opencontainers/go-digest v1.0.0 // indirect @@ -217,28 +207,18 @@ require ( github.com/vishvananda/netns v0.0.4 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect - github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.2 // indirect - github.com/xdg-go/stringprep v1.0.4 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/xlab/treeprint v1.2.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect - go.etcd.io/etcd/api/v3 v3.5.14 // indirect - go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect - go.etcd.io/etcd/client/v3 v3.5.14 // indirect - go.mongodb.org/mongo-driver v1.11.1 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect go.opentelemetry.io/otel v1.28.0 // indirect go.opentelemetry.io/otel/metric v1.28.0 // indirect go.opentelemetry.io/otel/trace v1.28.0 // indirect go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect - go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.26.0 // indirect golang.org/x/crypto v0.27.0 // indirect golang.org/x/net v0.29.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect @@ -246,7 +226,6 @@ require ( golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect golang.zx2c4.com/wireguard v0.0.0-20220904105730-b51010ba13f0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 5c64f7d220..7dc1e42b0e 100644 --- a/go.sum +++ b/go.sum @@ -134,8 +134,6 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= -github.com/avast/retry-go/v4 v4.3.2 h1:x4sTEu3jSwr7zNjya8NTdIN+U88u/jtO/q3OupBoDtM= -github.com/avast/retry-go/v4 v4.3.2/go.mod h1:rg6XFaiuFYII0Xu3RDbZQkxCofFwruZKW8oEF1jpWiU= github.com/aws/aws-sdk-go v1.54.6 h1:HEYUib3yTt8E6vxjMWM3yAq5b+qjj/6aKA62mkgux9g= github.com/aws/aws-sdk-go v1.54.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -158,8 +156,6 @@ github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0Bsq github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0 h1:nvj0OLI3YqYXer/kZD8Ri1aaunCxIEsOst1BVJswV0o= github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= -github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= -github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -187,10 +183,6 @@ github.com/containerd/errdefs v0.1.0 h1:m0wCRBiu1WJT/Fr+iOoQHMQS/eP5myQ8lCv4Dz5Z github.com/containerd/errdefs v0.1.0/go.mod h1:YgWiiHtLmSeBrvpw+UfPijzbLaB77mEG1WwJTDETIV0= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= -github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= -github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= -github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -203,8 +195,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2 h1:aBfCb7iqHmDEIp6fBvC/hQUddQfg+3qdYjwzaiP9Hnc= @@ -225,8 +215,6 @@ github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA= github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8= github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw= -github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= -github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1 h1:ZClxb8laGDf5arXfYcAtECDFgAgHklGI8CxgjHnXKJ4= github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= @@ -318,8 +306,6 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.22.7 h1:JWrc1uc/P9cSomxfnsFSVWoE1FW6bNbrVPmpQYpCcR8= github.com/go-openapi/swag v0.22.7/go.mod h1:Gl91UqO+btAM0plGGxHqJcQZ1ZTy6jbmridBTsDy8A0= -github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= -github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -327,7 +313,6 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -364,9 +349,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k= github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -486,7 +468,6 @@ github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= @@ -521,8 +502,6 @@ github.com/lithammer/dedent v1.1.0 h1:VNzHMVCBNG1j0fh3OrsFRkVUwStdDArbgBWoPAffkt github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc= github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= -github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= -github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -550,8 +529,6 @@ github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU github.com/mdlayher/socket v0.1.1/go.mod h1:mYV5YIZAfHh4dzDVzI8x8tWLWCliuX8Mon5Awbj+qDs= github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI= github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI= -github.com/metal-stack/go-ipam v1.11.3 h1:PSc+WslrRFGT76puT7Av1qiuEOlxDZvCOxfsSSqBp2w= -github.com/metal-stack/go-ipam v1.11.3/go.mod h1:SLuqunVwvGVbclmzIsw6FWY060KqxyB+iBRMU0OagG8= github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= @@ -570,17 +547,11 @@ github.com/mittwald/go-helm-client v0.12.14 h1:az3GJ4kRmFK609Ic3iHXveNtg92n9jWG0 github.com/mittwald/go-helm-client v0.12.14/go.mod h1:2VogAupgnV7FiuoPqtpCYKS/RrMh9fFA3/pD/OmTaLc= github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg= github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc= -github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= -github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/moby/spdystream v0.4.0 h1:Vy79D6mHeJJjiPdFEL2yku1kl0chZpJfZcPpb16BRl8= github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI= github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78= github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI= -github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= -github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= -github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg= -github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -592,11 +563,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ= -github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= -github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= -github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= @@ -604,14 +570,10 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA= github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= @@ -728,10 +690,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/testcontainers/testcontainers-go v0.15.0 h1:3Ex7PUGFv0b2bBsdOv6R42+SK2qoZnWBd21LvZYhUtQ= -github.com/testcontainers/testcontainers-go v0.15.0/go.mod h1:PkohMRH2X8Hib0IWtifVexDfLPVT+tb5E9hsf7cW12w= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY= github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs= @@ -743,14 +701,6 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= -github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= -github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= -github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= -github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= -github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= -github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= -github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= @@ -765,9 +715,6 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= -github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= -github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -777,14 +724,6 @@ github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50 h1:hlE8//ciYMzt github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f h1:ERexzlUfuTvpE74urLSbIQW0Z/6hF9t8U4NsJLaioAY= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg= -go.etcd.io/etcd/api/v3 v3.5.14 h1:vHObSCxyB9zlF60w7qzAdTcGaglbJOpSj1Xj9+WGxq0= -go.etcd.io/etcd/api/v3 v3.5.14/go.mod h1:BmtWcRlQvwa1h3G2jvKYwIQy4PkHlDej5t7uLMUdJUU= -go.etcd.io/etcd/client/pkg/v3 v3.5.14 h1:SaNH6Y+rVEdxfpA2Jr5wkEvN6Zykme5+YnbCkxvuWxQ= -go.etcd.io/etcd/client/pkg/v3 v3.5.14/go.mod h1:8uMgAokyG1czCtIdsq+AGyYQMvpIKnSvPjFMunkgeZI= -go.etcd.io/etcd/client/v3 v3.5.14 h1:CWfRs4FDaDoSz81giL7zPpZH2Z35tbOrAJkkjMqOupg= -go.etcd.io/etcd/client/v3 v3.5.14/go.mod h1:k3XfdV/VIHy/97rqWjoUzrj9tk7GgJGH9J8L4dNXmAk= -go.mongodb.org/mongo-driver v1.11.1 h1:QP0znIRTuL0jf1oBQoAoM0C6ZJfBK4kx0Uumtv1A7w8= -go.mongodb.org/mongo-driver v1.11.1/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -807,8 +746,6 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= -go4.org/netipx v0.0.0-20220925034521-797b0c90d8ab h1:+yW1yrZ09EYNu1spCUOHBBNRbrLnfmutwyhbhCv3b6Q= -go4.org/netipx v0.0.0-20220925034521-797b0c90d8ab/go.mod h1:tgPU4N2u9RByaTN3NC2p9xOzyFpte4jYwsIIRF7XlSc= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -816,7 +753,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= @@ -996,7 +932,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= @@ -1097,6 +1032,7 @@ google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ= google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= @@ -1137,7 +1073,6 @@ gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWM gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= diff --git a/pkg/consts/labels.go b/pkg/consts/labels.go index 6326781e4b..e69d7fe779 100644 --- a/pkg/consts/labels.go +++ b/pkg/consts/labels.go @@ -38,13 +38,6 @@ const ( // APIServerProxyAppName label value that denotes the name of the liqo-api-server-proxy deployment. APIServerProxyAppName = "proxy" - // IpamStorageResourceLabelKey is the constant representing - // the key of the label assigned to all IpamStorage resources. - IpamStorageResourceLabelKey = "ipam.liqo.io/ipamstorage" - // IpamStorageResourceLabelValue is the constant representing - // the value of the label assigned to all IpamStorage resources. - IpamStorageResourceLabelValue = "true" - // WebhookResourceLabelKey is the constant representing // the key of the label assigned to all Webhook resources. WebhookResourceLabelKey = "liqo.io/webhook" diff --git a/pkg/ipamold/doc.go b/pkg/ipamold/doc.go deleted file mode 100644 index fc0bf1e6d5..0000000000 --- a/pkg/ipamold/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ipam contains the IPAM module. It is in charge of: -// 1. Keep track of used networks/IP addresses -// 2. Assign networks (ex. remap a remote cluster network to a new network) -// 3. Assign IP addresses (ex. to service endpoints) -// 4. Notify GW about endpoint IP remapping -package ipam diff --git a/pkg/ipamold/errors/doc.go b/pkg/ipamold/errors/doc.go deleted file mode 100644 index dc3c795ad6..0000000000 --- a/pkg/ipamold/errors/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package errors contains error types definition and related functions -// used by the IPAM package. -package errors diff --git a/pkg/ipamold/errors/errors.go b/pkg/ipamold/errors/errors.go deleted file mode 100644 index 02671a5868..0000000000 --- a/pkg/ipamold/errors/errors.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package errors - -import ( - "reflect" - "strings" -) - -const ( - // GreaterOrEqual used as reason of failure in WrongParameter error. - GreaterOrEqual = ">=" - // MinorOrEqual used as reason of failure in WrongParameter error. - MinorOrEqual = "<=" - // AtLeastOneValid used as reason of failure in WrongParameter error. - AtLeastOneValid = "at least one of the arguments has to be valid" - // ValidIP used as reason of failure in WrongParameter error. - ValidIP = "a valid IP address" - // NotNil used as reason of failure in WrongParameter error. - NotNil = "not nil" - // ValidCIDR used as reason of failure in WrongParameter error. - ValidCIDR = "a valid network CIDR" - // StringNotEmpty used as reason of failure in WrongParameter error. - StringNotEmpty = "not empty" - // Initialization used as reason of failure in WrongParameter error. - Initialization = "initialized first" -) - -// ParseIPError it is returned when net.ParseIP() fails to parse and ip address. -type ParseIPError struct { - IPToBeParsed string -} - -func (pie *ParseIPError) Error() string { - return "please check that the IP address is in che correct format: " + pie.IPToBeParsed -} - -// WrongParameter it is returned when parameters passed to a function are not correct. -type WrongParameter struct { - Argument string - Reason string - Parameter string -} - -func (wp *WrongParameter) Error() string { - return strings.Join([]string{wp.Parameter, " must be ", wp.Reason, wp.Argument}, "") -} - -// NoRouteFound it is returned when no route is found for a given destination network. -type NoRouteFound struct { - IPAddress string -} - -func (nrf *NoRouteFound) Error() string { - return "no route found for IP address: " + nrf.IPAddress -} - -// MissingInit is returned when a data structure is tried to be used before correct -// initialization. -type MissingInit struct { - StructureName string -} - -func (sni *MissingInit) Error() string { - return strings.Join([]string{sni.StructureName, "must be", Initialization}, " ") -} - -// Is function is used for assert that a generic error is a MissingInit error. -func (sni *MissingInit) Is(target error) bool { - return reflect.TypeOf(sni) == reflect.TypeOf(target) -} diff --git a/pkg/ipamold/fake/doc.go b/pkg/ipamold/fake/doc.go deleted file mode 100644 index 818e1341a7..0000000000 --- a/pkg/ipamold/fake/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package fake implements fake IPAM grpc interfaces for testing purposes. -package fake diff --git a/pkg/ipamold/fake/ipam.go b/pkg/ipamold/fake/ipam.go deleted file mode 100644 index 9c54c54a1e..0000000000 --- a/pkg/ipamold/fake/ipam.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fake - -import ( - "context" - "fmt" - - grpc "google.golang.org/grpc" - - ipam "github.com/liqotech/liqo/pkg/ipamold" - ipamutils "github.com/liqotech/liqo/pkg/ipamold/utils" -) - -var _ ipam.IpamClient = &IPAMClient{} - -// IPAMClient provides a mock implementation of the IPAMClient interface for testing purposes. -type IPAMClient struct { - localRemappedPodCIDR string - remoteRemappedPodCIDR string - enforceSingleRequest bool - - pods map[string]string - endpoints map[string]string -} - -// NewIPAMClient returns a new fake IPAMClient. -func NewIPAMClient(localRemappedPodCIDR, remoteRemappedPodCIDR string, enforceSingleRequest bool) *IPAMClient { - return &IPAMClient{ - localRemappedPodCIDR: localRemappedPodCIDR, - remoteRemappedPodCIDR: remoteRemappedPodCIDR, - enforceSingleRequest: true, - - pods: make(map[string]string), - endpoints: make(map[string]string), - } -} - -// MapEndpointIP mocks the corresponding IPAMClient function. -func (mock *IPAMClient) MapEndpointIP(_ context.Context, req *ipam.MapRequest, _ ...grpc.CallOption) (*ipam.MapResponse, error) { - // Check first if the translation has already been computed. - if translation, found := mock.endpoints[req.GetIp()]; found { - if mock.enforceSingleRequest { - return nil, fmt.Errorf("mapping for IP %v already requested", req.GetIp()) - } - return &ipam.MapResponse{Ip: translation}, nil - } - - ip, err := ipamutils.MapIPToNetwork(mock.localRemappedPodCIDR, req.GetIp()) - if err != nil { - return nil, err - } - mock.endpoints[req.GetIp()] = ip - return &ipam.MapResponse{Ip: ip}, nil -} - -// UnmapEndpointIP mocks the corresponding IPAMClient function. -func (mock *IPAMClient) UnmapEndpointIP(_ context.Context, req *ipam.UnmapRequest, _ ...grpc.CallOption) (*ipam.UnmapResponse, error) { - // Check first if the translation has already been removed. - if _, found := mock.endpoints[req.GetIp()]; !found && mock.enforceSingleRequest { - return nil, fmt.Errorf("unmapping for IP %v already requested", req.GetIp()) - } - delete(mock.endpoints, req.GetIp()) - return &ipam.UnmapResponse{}, nil -} - -// IsEndpointTranslated returns whether the given endpoint has a valid translation. -func (mock *IPAMClient) IsEndpointTranslated(ip string) bool { - _, found := mock.endpoints[ip] - return found -} - -// GetHomePodIP mocks the corresponding IPAMClient function. -func (mock *IPAMClient) GetHomePodIP(_ context.Context, req *ipam.GetHomePodIPRequest, _ ...grpc.CallOption) (*ipam.GetHomePodIPResponse, error) { - // Check first if the translation has already been computed. - if translation, found := mock.pods[req.GetIp()]; found { - if mock.enforceSingleRequest { - return nil, fmt.Errorf("mapping for IP %v already requested", req.GetIp()) - } - return &ipam.GetHomePodIPResponse{HomeIP: translation}, nil - } - - homeIP, err := ipamutils.MapIPToNetwork(mock.remoteRemappedPodCIDR, req.GetIp()) - if err != nil { - return nil, err - } - mock.pods[req.GetIp()] = homeIP - return &ipam.GetHomePodIPResponse{HomeIP: homeIP}, nil -} - -// BelongsToPodCIDR mocks the corresponding IPAMClient function. -func (mock *IPAMClient) BelongsToPodCIDR(context.Context, *ipam.BelongsRequest, - ...grpc.CallOption) (*ipam.BelongsResponse, error) { - return &ipam.BelongsResponse{Belongs: true}, nil -} - -// MapNetworkCIDR mocks the corresponding IPAMClient function. -func (mock *IPAMClient) MapNetworkCIDR(_ context.Context, req *ipam.MapCIDRRequest, _ ...grpc.CallOption) (*ipam.MapCIDRResponse, error) { - return &ipam.MapCIDRResponse{Cidr: req.GetCidr()}, nil -} - -// UnmapNetworkCIDR mocks the corresponding IPAMClient function. -func (mock *IPAMClient) UnmapNetworkCIDR(_ context.Context, _ *ipam.UnmapCIDRRequest, _ ...grpc.CallOption) (*ipam.UnmapCIDRResponse, error) { - return &ipam.UnmapCIDRResponse{}, nil -} - -// GetOrSetExternalCIDR mocks the corresponding IPAMClient function. -func (mock *IPAMClient) GetOrSetExternalCIDR(_ context.Context, req *ipam.GetOrSetExtCIDRRequest, - _ ...grpc.CallOption) (*ipam.GetOrSetExtCIDRResponse, error) { - return &ipam.GetOrSetExtCIDRResponse{RemappedExtCIDR: req.DesiredExtCIDR}, nil -} - -// SetSubnetsPerCluster mocks the corresponding IPAMClient function. -func (mock *IPAMClient) SetSubnetsPerCluster(_ context.Context, _ *ipam.SetSubnetsPerClusterRequest, - _ ...grpc.CallOption) (*ipam.SetSubnetsPerClusterResponse, error) { - return &ipam.SetSubnetsPerClusterResponse{}, nil -} diff --git a/pkg/ipamold/flags.go b/pkg/ipamold/flags.go deleted file mode 100644 index 5aed2ba0b3..0000000000 --- a/pkg/ipamold/flags.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ipam - -import ( - "time" - - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -// FlagName is the type for the name of the flags. -type FlagName string - -func (fn FlagName) String() string { - return string(fn) -} - -const ( - // FlagNamePodCIDR is the podCIDR of the cluster. - FlagNamePodCIDR FlagName = "pod-cidr" - // FlagNameServiceCIDR is the serviceCIDR of the cluster. - FlagNameServiceCIDR FlagName = "service-cidr" - // FlagNameReservedPools contains the reserved network cidr of the cluster. - FlagNameReservedPools FlagName = "reserved-pools" - // FlagNameAdditionalPools contains additional network cidr used to map a cluster network into another one. - FlagNameAdditionalPools FlagName = "additional-pools" - - // FlagNameLeaseEnabled is the flag to enable the lease for the IPAM pods. - FlagNameLeaseEnabled FlagName = "lease-enabled" - // FlagNameLeaseDuration is the duration that non-leader candidates will wait to force acquire leadership. - FlagNameLeaseDuration FlagName = "lease-duration" - // FlagNameLeaseRenewDeadline is the duration that the acting master will retry refreshing leadership before giving up. - FlagNameLeaseRenewDeadline FlagName = "lease-renew-interval" - // FlagNameLeaseRetryPeriod is the duration the LeaderElector clients should wait between tries of actions. - FlagNameLeaseRetryPeriod FlagName = "lease-retry-period" - // FlagNameLabelLeader is the flag to enable the label of the leader node. - FlagNameLabelLeader FlagName = "label-leader" -) - -// RequiredFlags contains the list of the mandatory flags. -var RequiredFlags = []FlagName{ - FlagNamePodCIDR, - FlagNameServiceCIDR, -} - -// InitFlags initializes the flags for the Options struct. -func InitFlags(flagset *pflag.FlagSet, o *Options) { - flagset.Var(&o.PodCIDR, FlagNamePodCIDR.String(), "The subnet used by the cluster for the pods, in CIDR notation") - flagset.Var(&o.ServiceCIDR, FlagNameServiceCIDR.String(), "The subnet used by the cluster for the pods, in services notation") - flagset.Var(&o.ReservedPools, FlagNameReservedPools.String(), - "Private CIDRs slices used by the Kubernetes infrastructure, in addition to the pod and service CIDR (e.g., the node subnet).") - flagset.Var(&o.AdditionalPools, FlagNameAdditionalPools.String(), - "Network pools used to map a cluster network into another one in order to prevent conflicts, in addition to standard private CIDRs.") - - flagset.BoolVar(&o.LeaseEnabled, FlagNameLeaseEnabled.String(), false, - "Enable the lease for the IPAM pods. Disabling it will disable IPAM high-availability.") - flagset.DurationVar(&o.LeaseDuration, FlagNameLeaseDuration.String(), 15*time.Second, - "The duration that non-leader candidates will wait to force acquire leadership.") - flagset.DurationVar(&o.LeaseRenewDeadline, FlagNameLeaseRenewDeadline.String(), 10*time.Second, - "The duration that the acting master will retry refreshing leadership before giving up.") - flagset.DurationVar(&o.LeaseRetryPeriod, FlagNameLeaseRetryPeriod.String(), 5*time.Second, - "The duration the LeaderElector clients should wait between tries of actions.") - flagset.BoolVar(&o.LabelLeader, FlagNameLabelLeader.String(), true, - "Label the leader node.") -} - -// MarkFlagsRequired marks the flags as required. -func MarkFlagsRequired(cmd *cobra.Command, _ *Options) error { - for _, flag := range RequiredFlags { - if err := cmd.MarkFlagRequired(flag.String()); err != nil { - return err - } - } - return nil -} diff --git a/pkg/ipamold/ipam.go b/pkg/ipamold/ipam.go deleted file mode 100644 index 46ad253dcd..0000000000 --- a/pkg/ipamold/ipam.go +++ /dev/null @@ -1,1250 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ipam - -import ( - "context" - "errors" - "fmt" - "net" - "net/netip" - "slices" - "strings" - "sync" - - goipam "github.com/metal-stack/go-ipam" - "go4.org/netipx" - grpc "google.golang.org/grpc" - "google.golang.org/grpc/health" - "google.golang.org/grpc/health/grpc_health_v1" - "k8s.io/client-go/dynamic" - "k8s.io/klog/v2" - - ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" - "github.com/liqotech/liqo/pkg/consts" - ipamerrors "github.com/liqotech/liqo/pkg/ipamold/errors" - ipamutils "github.com/liqotech/liqo/pkg/ipamold/utils" - utils "github.com/liqotech/liqo/pkg/utils/ipam" -) - -// Ipam Interface. -type Ipam interface { - // AcquireReservedSubnet reserves a network. - AcquireReservedSubnet(network string) error - // FreeReservedSubnet frees a network. - FreeReservedSubnet(network string) error - // AddNetworkPool adds a network to the set of default network pools. - AddNetworkPool(network string) error - // RemoveNetworkPool removes a network from the set of network pools. - RemoveNetworkPool(network string) error - // GetExternalCIDR chooses and returns the local cluster's ExternalCIDR. - GetExternalCIDR(mask uint8) (string, error) - // SetPodCIDR sets the cluster PodCIDR. - SetPodCIDR(podCIDR string) error - // SetServiceCIDR sets the cluster ServiceCIDR. - SetServiceCIDR(serviceCIDR string) error - // Terminate function enforces a graceful termination of the IPAM module. - Terminate() - IpamServer -} - -// IPAM implementation. -type IPAM struct { - ipam goipam.Ipamer - ipamStorage IpamStorage - grpcServer *grpc.Server - mutex sync.Mutex - UnimplementedIpamServer -} - -// NewIPAM returns a IPAM instance. -func NewIPAM() *IPAM { - return &IPAM{} -} - -// Pools is a constant slice containing private IPv4 networks. -var Pools = []string{ - "10.0.0.0/8", - "192.168.0.0/16", - "172.16.0.0/12", -} - -const emptyCIDR = "" - -// Init uses the Ipam resource to retrieve and allocate reserved networks. -func (liqoIPAM *IPAM) Init(pools []string, dynClient dynamic.Interface, namespace string) error { - var err error - // Set up storage - liqoIPAM.ipamStorage, err = NewIPAMStorage(dynClient, namespace) - if err != nil { - return fmt.Errorf("cannot set up storage for ipam: %w", err) - } - liqoIPAM.ipam = goipam.NewWithStorage(liqoIPAM.ipamStorage) - - // Get resource - ipamPools := liqoIPAM.ipamStorage.getPools() - - // Have network pools been already set? If not, take them from caller - if len(ipamPools) == 0 { - for _, network := range pools { - if _, err := liqoIPAM.ipam.NewPrefix(context.TODO(), network); err != nil { - return fmt.Errorf("failed to create a new prefix for network %s: %w", network, err) - } - ipamPools = append(ipamPools, network) - klog.Infof("Pool %s has been successfully added to the pool list", network) - } - err = liqoIPAM.ipamStorage.updatePools(ipamPools) - if err != nil { - return fmt.Errorf("cannot set pools: %w", err) - } - } - - return nil -} - -// Serve starts the gRPC server. -func (liqoIPAM *IPAM) Serve(listeningPort int) error { - if listeningPort <= 0 { - return fmt.Errorf("IPAM gRPC server not started: invalid listening port %d", listeningPort) - } - - if err := liqoIPAM.initRPCServer(listeningPort); err != nil { - return fmt.Errorf("cannot start gRPC server: %w", err) - } - - klog.Infof("IPAM gRPC server listening on port %d", listeningPort) - - return nil -} - -// Terminate function stops the gRPC server. -func (liqoIPAM *IPAM) Terminate() { - // Stop GRPC server - if liqoIPAM.grpcServer != nil { - liqoIPAM.grpcServer.GracefulStop() - klog.Info("IPAM gRPC server gracefully stopped") - } -} - -func (liqoIPAM *IPAM) initRPCServer(port int) error { - lis, err := net.Listen("tcp", fmt.Sprintf("%s%d", "0.0.0.0:", port)) - if err != nil { - return err - } - liqoIPAM.grpcServer = grpc.NewServer() - - // Register health service - hs := health.NewServer() - grpc_health_v1.RegisterHealthServer(liqoIPAM.grpcServer, hs) - - // Register IPAM service - RegisterIpamServer(liqoIPAM.grpcServer, liqoIPAM) - - // Start serving - go func() { - err := liqoIPAM.grpcServer.Serve(lis) - if err != nil { - klog.Error(err) - } - }() - - return nil -} - -// reservePoolInHalves handles the special case in which a network pool has to be entirely reserved -// Since AcquireSpecificChildPrefix would return an error, reservePoolInHalves acquires the two -// halves of the network pool. -func (liqoIPAM *IPAM) reservePoolInHalves(pool string) error { - klog.Infof("Network %s is equal to a network pool, acquiring first half..", pool) - mask := ipamutils.GetMask(pool) - mask++ - _, err := liqoIPAM.ipam.AcquireChildPrefix(context.TODO(), pool, mask) - if err != nil { - return fmt.Errorf("cannot acquire first half of pool %s: %w", pool, err) - } - klog.Infof("Acquiring second half..") - _, err = liqoIPAM.ipam.AcquireChildPrefix(context.TODO(), pool, mask) - if err != nil { - return fmt.Errorf("cannot acquire second half of pool %s: %w", pool, err) - } - klog.Infof("Network %s has successfully been reserved", pool) - return nil -} - -// AcquireReservedSubnet marks as used the network received as parameter. -func (liqoIPAM *IPAM) AcquireReservedSubnet(reservedNetwork string) error { - klog.Infof("Request to reserve network %s has been received", reservedNetwork) - cluster, overlaps, err := liqoIPAM.overlapsWithCluster(reservedNetwork) - if err != nil { - return fmt.Errorf("cannot acquire network %s: %w", reservedNetwork, err) - } - if overlaps { - return fmt.Errorf("network %s cannot be reserved because it overlaps with network of cluster %s", - reservedNetwork, cluster) - } - pool, ok, err := liqoIPAM.getPoolFromNetwork(reservedNetwork) - if err != nil { - return err - } - if ok && reservedNetwork == pool { - return liqoIPAM.reservePoolInHalves(pool) - } - if ok && reservedNetwork != pool { - if _, err := liqoIPAM.ipam.AcquireSpecificChildPrefix(context.TODO(), pool, reservedNetwork); err != nil { - return fmt.Errorf("cannot reserve network %s: %w", reservedNetwork, err) - } - klog.Infof("Network %s has successfully been reserved", reservedNetwork) - return nil - } - if _, err := liqoIPAM.ipam.NewPrefix(context.TODO(), reservedNetwork); err != nil { - return fmt.Errorf("cannot reserve network %s: %w", reservedNetwork, err) - } - klog.Infof("Network %s has successfully been reserved.", reservedNetwork) - return nil -} - -// MarkAsAcquiredReservedSubnet marks as used the network received as parameter. -func (liqoIPAM *IPAM) MarkAsAcquiredReservedSubnet(reservedNetwork string) error { - klog.Infof("Request to reserve network %s has been received", reservedNetwork) - - pool, ok, err := liqoIPAM.getPoolFromNetwork(reservedNetwork) - if err != nil { - return err - } - if ok && reservedNetwork == pool { - klog.Infof("reserving subnet %s in two halves...", reservedNetwork) - for _, half := range ipamutils.SplitNetwork(reservedNetwork) { - if !liqoIPAM.isAcquired(half) { - if _, err := liqoIPAM.ipam.AcquireSpecificChildPrefix(context.TODO(), pool, half); err != nil { - return fmt.Errorf("cannot reserve network %s: %w", reservedNetwork, err) - } - } - klog.Infof("half %s for subnet %s successfully acquired", half, reservedNetwork) - } - } - if ok && reservedNetwork != pool { - if !liqoIPAM.isAcquired(reservedNetwork) { - if _, err := liqoIPAM.ipam.AcquireSpecificChildPrefix(context.TODO(), pool, reservedNetwork); err != nil { - return fmt.Errorf("cannot reserve network %s: %w", reservedNetwork, err) - } - } - klog.Infof("Network %s has successfully been reserved", reservedNetwork) - return nil - } - if !liqoIPAM.isAcquired(reservedNetwork) { - if _, err := liqoIPAM.ipam.NewPrefix(context.TODO(), reservedNetwork); err != nil { - return fmt.Errorf("cannot reserve network %s: %w", reservedNetwork, err) - } - } - klog.Infof("Network %s has successfully been reserved.", reservedNetwork) - return nil -} - -func (liqoIPAM *IPAM) overlapsWithNetwork(newNetwork, network string) (overlaps bool, err error) { - if network == "" { - return - } - if err = goipam.PrefixesOverlapping([]string{network}, []string{newNetwork}); err != nil && strings.Contains(err.Error(), "overlaps") { - // overlaps - overlaps = true - err = nil - return - } - return -} - -func (liqoIPAM *IPAM) overlapsWithCluster(network string) (overlappingCluster string, overlaps bool, err error) { - var overlapsWithPodCIDR bool - var overlapsWithExternalCIDR bool - // Get cluster subnets - clusterSubnets := liqoIPAM.ipamStorage.getClusterSubnets() - for cluster, subnets := range clusterSubnets { - overlapsWithPodCIDR, err = liqoIPAM.overlapsWithNetwork(network, subnets.RemotePodCIDR) - if err != nil { - return - } - overlapsWithExternalCIDR, err = liqoIPAM.overlapsWithNetwork(network, subnets.RemoteExternalCIDR) - if err != nil { - return - } - if overlapsWithPodCIDR || overlapsWithExternalCIDR { - overlaps = true - overlappingCluster = cluster - return - } - } - return overlappingCluster, overlaps, err -} - -func (liqoIPAM *IPAM) overlapsWithPool(network string) (overlappingPool string, overlaps bool, err error) { - // Get resource - pools := liqoIPAM.ipamStorage.getPools() - for _, pool := range pools { - overlaps, err = liqoIPAM.overlapsWithNetwork(network, pool) - if err != nil { - return - } - if overlaps { - overlappingPool = pool - return - } - } - return -} - -func (liqoIPAM *IPAM) overlapsWithReserved(network string) (overlappingReserved string, overlaps bool, err error) { - reserved := liqoIPAM.ipamStorage.getReservedSubnets() - for _, r := range reserved { - if overlaps, err = liqoIPAM.overlapsWithNetwork(network, r); err != nil { - return - } - - if overlaps { - overlappingReserved = r - return - } - } - return -} - -// hasBeenAcquired checks for a given network if it has been acquired by checking if a prefix equal to -// the network exists. -func (liqoIPAM *IPAM) isAcquired(network string) bool { - if p := liqoIPAM.ipam.PrefixFrom(context.TODO(), network); p != nil { - return true - } - return false -} - -// Function that receives a network as parameter and returns the pool to which this network belongs to. -func (liqoIPAM *IPAM) getPoolFromNetwork(network string) (networkPool string, success bool, err error) { - var poolIPset netipx.IPSetBuilder - var c netip.Prefix - // Get resource - pools := liqoIPAM.ipamStorage.getPools() - // Build IPSet for new network - ipprefix, err := netip.ParsePrefix(network) - if err != nil { - return - } - for _, pool := range pools { - // Build IPSet for pool - c, err = netip.ParsePrefix(pool) - if err != nil { - return - } - poolIPset.AddPrefix(c) - // Check if the pool contains network - var ipSet *netipx.IPSet - ipSet, err = poolIPset.IPSet() - if err != nil { - return - } - if ipSet.ContainsPrefix(ipprefix) { - networkPool = pool - success = true - return - } - } - return -} - -func (liqoIPAM *IPAM) clusterSubnetEqualToPool(pool string) (string, error) { - klog.Infof("Network %s is equal to a pool, looking for a mapping..", pool) - mappedNetwork, err := liqoIPAM.getNetworkFromPool(ipamutils.GetMask(pool)) - if err != nil { - klog.Infof("Mapping not found, acquiring the entire network pool..") - err = liqoIPAM.reservePoolInHalves(pool) - if err != nil { - return "", fmt.Errorf("no networks available: %w", err) - } - return pool, nil - } - return mappedNetwork, nil -} - -// MapNetworkCIDR receives a network CIDR and return the network CIDR to use for the remote cluster, -// remapped if necessary. -func (liqoIPAM *IPAM) MapNetworkCIDR(_ context.Context, mapCIDRRequest *MapCIDRRequest) (*MapCIDRResponse, error) { - mappedCIDR, err := liqoIPAM.getOrRemapNetwork(mapCIDRRequest.GetCidr()) - if err != nil { - return &MapCIDRResponse{}, fmt.Errorf("cannot map network CIDR %s: %w", mapCIDRRequest.GetCidr(), err) - } - return &MapCIDRResponse{Cidr: mappedCIDR}, nil -} - -// UnmapNetworkCIDR set the network CIDR as unused. -func (liqoIPAM *IPAM) UnmapNetworkCIDR(_ context.Context, unmapCIDRRequest *UnmapCIDRRequest) (*UnmapCIDRResponse, error) { - err := liqoIPAM.FreeReservedSubnet(unmapCIDRRequest.GetCidr()) - if err != nil { - return &UnmapCIDRResponse{}, fmt.Errorf("cannot unmap network CIDR %s: %w", unmapCIDRRequest.GetCidr(), err) - } - return &UnmapCIDRResponse{}, nil -} - -// GetOrSetExternalCIDR get or set the external CIDR (eventually remapped) for the cluster. -func (liqoIPAM *IPAM) GetOrSetExternalCIDR(ctx context.Context, getOrSetExtCIDRRequest *GetOrSetExtCIDRRequest) (*GetOrSetExtCIDRResponse, error) { - // Get cluster externalCIDR if already set - externalCIDR := liqoIPAM.ipamStorage.getExternalCIDR() - if externalCIDR != "" { - return &GetOrSetExtCIDRResponse{RemappedExtCIDR: externalCIDR}, nil - } - - // ExternalCIDR is not set: allocate a new network (eventually remapped if conflicts are found) - externalCIDR, err := liqoIPAM.getOrRemapNetwork(getOrSetExtCIDRRequest.GetDesiredExtCIDR()) - if err != nil { - return &GetOrSetExtCIDRResponse{}, fmt.Errorf("cannot map external CIDR %s: %w", getOrSetExtCIDRRequest.GetDesiredExtCIDR(), err) - } - - // Update ipamstorage with the new external CIDR - if err := liqoIPAM.ipamStorage.updateExternalCIDR(externalCIDR); err != nil { - _ = liqoIPAM.FreeReservedSubnet(externalCIDR) - return &GetOrSetExtCIDRResponse{}, fmt.Errorf("cannot update external CIDR in the ipam storage: %w", err) - } - - // Acquire the UnknownSourceIP - // It must be the first ip in the externalCIDR - unknownSourceIP, err := utils.GetUnknownSourceIP(externalCIDR) - if err != nil { - return &GetOrSetExtCIDRResponse{}, fmt.Errorf("cannot get the UnknownSourceIP: %w", err) - } - r, err := liqoIPAM.ipam.AcquireSpecificIP(ctx, externalCIDR, unknownSourceIP) - if err != nil { - if !errors.Is(err, goipam.ErrAlreadyAllocated) { - return &GetOrSetExtCIDRResponse{}, fmt.Errorf("cannot acquire the UnknownSourceIP: %w", err) - } - r = &goipam.IP{IP: netip.MustParseAddr(unknownSourceIP)} - } - if r == nil { - return &GetOrSetExtCIDRResponse{}, fmt.Errorf("cannot acquire the UnknownSourceIP: nil response") - } - if r.IP.String() != unknownSourceIP { - return &GetOrSetExtCIDRResponse{}, fmt.Errorf("cannot acquire the UnknownSourceIP: returned %s but expected %s", r.IP.String(), unknownSourceIP) - } - - return &GetOrSetExtCIDRResponse{RemappedExtCIDR: externalCIDR}, nil -} - -// SetSubnetsPerCluster set the remapped PodCIDR and ExternalCIDR for a given Cluster in the IpamStorage. -func (liqoIPAM *IPAM) SetSubnetsPerCluster(_ context.Context, - setSubnetsRequest *SetSubnetsPerClusterRequest) (*SetSubnetsPerClusterResponse, error) { - // Set subnets for the cluster - err := liqoIPAM.SetSubnetsPerClusterInternal(setSubnetsRequest.GetRemappedPodCIDR(), setSubnetsRequest.GetRemappedExternalCIDR(), - setSubnetsRequest.GetClusterID()) - if err != nil { - return &SetSubnetsPerClusterResponse{}, fmt.Errorf("cannot set subnets for cluster %s: %w", setSubnetsRequest.GetClusterID(), err) - } - return &SetSubnetsPerClusterResponse{}, nil -} - -// getOrRemapNetwork first tries to acquire the received network. -// If conflicts are found, a new mapped network is returned. -func (liqoIPAM *IPAM) getOrRemapNetwork(network string) (string, error) { - var mappedNetwork string - klog.Infof("Allocating network %s", network) - // First try to get a new Prefix - _, err := liqoIPAM.ipam.NewPrefix(context.TODO(), network) - - if err != nil && !strings.Contains(err.Error(), "overlaps") { - // Return if get an error that is not an overlapping error - return "", fmt.Errorf("cannot reserve network %s: %w", network, err) - } - if err == nil { - // New Prefix succeeded, return - return network, nil - } - // NewPrefix failed, network overlaps with a network pool or with a reserved network - pool, ok, err := liqoIPAM.getPoolFromNetwork(network) - if err != nil { - return "", err - } - if ok && network == pool { - /* getPodCidr could behave as AcquireReservedSubnet does in this condition, but in this case - is better to look first for a mapping rather than acquire the entire network pool. - Consider the impact of having a network pool n completely filled and multiple clusters asking for - networks in n. This would create the necessity of nat-ting the traffic towards these clusters. */ - mappedNetwork, err = liqoIPAM.clusterSubnetEqualToPool(pool) - if err != nil { - return "", err - } - klog.Infof("Network %s successfully mapped to network %s", network, mappedNetwork) - return mappedNetwork, nil - } - if ok && network != pool { - _, err := liqoIPAM.ipam.AcquireSpecificChildPrefix(context.TODO(), pool, network) - if err != nil && !strings.Contains(err.Error(), "is not available") { - /* Unknown error, return */ - return "", fmt.Errorf("cannot acquire prefix %s from prefix %s: %w", network, pool, err) - } - if err == nil { - return network, nil - } - } - /* Network is already reserved, need a mapping */ - mappedNetwork, err = liqoIPAM.getNetworkFromPool(ipamutils.GetMask(network)) - if err != nil { - return "", err - } - klog.Infof("Network %s successfully mapped to network %s", network, mappedNetwork) - return mappedNetwork, nil -} - -/* -SetSubnetsPerClusterInternal set the remapped PodCIDR and ExternalCIDR for a given Cluster. -*/ -func (liqoIPAM *IPAM) SetSubnetsPerClusterInternal(mappedPodCIDR, mappedExternalCIDR, clusterID string) error { - var exists bool - - // Check if podCidr is a valid CIDR - if err := ipamutils.IsValidCIDR(mappedPodCIDR); err != nil { - return fmt.Errorf("PodCidr is an invalid CIDR: %w", err) - } - - // Check if externalCIDR is a valid CIDR - if err := ipamutils.IsValidCIDR(mappedExternalCIDR); err != nil { - return fmt.Errorf("ExternalCIDR is an invalid CIDR: %w", err) - } - - // Get subnets for the cluster - clusterSubnets := liqoIPAM.ipamStorage.getClusterSubnets() - - // Check if entry is already present and do nothing if CIDRs are the same - subnets, exists := clusterSubnets[clusterID] - if exists && subnets.RemotePodCIDR == mappedPodCIDR && subnets.RemoteExternalCIDR == mappedExternalCIDR { - return nil - } - - // Create or update subnets for the cluster - if !exists { - // Create cluster network configuration - subnets = ipamv1alpha1.Subnets{ - LocalNATPodCIDR: consts.DefaultCIDRValue, - RemotePodCIDR: mappedPodCIDR, - RemoteExternalCIDR: mappedExternalCIDR, - LocalNATExternalCIDR: consts.DefaultCIDRValue, - } - } else { - // Update cluster network configuration - subnets.RemotePodCIDR = mappedPodCIDR - subnets.RemoteExternalCIDR = mappedExternalCIDR - } - clusterSubnets[clusterID] = subnets - - // Push it in clusterSubnets - if err := liqoIPAM.ipamStorage.updateClusterSubnets(clusterSubnets); err != nil { - return fmt.Errorf("cannot update cluster subnets: %w", err) - } - return nil -} - -// getNetworkFromPool returns a network with mask length equal to mask taken by a network pool. -func (liqoIPAM *IPAM) getNetworkFromPool(mask uint8) (string, error) { - // Get network pools - pools := liqoIPAM.ipamStorage.getPools() - // For each pool, try to get a network with mask length mask - for _, pool := range pools { - if mappedNetwork, err := liqoIPAM.ipam.AcquireChildPrefix(context.TODO(), pool, mask); err == nil { - klog.Infof("Acquired network %s", mappedNetwork) - return mappedNetwork.String(), nil - } - } - return "", fmt.Errorf("no networks available") -} - -func (liqoIPAM *IPAM) freePoolInHalves(pool string) error { - var err error - - // Get halves mask length - mask := ipamutils.GetMask(pool) - mask++ - - // Get first half CIDR - halfCidr := ipamutils.SetMask(pool, mask) - - klog.Infof("Network %s is equal to a network pool, freeing first half..", pool) - if prefix := liqoIPAM.ipam.PrefixFrom(context.TODO(), halfCidr); prefix != nil { - err = liqoIPAM.ipam.ReleaseChildPrefix(context.TODO(), prefix) - if err != nil { - return fmt.Errorf("cannot free first half of pool %s", pool) - } - } - - // Get second half CIDR - halfCidr = ipamutils.Next(halfCidr) - if err != nil { - return err - } - klog.Infof("Freeing second half..") - if prefix := liqoIPAM.ipam.PrefixFrom(context.TODO(), halfCidr); prefix != nil { - err = liqoIPAM.ipam.ReleaseChildPrefix(context.TODO(), prefix) - if err != nil { - return fmt.Errorf("cannot free second half of pool %s", pool) - } - } - - klog.Infof("Network %s has successfully been freed", pool) - return nil -} - -// FreeReservedSubnet marks as free a reserved subnet. -func (liqoIPAM *IPAM) FreeReservedSubnet(network string) error { - var p *goipam.Prefix - - // Check existence - if p = liqoIPAM.ipam.PrefixFrom(context.TODO(), network); p == nil { - return nil - } - - // Check if it is equal to a network pool - pool, ok, err := liqoIPAM.getPoolFromNetwork(network) - if err != nil { - return err - } - if ok && pool == network { - return liqoIPAM.freePoolInHalves(pool) - } - - // Try to release it as a child prefix - if err := liqoIPAM.ipam.ReleaseChildPrefix(context.TODO(), p); err != nil { - klog.Infof("Cannot release subnet %s previously allocated from the pools", network) - // It is not a child prefix, then it is a parent prefix, so delete it - if _, err := liqoIPAM.ipam.DeletePrefix(context.TODO(), network); err != nil { - klog.Errorf("Cannot delete prefix %s", network) - return fmt.Errorf("cannot remove subnet %s: %w", network, err) - } - } - klog.Infof("Network %s has just been freed", network) - return nil -} - -// eventuallyDeleteClusterSubnet deletes cluster entry from cluster subnets if all fields are deleted (empty string). -func (liqoIPAM *IPAM) eventuallyDeleteClusterSubnet(clusterID string, - clusterSubnets map[string]ipamv1alpha1.Subnets) error { - // Get entry of cluster - subnets := clusterSubnets[clusterID] - - // Check is all field are the empty string - if subnets.RemotePodCIDR == "" && - subnets.LocalNATPodCIDR == "" && - subnets.RemoteExternalCIDR == "" && - subnets.LocalNATExternalCIDR == "" { - // Delete entry - delete(clusterSubnets, clusterID) - } - // Update - if err := liqoIPAM.ipamStorage.updateClusterSubnets(clusterSubnets); err != nil { - return err - } - return nil -} - -// AddNetworkPool adds a network to the set of network pools. -func (liqoIPAM *IPAM) AddNetworkPool(network string) error { - // Get resource - ipamPools := liqoIPAM.ipamStorage.getPools() - // Check overlapping with existing pools - // Either this and the following checks are carried out also within NewPrefix. - // Perform them here permits a more detailed error description. - pool, overlaps, err := liqoIPAM.overlapsWithPool(network) - if err != nil { - return fmt.Errorf("cannot establish if new network pool overlaps with existing network pools: %w", err) - } - if overlaps { - return fmt.Errorf("cannot add new network pool %s because it overlaps with existing network pool %s", network, pool) - } - // Check overlapping with cluster subnets - cluster, overlaps, err := liqoIPAM.overlapsWithCluster(network) - if err != nil { - return fmt.Errorf("cannot establish if new network pool overlaps with a reserved subnet: %w", err) - } - if overlaps { - return fmt.Errorf("cannot add network pool %s because it overlaps with network of cluster %s", network, cluster) - } - // Add network pool - _, err = liqoIPAM.ipam.NewPrefix(context.TODO(), network) - if err != nil { - return fmt.Errorf("cannot add network pool %s: %w", network, err) - } - ipamPools = append(ipamPools, network) - klog.Infof("Network pool %s added to IPAM", network) - // Update configuration - err = liqoIPAM.ipamStorage.updatePools(ipamPools) - if err != nil { - return fmt.Errorf("cannot update Ipam configuration: %w", err) - } - return nil -} - -// RemoveNetworkPool removes a network from the set of network pools. -func (liqoIPAM *IPAM) RemoveNetworkPool(network string) error { - // Get resource - ipamPools := liqoIPAM.ipamStorage.getPools() - // Get cluster subnets - clusterSubnets := liqoIPAM.ipamStorage.getClusterSubnets() - // Check existence - if exists := slices.Contains(ipamPools, network); !exists { - return fmt.Errorf("network %s is not a network pool", network) - } - // Cannot remove a default one - if contains := slices.Contains(Pools, network); contains { - return fmt.Errorf("cannot remove a default network pool") - } - // Check overlapping with cluster networks - cluster, overlaps, err := liqoIPAM.overlapsWithCluster(network) - if err != nil { - return fmt.Errorf("cannot check if network pool %s overlaps with cluster networks: %w", network, err) - } - if overlaps { - return fmt.Errorf("cannot remove network pool %s because it overlaps with network %s of cluster %s", - network, clusterSubnets[cluster], cluster) - } - // Release it - _, err = liqoIPAM.ipam.DeletePrefix(context.TODO(), network) - if err != nil { - return fmt.Errorf("cannot remove network pool %s: %w", network, err) - } - // Delete it - var i int - for index, value := range ipamPools { - if value == network { - i = index - break - } - } - if i == (len(ipamPools) - 1) { - ipamPools = ipamPools[:len(ipamPools)-1] - } else { - copy(ipamPools[i:], ipamPools[i+1:]) - ipamPools = ipamPools[:len(ipamPools)-1] - } - err = liqoIPAM.ipamStorage.updatePools(ipamPools) - if err != nil { - return fmt.Errorf("cannot update Ipam configuration: %w", err) - } - klog.Infof("Network pool %s has just been removed", network) - return nil -} - -// RemoveLocalSubnetsPerCluster deletes networks related to a cluster. -func (liqoIPAM *IPAM) RemoveLocalSubnetsPerCluster(clusterID string) error { - var exists bool - var subnets ipamv1alpha1.Subnets - - // Get cluster subnets - clusterSubnets := liqoIPAM.ipamStorage.getClusterSubnets() - // Check existence - subnets, exists = clusterSubnets[clusterID] - if !exists || (subnets.LocalNATPodCIDR == "" && subnets.LocalNATExternalCIDR == "") { - return nil - } - - // Unset networks - subnets.LocalNATPodCIDR = "" - subnets.LocalNATExternalCIDR = "" - clusterSubnets[clusterID] = subnets - - klog.Infof("Local NAT networks of cluster %s deleted", clusterID) - if err := liqoIPAM.eventuallyDeleteClusterSubnet(clusterID, clusterSubnets); err != nil { - return err - } - return nil -} - -// GetExternalCIDR chooses and returns the local cluster's ExternalCIDR. -func (liqoIPAM *IPAM) GetExternalCIDR(mask uint8) (string, error) { - var externalCIDR string - var err error - - // Get cluster ExternalCIDR - externalCIDR = liqoIPAM.ipamStorage.getExternalCIDR() - if externalCIDR != "" { - return externalCIDR, nil - } - if externalCIDR, err = liqoIPAM.getNetworkFromPool(mask); err != nil { - return "", fmt.Errorf("cannot allocate an ExternalCIDR: %w", err) - } - if err := liqoIPAM.ipamStorage.updateExternalCIDR(externalCIDR); err != nil { - _ = liqoIPAM.FreeReservedSubnet(externalCIDR) - return "", fmt.Errorf("cannot update ExternalCIDR: %w", err) - } - return externalCIDR, nil -} - -// Function that receives an IP and a network and returns true if -// the IP address does belong to the network. -func ipBelongsToNetwork(ip, network string) (bool, error) { - // Parse network - p, err := netip.ParsePrefix(network) - if err != nil { - return false, fmt.Errorf("cannot parse network: %w", err) - } - return p.Contains(netip.MustParseAddr(ip)), nil -} - -func (liqoIPAM *IPAM) belongsToPodCIDRInternal(ip string) (bool, error) { - if netIP := net.ParseIP(ip); netIP == nil { - return false, &ipamerrors.WrongParameter{ - Reason: ipamerrors.ValidIP, - Parameter: "Endpoint IP", - } - } - - podCIDR := liqoIPAM.ipamStorage.getPodCIDR() - if podCIDR == "" { - return false, fmt.Errorf("the pod CIDR is not set") - } - klog.V(5).Infof("BelongsToPodCIDR(%s): pod CIDR is %s", ip, podCIDR) - - return ipBelongsToNetwork(ip, podCIDR) -} - -// BelongsToPodCIDR tells if the given IP belongs to the remote pod CIDR for the given cluster. -func (liqoIPAM *IPAM) BelongsToPodCIDR(ctx context.Context, belongsRequest *BelongsRequest) (*BelongsResponse, error) { - belongs, err := liqoIPAM.belongsToPodCIDRInternal(belongsRequest.GetIp()) - if err != nil { - return &BelongsResponse{}, fmt.Errorf("cannot tell if IP %s is in pod CIDR: %w", belongsRequest.GetIp(), err) - } - return &BelongsResponse{Belongs: belongs}, nil -} - -/* - mapIPToExternalCIDR acquires an IP belonging to the local ExternalCIDR for the specific IP and - -if necessary maps it using the remoteExternalCIDR (this means remote cluster has remapped local ExternalCIDR) -Further invocations passing the same IP won't acquire a new IP, but will use the one already acquired. -*/ -func (liqoIPAM *IPAM) mapIPToExternalCIDR(clusterID, remoteExternalCIDR, ip string) (string, error) { - var externalCIDR string - // Get endpointMappings - endpointMappings := liqoIPAM.ipamStorage.getEndpointMappings() - - // Get local ExternalCIDR - localExternalCIDR := liqoIPAM.ipamStorage.getExternalCIDR() - - if remoteExternalCIDR == consts.DefaultCIDRValue { - externalCIDR = localExternalCIDR - } else { - externalCIDR = remoteExternalCIDR - } - - // Check entry existence - if _, exists := endpointMappings[ip]; !exists { - // Create new entry - ipamIP, err := liqoIPAM.ipam.AcquireIP(context.TODO(), localExternalCIDR) - if err != nil { - return "", fmt.Errorf("cannot allocate a new IP for endpoint %s: %w", ip, err) - } - endpointMappings[ip] = ipamv1alpha1.EndpointMapping{ - ExternalCIDROriginalIP: ipamIP.IP.String(), - ClusterMappings: make(map[string]ipamv1alpha1.ClusterMapping), - } - klog.Infof("%s has been acquired for endpoint %s", endpointMappings[ip].ExternalCIDROriginalIP, ip) - } - - if _, exists := endpointMappings[ip].ClusterMappings[clusterID]; !exists { - // Map IP if remote cluster has remapped local ExternalCIDR - externalCIDRNattedIP, err := ipamutils.MapIPToNetwork(externalCIDR, endpointMappings[ip].ExternalCIDROriginalIP) - if err != nil { - return "", fmt.Errorf("cannot map IP %s to network %s: %w", endpointMappings[ip].ExternalCIDROriginalIP, externalCIDR, err) - } - - // setup clusterMappings - endpointMappings[ip].ClusterMappings[clusterID] = ipamv1alpha1.ClusterMapping{ExternalCIDRNattedIP: externalCIDRNattedIP} - klog.Infof("Endpoint %s has been remapped as %s", ip, externalCIDRNattedIP) - - // Update endpointMappings - if err := liqoIPAM.ipamStorage.updateEndpointMappings(endpointMappings); err != nil { - return "", fmt.Errorf("cannot update endpointMappings: %w", err) - } - } - - return endpointMappings[ip].ClusterMappings[clusterID].ExternalCIDRNattedIP, nil -} - -/* - mapEndpointIPInternal is the internal implementation of MapEndpointIP gRPC. - -If the received IP belongs to local PodCIDR, then it maps the address in the traditional way, -i.e. using the network used in the remote cluster for local PodCIDR. -If the received IP does not belong to local PodCIDR, then it maps the address using the ExternalCIDR. -*/ -func (liqoIPAM *IPAM) mapEndpointIPInternal(clusterID, ip string) (string, error) { - var subnets ipamv1alpha1.Subnets - var exists bool - - err := validateEndpointMappingInputs(clusterID, ip) - if err != nil { - return "", err - } - - liqoIPAM.mutex.Lock() - defer liqoIPAM.mutex.Unlock() - - // Get cluster subnets - clusterSubnets := liqoIPAM.ipamStorage.getClusterSubnets() - subnets, exists = clusterSubnets[clusterID] - if !exists { - return "", fmt.Errorf("cluster %s has not a network configuration", clusterID) - } - - // Get PodCIDR - podCIDR := liqoIPAM.ipamStorage.getPodCIDR() - if podCIDR == emptyCIDR { - return "", fmt.Errorf("cannot get cluster PodCIDR: %w", err) - } - - belongs, err := ipBelongsToNetwork(ip, podCIDR) - if err != nil { - return "", fmt.Errorf("cannot establish if IP %s belongs to PodCIDR: %w", ip, err) - } - if belongs { - klog.V(5).Infof("MapEndpointIP(%s, %s): ip is in pod CIDR %s, mapping to LocalNATPodCIDR %s", - ip, clusterID, podCIDR, subnets.LocalNATPodCIDR) - - /* IP belongs to local PodCIDR, this means the Pod is a local Pod and - the new IP should belong to the network used in the remote cluster - for local Pods: this can be either the cluster PodCIDR or a different network */ - newIP, err := ipamutils.MapIPToNetwork(subnets.LocalNATPodCIDR, ip) - if err != nil { - return "", fmt.Errorf("cannot map endpoint IP %s to PodCIDR of remote cluster %s: %w", ip, clusterID, err) - } - return newIP, nil - } - // IP does not belong to cluster PodCIDR: Pod is a reflected Pod - klog.V(5).Infof("MapEndpointIP(%s, %s): ip is not in pod CIDR %s, mapping to LocalNATExternalCIDR %s", - ip, clusterID, podCIDR, subnets.LocalNATExternalCIDR) - - // Map IP to ExternalCIDR - newIP, err := liqoIPAM.mapIPToExternalCIDR(clusterID, subnets.LocalNATExternalCIDR, ip) - if err != nil { - return "", fmt.Errorf("cannot map endpoint IP %s to ExternalCIDR of cluster %s: %w", ip, clusterID, err) - } - - return newIP, nil -} - -// MapEndpointIP receives a service endpoint IP and a cluster identifier and, -// if the endpoint IP does not belong to cluster PodCIDR, maps -// the endpoint IP to a new IP taken from the remote ExternalCIDR of the remote cluster. -func (liqoIPAM *IPAM) MapEndpointIP(_ context.Context, mapRequest *MapRequest) (*MapResponse, error) { - mappedIP, err := liqoIPAM.mapEndpointIPInternal(mapRequest.GetClusterID(), mapRequest.GetIp()) - if err != nil { - return &MapResponse{}, fmt.Errorf("cannot map endpoint IP to ExternalCIDR of cluster %s, %w", - mapRequest.GetClusterID(), err) - } - return &MapResponse{Ip: mappedIP}, nil -} - -func validateEndpointMappingInputs(clusterID, ip string) error { - const emptyClusterID = "" - // Parse IP - if netIP := net.ParseIP(ip); netIP == nil { - return &ipamerrors.WrongParameter{ - Reason: ipamerrors.ValidIP, - Parameter: "Endpoint IP", - } - } - - if clusterID == emptyClusterID { - return &ipamerrors.WrongParameter{ - Reason: ipamerrors.StringNotEmpty, - Parameter: consts.ClusterIDLabelName, - } - } - return nil -} - -// GetHomePodIP receives a Pod IP valid in the remote cluster and returns the corresponding home Pod IP -// (i.e. with validity in home cluster). -func (liqoIPAM *IPAM) GetHomePodIP(ctx context.Context, request *GetHomePodIPRequest) (*GetHomePodIPResponse, error) { - homeIP, err := liqoIPAM.getHomePodIPInternal(request.GetClusterID(), request.GetIp()) - if err != nil { - return &GetHomePodIPResponse{}, fmt.Errorf("cannot get home Pod IP starting from IP %s: %w", - request.GetIp(), err) - } - return &GetHomePodIPResponse{HomeIP: homeIP}, nil -} - -// Internal implementation of exported func GetHomePodIP. -func (liqoIPAM *IPAM) getHomePodIPInternal(clusterID, ip string) (string, error) { - if clusterID == "" { - return "", &ipamerrors.WrongParameter{ - Parameter: consts.ClusterIDLabelName, - Reason: ipamerrors.StringNotEmpty, - } - } - if parsedIP := net.ParseIP(ip); parsedIP == nil { - return "", &ipamerrors.WrongParameter{ - Reason: ipamerrors.ValidIP, - Parameter: ip, - } - } - - liqoIPAM.mutex.Lock() - defer liqoIPAM.mutex.Unlock() - - // Get cluster subnets - clusterSubnets := liqoIPAM.ipamStorage.getClusterSubnets() - subnets, exists := clusterSubnets[clusterID] - - // Check if RemotePodCIDR is set - if !exists { - return "", fmt.Errorf("cluster %s subnets are not set", clusterID) - } - - if subnets.RemotePodCIDR == "" { - return "", &ipamerrors.WrongParameter{ - Reason: ipamerrors.StringNotEmpty, - } - } - - klog.V(5).Infof("GetHomePodIP(%s, %s): mapping to RemotePodCIDR %s", - ip, clusterID, subnets.RemotePodCIDR) - return ipamutils.MapIPToNetwork(subnets.RemotePodCIDR, ip) -} - -// unmapEndpointIPInternal is the internal implementation of UnmapEndpointIP. -// If the endpointIP is not reflected anymore in any remote cluster, then it frees the corresponding ExternalCIDR IP. -func (liqoIPAM *IPAM) unmapEndpointIPInternal(clusterID, endpointIP string) error { - var exists bool - - err := validateEndpointMappingInputs(clusterID, endpointIP) - if err != nil { - return err - } - - liqoIPAM.mutex.Lock() - defer liqoIPAM.mutex.Unlock() - - // Get endpointMappings - endpointMappings := liqoIPAM.ipamStorage.getEndpointMappings() - - // Get local ExternalCIDR - localExternalCIDR := liqoIPAM.ipamStorage.getExternalCIDR() - if localExternalCIDR == emptyCIDR { - return fmt.Errorf("cannot get ExternalCIDR: %w", err) - } - - endpointMapping, exists := endpointMappings[endpointIP] - if !exists { - // a. the entry does not exists because the endpointIP is an IP - // belonging to the local PodCIDR, therefore there is no need of do nothing. - // b. the entry does not exists because it was already deleted, same as above. - return nil - } - - klog.Infof("endpoint IP %s: removed %s for cluster %s", endpointIP, endpointMapping.ClusterMappings[clusterID].ExternalCIDRNattedIP, clusterID) - delete(endpointMapping.ClusterMappings, clusterID) - - if len(endpointMapping.ClusterMappings) == 0 { - // Free IP - err = liqoIPAM.ipam.ReleaseIPFromPrefix(context.TODO(), localExternalCIDR, endpointMapping.ExternalCIDROriginalIP) - if err != nil && !errors.Is(err, goipam.ErrNotFound) { - /* - ReleaseIPFromPrefix can return ErrNotFound either if the prefix - is not found and if the IP is not allocated. - Since the prefix represents the ExternalCIDR, whose existence has - been checked some lines above, ReleaseIPFromPrefix returns - ErrNotFound if the IP has not been allocated or has already been freed. - */ - return fmt.Errorf("cannot free IP: %w", err) - } - if err == nil { - klog.Infof("IP %s (mapped from %s) has been freed", endpointMapping.ExternalCIDROriginalIP, endpointIP) - } - - delete(endpointMappings, endpointIP) - } else { - endpointMappings[endpointIP] = endpointMapping - } - - // Push update - if err := liqoIPAM.ipamStorage.updateEndpointMappings(endpointMappings); err != nil { - return fmt.Errorf("cannot update endpointIPs: %w", err) - } - - return nil -} - -// UnmapEndpointIP set the endpoint as unused for a specific cluster. -func (liqoIPAM *IPAM) UnmapEndpointIP(ctx context.Context, unmapRequest *UnmapRequest) (*UnmapResponse, error) { - err := liqoIPAM.unmapEndpointIPInternal(unmapRequest.GetClusterID(), unmapRequest.GetIp()) - if err != nil { - return &UnmapResponse{}, fmt.Errorf("cannot unmap the IP of endpoint %s: %w", unmapRequest.GetIp(), err) - } - return &UnmapResponse{}, nil -} - -// SetPodCIDR sets the PodCIDR. -func (liqoIPAM *IPAM) SetPodCIDR(podCIDR string) error { - // Get PodCIDR - oldPodCIDR := liqoIPAM.ipamStorage.getPodCIDR() - if oldPodCIDR != "" && oldPodCIDR != podCIDR { - return fmt.Errorf("trying to change PodCIDR") - } - if oldPodCIDR != "" && oldPodCIDR == podCIDR { - return nil - } - // Acquire PodCIDR - if err := liqoIPAM.AcquireReservedSubnet(podCIDR); err != nil { - return fmt.Errorf("cannot acquire PodCIDR: %w", err) - } - // Update PodCIDR - if err := liqoIPAM.ipamStorage.updatePodCIDR(podCIDR); err != nil { - return fmt.Errorf("cannot set PodCIDR: %w", err) - } - return nil -} - -// SetServiceCIDR sets the ServiceCIDR. -func (liqoIPAM *IPAM) SetServiceCIDR(serviceCIDR string) error { - // Get ServiceCIDR - oldServiceCIDR := liqoIPAM.ipamStorage.getServiceCIDR() - if oldServiceCIDR != "" && oldServiceCIDR != serviceCIDR { - return fmt.Errorf("trying to change ServiceCIDR") - } - if oldServiceCIDR != "" && oldServiceCIDR == serviceCIDR { - return nil - } - // Acquire Service CIDR - if err := liqoIPAM.AcquireReservedSubnet(serviceCIDR); err != nil { - return fmt.Errorf("cannot acquire ServiceCIDR: %w", err) - } - // Update Service CIDR - if err := liqoIPAM.ipamStorage.updateServiceCIDR(serviceCIDR); err != nil { - return fmt.Errorf("cannot set ServiceCIDR: %w", err) - } - return nil -} - -// SetReservedSubnets acquires and/or frees the reserved networks. -func (liqoIPAM *IPAM) SetReservedSubnets(subnets []string) error { - reserved := liqoIPAM.ipamStorage.getReservedSubnets() - - // Free all the reserved networks not needed anymore. - for _, r := range reserved { - if !slices.Contains(subnets, r) { - klog.Infof("freeing old reserved subnet %s", r) - if err := liqoIPAM.FreeReservedSubnet(r); err != nil { - return fmt.Errorf("an error occurred while freeing reserved subnet {%s}: %w", r, err) - } - if err := liqoIPAM.ipamStorage.updateReservedSubnets(r, updateOpRemove); err != nil { - return err - } - } - } - // Get the reserved subnets after we have freed the old ones. - reserved = liqoIPAM.ipamStorage.getReservedSubnets() - - // Enforce the reserved subnets. Being the reservation a two-step process, - // it could happen that a subnet is added to the reserved list but not - // reserved due to an error. So we make sure that all the subnets in the - // reserved list have been acquired. - // We are sure that if a reserved network has been added to the reserved list - // the prefix for that network is free or has been already acquired on behalf - // of the current reserved network. - for _, rSubnet := range reserved { - if err := liqoIPAM.MarkAsAcquiredReservedSubnet(rSubnet); err != nil { - return fmt.Errorf("an error occurred while enforcing reserved subnet {%s}: %w", rSubnet, err) - } - } - - // Reserve the newly added subnets. - for _, s := range subnets { - if slices.Contains(reserved, s) { - continue - } - klog.Infof("acquiring reserved subnet %s", s) - // Check if the subnet does not overlap with the existing reserved subnets. - if err := liqoIPAM.reservedSubnetOverlaps(s); err != nil { - return err - } - - if err := liqoIPAM.ipamStorage.updateReservedSubnets(s, updateOpAdd); err != nil { - return err - } - if err := liqoIPAM.MarkAsAcquiredReservedSubnet(s); err != nil { - return fmt.Errorf("an error occurred while reserving subnet {%s}: %w", s, err) - } - } - return nil -} - -func (liqoIPAM *IPAM) reservedSubnetOverlaps(subnet string) error { - // Check if subnet overlaps with local pod CIDR. - podCidr := liqoIPAM.ipamStorage.getPodCIDR() - overlaps, err := liqoIPAM.overlapsWithNetwork(subnet, podCidr) - if err != nil { - return err - } - if overlaps { - return fmt.Errorf("network %s cannot be reserved because it overlaps with the local podCIDR %s", - subnet, podCidr) - } - - // Check if subnet overlaps with local service CIDR. - serviceCidr := liqoIPAM.ipamStorage.getServiceCIDR() - overlaps, err = liqoIPAM.overlapsWithNetwork(subnet, serviceCidr) - if err != nil { - return err - } - if overlaps { - return fmt.Errorf("network %s cannot be reserved because it overlaps with the local serviceCIDR %s", - subnet, serviceCidr) - } - - // Check if subnet overlaps with local external CIDR. - externalCidr := liqoIPAM.ipamStorage.getExternalCIDR() - overlaps, err = liqoIPAM.overlapsWithNetwork(subnet, externalCidr) - if err != nil { - return err - } - if overlaps { - return fmt.Errorf("network %s cannot be reserved because it overlaps with the local external CIDR %s", - subnet, externalCidr) - } - - // Check if the subnet does not overlap with the existing reserved subnets. - overlappingNet, overlaps, err := liqoIPAM.overlapsWithReserved(subnet) - if err != nil { - return err - } - if overlaps { - return fmt.Errorf("network %s cannot be reserved because it overlaps with the reserved network %s", - subnet, overlappingNet) - } - - // Check if the subnet does not overlap wit the existing cluster subnets. - overlappingNet, overlaps, err = liqoIPAM.overlapsWithCluster(subnet) - if err != nil { - return err - } - if overlaps { - return fmt.Errorf("network %s cannot be reserved because it overlaps with the reserved network %s", - subnet, overlappingNet) - } - - return nil -} - -// AcquireSpecificIP acquires the first IP in the given subnet and return it. -// This function returns nil if the IP is already acquired. -func (liqoIPAM *IPAM) AcquireSpecificIP(ip, subnet string) error { - r, err := liqoIPAM.ipam.AcquireSpecificIP(context.Background(), subnet, ip) - if err != nil && r != nil { - return err - } - return nil -} diff --git a/pkg/ipamold/ipam.pb.go b/pkg/ipamold/ipam.pb.go deleted file mode 100644 index 1d464838a0..0000000000 --- a/pkg/ipamold/ipam.pb.go +++ /dev/null @@ -1,925 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.3 -// source: pkg/ipamold/ipam.proto - -package ipam - -import ( - reflect "reflect" - sync "sync" - - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type MapRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ClusterID string `protobuf:"bytes,1,opt,name=clusterID,proto3" json:"clusterID,omitempty"` - Ip string `protobuf:"bytes,2,opt,name=ip,proto3" json:"ip,omitempty"` -} - -func (x *MapRequest) Reset() { - *x = MapRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *MapRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MapRequest) ProtoMessage() {} - -func (x *MapRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[0] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MapRequest.ProtoReflect.Descriptor instead. -func (*MapRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{0} -} - -func (x *MapRequest) GetClusterID() string { - if x != nil { - return x.ClusterID - } - return "" -} - -func (x *MapRequest) GetIp() string { - if x != nil { - return x.Ip - } - return "" -} - -type MapResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` -} - -func (x *MapResponse) Reset() { - *x = MapResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *MapResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MapResponse) ProtoMessage() {} - -func (x *MapResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[1] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MapResponse.ProtoReflect.Descriptor instead. -func (*MapResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{1} -} - -func (x *MapResponse) GetIp() string { - if x != nil { - return x.Ip - } - return "" -} - -type UnmapRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ClusterID string `protobuf:"bytes,1,opt,name=clusterID,proto3" json:"clusterID,omitempty"` - Ip string `protobuf:"bytes,2,opt,name=ip,proto3" json:"ip,omitempty"` -} - -func (x *UnmapRequest) Reset() { - *x = UnmapRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *UnmapRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UnmapRequest) ProtoMessage() {} - -func (x *UnmapRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[2] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UnmapRequest.ProtoReflect.Descriptor instead. -func (*UnmapRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{2} -} - -func (x *UnmapRequest) GetClusterID() string { - if x != nil { - return x.ClusterID - } - return "" -} - -func (x *UnmapRequest) GetIp() string { - if x != nil { - return x.Ip - } - return "" -} - -type UnmapResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *UnmapResponse) Reset() { - *x = UnmapResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *UnmapResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UnmapResponse) ProtoMessage() {} - -func (x *UnmapResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[3] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UnmapResponse.ProtoReflect.Descriptor instead. -func (*UnmapResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{3} -} - -type MapCIDRRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Cidr string `protobuf:"bytes,1,opt,name=cidr,proto3" json:"cidr,omitempty"` -} - -func (x *MapCIDRRequest) Reset() { - *x = MapCIDRRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *MapCIDRRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MapCIDRRequest) ProtoMessage() {} - -func (x *MapCIDRRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[4] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MapCIDRRequest.ProtoReflect.Descriptor instead. -func (*MapCIDRRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{4} -} - -func (x *MapCIDRRequest) GetCidr() string { - if x != nil { - return x.Cidr - } - return "" -} - -type MapCIDRResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Cidr string `protobuf:"bytes,1,opt,name=cidr,proto3" json:"cidr,omitempty"` -} - -func (x *MapCIDRResponse) Reset() { - *x = MapCIDRResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *MapCIDRResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MapCIDRResponse) ProtoMessage() {} - -func (x *MapCIDRResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[5] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use MapCIDRResponse.ProtoReflect.Descriptor instead. -func (*MapCIDRResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{5} -} - -func (x *MapCIDRResponse) GetCidr() string { - if x != nil { - return x.Cidr - } - return "" -} - -type UnmapCIDRRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Cidr string `protobuf:"bytes,1,opt,name=cidr,proto3" json:"cidr,omitempty"` -} - -func (x *UnmapCIDRRequest) Reset() { - *x = UnmapCIDRRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *UnmapCIDRRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UnmapCIDRRequest) ProtoMessage() {} - -func (x *UnmapCIDRRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[6] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UnmapCIDRRequest.ProtoReflect.Descriptor instead. -func (*UnmapCIDRRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{6} -} - -func (x *UnmapCIDRRequest) GetCidr() string { - if x != nil { - return x.Cidr - } - return "" -} - -type UnmapCIDRResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *UnmapCIDRResponse) Reset() { - *x = UnmapCIDRResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *UnmapCIDRResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UnmapCIDRResponse) ProtoMessage() {} - -func (x *UnmapCIDRResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[7] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UnmapCIDRResponse.ProtoReflect.Descriptor instead. -func (*UnmapCIDRResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{7} -} - -type GetHomePodIPRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ClusterID string `protobuf:"bytes,1,opt,name=clusterID,proto3" json:"clusterID,omitempty"` - Ip string `protobuf:"bytes,2,opt,name=ip,proto3" json:"ip,omitempty"` -} - -func (x *GetHomePodIPRequest) Reset() { - *x = GetHomePodIPRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *GetHomePodIPRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetHomePodIPRequest) ProtoMessage() {} - -func (x *GetHomePodIPRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[8] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetHomePodIPRequest.ProtoReflect.Descriptor instead. -func (*GetHomePodIPRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{8} -} - -func (x *GetHomePodIPRequest) GetClusterID() string { - if x != nil { - return x.ClusterID - } - return "" -} - -func (x *GetHomePodIPRequest) GetIp() string { - if x != nil { - return x.Ip - } - return "" -} - -type GetHomePodIPResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - HomeIP string `protobuf:"bytes,1,opt,name=homeIP,proto3" json:"homeIP,omitempty"` -} - -func (x *GetHomePodIPResponse) Reset() { - *x = GetHomePodIPResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *GetHomePodIPResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetHomePodIPResponse) ProtoMessage() {} - -func (x *GetHomePodIPResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[9] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetHomePodIPResponse.ProtoReflect.Descriptor instead. -func (*GetHomePodIPResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{9} -} - -func (x *GetHomePodIPResponse) GetHomeIP() string { - if x != nil { - return x.HomeIP - } - return "" -} - -type BelongsRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` -} - -func (x *BelongsRequest) Reset() { - *x = BelongsRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[10] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *BelongsRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*BelongsRequest) ProtoMessage() {} - -func (x *BelongsRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[10] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use BelongsRequest.ProtoReflect.Descriptor instead. -func (*BelongsRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{10} -} - -func (x *BelongsRequest) GetIp() string { - if x != nil { - return x.Ip - } - return "" -} - -type BelongsResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Belongs bool `protobuf:"varint,1,opt,name=belongs,proto3" json:"belongs,omitempty"` -} - -func (x *BelongsResponse) Reset() { - *x = BelongsResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[11] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *BelongsResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*BelongsResponse) ProtoMessage() {} - -func (x *BelongsResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[11] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use BelongsResponse.ProtoReflect.Descriptor instead. -func (*BelongsResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{11} -} - -func (x *BelongsResponse) GetBelongs() bool { - if x != nil { - return x.Belongs - } - return false -} - -type GetOrSetExtCIDRRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DesiredExtCIDR string `protobuf:"bytes,1,opt,name=desiredExtCIDR,proto3" json:"desiredExtCIDR,omitempty"` -} - -func (x *GetOrSetExtCIDRRequest) Reset() { - *x = GetOrSetExtCIDRRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[12] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *GetOrSetExtCIDRRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetOrSetExtCIDRRequest) ProtoMessage() {} - -func (x *GetOrSetExtCIDRRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[12] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetOrSetExtCIDRRequest.ProtoReflect.Descriptor instead. -func (*GetOrSetExtCIDRRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{12} -} - -func (x *GetOrSetExtCIDRRequest) GetDesiredExtCIDR() string { - if x != nil { - return x.DesiredExtCIDR - } - return "" -} - -type GetOrSetExtCIDRResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - RemappedExtCIDR string `protobuf:"bytes,1,opt,name=remappedExtCIDR,proto3" json:"remappedExtCIDR,omitempty"` -} - -func (x *GetOrSetExtCIDRResponse) Reset() { - *x = GetOrSetExtCIDRResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[13] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *GetOrSetExtCIDRResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetOrSetExtCIDRResponse) ProtoMessage() {} - -func (x *GetOrSetExtCIDRResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[13] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetOrSetExtCIDRResponse.ProtoReflect.Descriptor instead. -func (*GetOrSetExtCIDRResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{13} -} - -func (x *GetOrSetExtCIDRResponse) GetRemappedExtCIDR() string { - if x != nil { - return x.RemappedExtCIDR - } - return "" -} - -type SetSubnetsPerClusterRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - RemappedPodCIDR string `protobuf:"bytes,1,opt,name=remappedPodCIDR,proto3" json:"remappedPodCIDR,omitempty"` - RemappedExternalCIDR string `protobuf:"bytes,2,opt,name=remappedExternalCIDR,proto3" json:"remappedExternalCIDR,omitempty"` - ClusterID string `protobuf:"bytes,3,opt,name=clusterID,proto3" json:"clusterID,omitempty"` -} - -func (x *SetSubnetsPerClusterRequest) Reset() { - *x = SetSubnetsPerClusterRequest{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[14] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *SetSubnetsPerClusterRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SetSubnetsPerClusterRequest) ProtoMessage() {} - -func (x *SetSubnetsPerClusterRequest) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[14] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use SetSubnetsPerClusterRequest.ProtoReflect.Descriptor instead. -func (*SetSubnetsPerClusterRequest) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{14} -} - -func (x *SetSubnetsPerClusterRequest) GetRemappedPodCIDR() string { - if x != nil { - return x.RemappedPodCIDR - } - return "" -} - -func (x *SetSubnetsPerClusterRequest) GetRemappedExternalCIDR() string { - if x != nil { - return x.RemappedExternalCIDR - } - return "" -} - -func (x *SetSubnetsPerClusterRequest) GetClusterID() string { - if x != nil { - return x.ClusterID - } - return "" -} - -type SetSubnetsPerClusterResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *SetSubnetsPerClusterResponse) Reset() { - *x = SetSubnetsPerClusterResponse{} - mi := &file_pkg_ipamold_ipam_proto_msgTypes[15] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *SetSubnetsPerClusterResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SetSubnetsPerClusterResponse) ProtoMessage() {} - -func (x *SetSubnetsPerClusterResponse) ProtoReflect() protoreflect.Message { - mi := &file_pkg_ipamold_ipam_proto_msgTypes[15] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use SetSubnetsPerClusterResponse.ProtoReflect.Descriptor instead. -func (*SetSubnetsPerClusterResponse) Descriptor() ([]byte, []int) { - return file_pkg_ipamold_ipam_proto_rawDescGZIP(), []int{15} -} - -var File_pkg_ipamold_ipam_proto protoreflect.FileDescriptor - -var file_pkg_ipamold_ipam_proto_rawDesc = []byte{ - 0x0a, 0x16, 0x70, 0x6b, 0x67, 0x2f, 0x69, 0x70, 0x61, 0x6d, 0x6f, 0x6c, 0x64, 0x2f, 0x69, 0x70, - 0x61, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3a, 0x0a, 0x0a, 0x4d, 0x61, 0x70, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, - 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x49, 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x02, 0x69, 0x70, 0x22, 0x1d, 0x0a, 0x0b, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x69, 0x70, 0x22, 0x3c, 0x0a, 0x0c, 0x55, 0x6e, 0x6d, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x44, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, - 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, - 0x70, 0x22, 0x0f, 0x0a, 0x0d, 0x55, 0x6e, 0x6d, 0x61, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x24, 0x0a, 0x0e, 0x4d, 0x61, 0x70, 0x43, 0x49, 0x44, 0x52, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x69, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x63, 0x69, 0x64, 0x72, 0x22, 0x25, 0x0a, 0x0f, 0x4d, 0x61, 0x70, 0x43, - 0x49, 0x44, 0x52, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, - 0x69, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x69, 0x64, 0x72, 0x22, - 0x26, 0x0a, 0x10, 0x55, 0x6e, 0x6d, 0x61, 0x70, 0x43, 0x49, 0x44, 0x52, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x69, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x63, 0x69, 0x64, 0x72, 0x22, 0x13, 0x0a, 0x11, 0x55, 0x6e, 0x6d, 0x61, 0x70, - 0x43, 0x49, 0x44, 0x52, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x43, 0x0a, 0x13, - 0x47, 0x65, 0x74, 0x48, 0x6f, 0x6d, 0x65, 0x50, 0x6f, 0x64, 0x49, 0x50, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x44, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, - 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, - 0x70, 0x22, 0x2e, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x48, 0x6f, 0x6d, 0x65, 0x50, 0x6f, 0x64, 0x49, - 0x50, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x6f, 0x6d, - 0x65, 0x49, 0x50, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x6f, 0x6d, 0x65, 0x49, - 0x50, 0x22, 0x20, 0x0a, 0x0e, 0x42, 0x65, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x69, 0x70, 0x22, 0x2b, 0x0a, 0x0f, 0x42, 0x65, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x65, 0x6c, 0x6f, 0x6e, 0x67, - 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x62, 0x65, 0x6c, 0x6f, 0x6e, 0x67, 0x73, - 0x22, 0x40, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74, 0x43, - 0x49, 0x44, 0x52, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0e, 0x64, 0x65, - 0x73, 0x69, 0x72, 0x65, 0x64, 0x45, 0x78, 0x74, 0x43, 0x49, 0x44, 0x52, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0e, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x45, 0x78, 0x74, 0x43, 0x49, - 0x44, 0x52, 0x22, 0x43, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x53, 0x65, 0x74, 0x45, 0x78, - 0x74, 0x43, 0x49, 0x44, 0x52, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, - 0x0f, 0x72, 0x65, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x64, 0x45, 0x78, 0x74, 0x43, 0x49, 0x44, 0x52, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x64, - 0x45, 0x78, 0x74, 0x43, 0x49, 0x44, 0x52, 0x22, 0x99, 0x01, 0x0a, 0x1b, 0x53, 0x65, 0x74, 0x53, - 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, 0x50, 0x65, 0x72, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x0f, 0x72, 0x65, 0x6d, 0x61, 0x70, - 0x70, 0x65, 0x64, 0x50, 0x6f, 0x64, 0x43, 0x49, 0x44, 0x52, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0f, 0x72, 0x65, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x64, 0x50, 0x6f, 0x64, 0x43, 0x49, 0x44, - 0x52, 0x12, 0x32, 0x0a, 0x14, 0x72, 0x65, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x64, 0x45, 0x78, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x43, 0x49, 0x44, 0x52, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x14, 0x72, 0x65, 0x6d, 0x61, 0x70, 0x70, 0x65, 0x64, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x43, 0x49, 0x44, 0x52, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, - 0x72, 0x49, 0x44, 0x22, 0x1e, 0x0a, 0x1c, 0x53, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, - 0x73, 0x50, 0x65, 0x72, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x32, 0xe8, 0x03, 0x0a, 0x04, 0x69, 0x70, 0x61, 0x6d, 0x12, 0x2a, 0x0a, 0x0d, - 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x50, 0x12, 0x0b, 0x2e, - 0x4d, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x4d, 0x61, 0x70, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x0f, 0x55, 0x6e, 0x6d, 0x61, - 0x70, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x49, 0x50, 0x12, 0x0d, 0x2e, 0x55, 0x6e, - 0x6d, 0x61, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x55, 0x6e, 0x6d, - 0x61, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x0e, 0x4d, 0x61, - 0x70, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x49, 0x44, 0x52, 0x12, 0x0f, 0x2e, 0x4d, - 0x61, 0x70, 0x43, 0x49, 0x44, 0x52, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, - 0x4d, 0x61, 0x70, 0x43, 0x49, 0x44, 0x52, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x39, 0x0a, 0x10, 0x55, 0x6e, 0x6d, 0x61, 0x70, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, - 0x49, 0x44, 0x52, 0x12, 0x11, 0x2e, 0x55, 0x6e, 0x6d, 0x61, 0x70, 0x43, 0x49, 0x44, 0x52, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x55, 0x6e, 0x6d, 0x61, 0x70, 0x43, 0x49, - 0x44, 0x52, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x0c, 0x47, 0x65, - 0x74, 0x48, 0x6f, 0x6d, 0x65, 0x50, 0x6f, 0x64, 0x49, 0x50, 0x12, 0x14, 0x2e, 0x47, 0x65, 0x74, - 0x48, 0x6f, 0x6d, 0x65, 0x50, 0x6f, 0x64, 0x49, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x15, 0x2e, 0x47, 0x65, 0x74, 0x48, 0x6f, 0x6d, 0x65, 0x50, 0x6f, 0x64, 0x49, 0x50, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x10, 0x42, 0x65, 0x6c, 0x6f, 0x6e, - 0x67, 0x73, 0x54, 0x6f, 0x50, 0x6f, 0x64, 0x43, 0x49, 0x44, 0x52, 0x12, 0x0f, 0x2e, 0x42, 0x65, - 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x42, - 0x65, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, - 0x0a, 0x14, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, - 0x61, 0x6c, 0x43, 0x49, 0x44, 0x52, 0x12, 0x17, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x53, 0x65, - 0x74, 0x45, 0x78, 0x74, 0x43, 0x49, 0x44, 0x52, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x18, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74, 0x43, 0x49, 0x44, - 0x52, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x14, 0x53, 0x65, 0x74, - 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, 0x50, 0x65, 0x72, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, - 0x72, 0x12, 0x1c, 0x2e, 0x53, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, 0x50, 0x65, - 0x72, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1d, 0x2e, 0x53, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, 0x50, 0x65, 0x72, 0x43, - 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x08, - 0x5a, 0x06, 0x2e, 0x2f, 0x69, 0x70, 0x61, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_pkg_ipamold_ipam_proto_rawDescOnce sync.Once - file_pkg_ipamold_ipam_proto_rawDescData = file_pkg_ipamold_ipam_proto_rawDesc -) - -func file_pkg_ipamold_ipam_proto_rawDescGZIP() []byte { - file_pkg_ipamold_ipam_proto_rawDescOnce.Do(func() { - file_pkg_ipamold_ipam_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_ipamold_ipam_proto_rawDescData) - }) - return file_pkg_ipamold_ipam_proto_rawDescData -} - -var file_pkg_ipamold_ipam_proto_msgTypes = make([]protoimpl.MessageInfo, 16) -var file_pkg_ipamold_ipam_proto_goTypes = []any{ - (*MapRequest)(nil), // 0: MapRequest - (*MapResponse)(nil), // 1: MapResponse - (*UnmapRequest)(nil), // 2: UnmapRequest - (*UnmapResponse)(nil), // 3: UnmapResponse - (*MapCIDRRequest)(nil), // 4: MapCIDRRequest - (*MapCIDRResponse)(nil), // 5: MapCIDRResponse - (*UnmapCIDRRequest)(nil), // 6: UnmapCIDRRequest - (*UnmapCIDRResponse)(nil), // 7: UnmapCIDRResponse - (*GetHomePodIPRequest)(nil), // 8: GetHomePodIPRequest - (*GetHomePodIPResponse)(nil), // 9: GetHomePodIPResponse - (*BelongsRequest)(nil), // 10: BelongsRequest - (*BelongsResponse)(nil), // 11: BelongsResponse - (*GetOrSetExtCIDRRequest)(nil), // 12: GetOrSetExtCIDRRequest - (*GetOrSetExtCIDRResponse)(nil), // 13: GetOrSetExtCIDRResponse - (*SetSubnetsPerClusterRequest)(nil), // 14: SetSubnetsPerClusterRequest - (*SetSubnetsPerClusterResponse)(nil), // 15: SetSubnetsPerClusterResponse -} -var file_pkg_ipamold_ipam_proto_depIdxs = []int32{ - 0, // 0: ipam.MapEndpointIP:input_type -> MapRequest - 2, // 1: ipam.UnmapEndpointIP:input_type -> UnmapRequest - 4, // 2: ipam.MapNetworkCIDR:input_type -> MapCIDRRequest - 6, // 3: ipam.UnmapNetworkCIDR:input_type -> UnmapCIDRRequest - 8, // 4: ipam.GetHomePodIP:input_type -> GetHomePodIPRequest - 10, // 5: ipam.BelongsToPodCIDR:input_type -> BelongsRequest - 12, // 6: ipam.GetOrSetExternalCIDR:input_type -> GetOrSetExtCIDRRequest - 14, // 7: ipam.SetSubnetsPerCluster:input_type -> SetSubnetsPerClusterRequest - 1, // 8: ipam.MapEndpointIP:output_type -> MapResponse - 3, // 9: ipam.UnmapEndpointIP:output_type -> UnmapResponse - 5, // 10: ipam.MapNetworkCIDR:output_type -> MapCIDRResponse - 7, // 11: ipam.UnmapNetworkCIDR:output_type -> UnmapCIDRResponse - 9, // 12: ipam.GetHomePodIP:output_type -> GetHomePodIPResponse - 11, // 13: ipam.BelongsToPodCIDR:output_type -> BelongsResponse - 13, // 14: ipam.GetOrSetExternalCIDR:output_type -> GetOrSetExtCIDRResponse - 15, // 15: ipam.SetSubnetsPerCluster:output_type -> SetSubnetsPerClusterResponse - 8, // [8:16] is the sub-list for method output_type - 0, // [0:8] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_pkg_ipamold_ipam_proto_init() } -func file_pkg_ipamold_ipam_proto_init() { - if File_pkg_ipamold_ipam_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_pkg_ipamold_ipam_proto_rawDesc, - NumEnums: 0, - NumMessages: 16, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_pkg_ipamold_ipam_proto_goTypes, - DependencyIndexes: file_pkg_ipamold_ipam_proto_depIdxs, - MessageInfos: file_pkg_ipamold_ipam_proto_msgTypes, - }.Build() - File_pkg_ipamold_ipam_proto = out.File - file_pkg_ipamold_ipam_proto_rawDesc = nil - file_pkg_ipamold_ipam_proto_goTypes = nil - file_pkg_ipamold_ipam_proto_depIdxs = nil -} diff --git a/pkg/ipamold/ipam.proto b/pkg/ipamold/ipam.proto deleted file mode 100644 index 60ce330480..0000000000 --- a/pkg/ipamold/ipam.proto +++ /dev/null @@ -1,76 +0,0 @@ -syntax="proto3"; -option go_package = "./ipam"; - -service ipam { - rpc MapEndpointIP (MapRequest) returns (MapResponse); - rpc UnmapEndpointIP (UnmapRequest) returns (UnmapResponse); - rpc MapNetworkCIDR (MapCIDRRequest) returns (MapCIDRResponse); - rpc UnmapNetworkCIDR (UnmapCIDRRequest) returns (UnmapCIDRResponse); - rpc GetHomePodIP (GetHomePodIPRequest) returns (GetHomePodIPResponse); - rpc BelongsToPodCIDR (BelongsRequest) returns (BelongsResponse); - rpc GetOrSetExternalCIDR(GetOrSetExtCIDRRequest) returns (GetOrSetExtCIDRResponse); - rpc SetSubnetsPerCluster(SetSubnetsPerClusterRequest) returns (SetSubnetsPerClusterResponse); -} - -message MapRequest { - string clusterID = 1; - string ip = 2; -} - -message MapResponse { - string ip = 1; -} - -message UnmapRequest { - string clusterID = 1; - string ip = 2; -} - -message UnmapResponse {} - -message MapCIDRRequest { - string cidr = 1; -} - -message MapCIDRResponse { - string cidr = 1; -} - -message UnmapCIDRRequest { - string cidr = 1; -} - -message UnmapCIDRResponse {} - -message GetHomePodIPRequest { - string clusterID = 1; - string ip = 2; -} - -message GetHomePodIPResponse { - string homeIP = 1; -} - -message BelongsRequest { - string ip = 1; -} - -message BelongsResponse { - bool belongs = 1; -} - -message GetOrSetExtCIDRRequest { - string desiredExtCIDR = 1; -} - -message GetOrSetExtCIDRResponse { - string remappedExtCIDR = 1; -} - -message SetSubnetsPerClusterRequest { - string remappedPodCIDR = 1; - string remappedExternalCIDR = 2; - string clusterID = 3; -} - -message SetSubnetsPerClusterResponse {} diff --git a/pkg/ipamold/ipamStorage.go b/pkg/ipamold/ipamStorage.go deleted file mode 100644 index f943469af4..0000000000 --- a/pkg/ipamold/ipamStorage.go +++ /dev/null @@ -1,401 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ipam - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "sync" - - goipam "github.com/metal-stack/go-ipam" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/client-go/dynamic" - "k8s.io/klog/v2" - - ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" - "github.com/liqotech/liqo/pkg/consts" - "github.com/liqotech/liqo/pkg/utils/slice" -) - -const ( - ipamNamePrefix = "ipamstorage-" - clusterSubnetUpdate = "clusterSubnets" - poolsUpdate = "pools" - reservedSubnetsUpdate = "reservedSubnets" - prefixesUpdate = "prefixes" - externalCIDRUpdate = "externalCIDR" - endpointMappingsUpdate = "endpointMappings" - podCIDRUpdate = "podCIDR" - serviceCIDRUpdate = "serviceCIDR" - updateOpAdd = "add" - updateOpRemove = "remove" -) - -// IpamStorage is the interface to be implemented to enforce persistency in IPAM. -type IpamStorage interface { - updateClusterSubnets(clusterSubnet map[string]ipamv1alpha1.Subnets) error - updatePools(pools []string) error - updateExternalCIDR(externalCIDR string) error - updateEndpointMappings(endpoints map[string]ipamv1alpha1.EndpointMapping) error - updatePodCIDR(podCIDR string) error - updateServiceCIDR(serviceCIDR string) error - updateReservedSubnets(subnet, operation string) error - getClusterSubnets() map[string]ipamv1alpha1.Subnets - getPools() []string - getExternalCIDR() string - getEndpointMappings() map[string]ipamv1alpha1.EndpointMapping - getPodCIDR() string - getServiceCIDR() string - getReservedSubnets() []string - goipam.Storage -} - -// IPAMStorage is an implementation of IpamStorage that takes advantage of the CRD IpamStorage. -type IPAMStorage struct { - m sync.RWMutex - - dynClient dynamic.Interface - storage *ipamv1alpha1.IpamStorage - - namespace string -} - -// NewIPAMStorage inits the storage of the IPAM module, -// retrieving an existing ipamStorage resource or creating a new one. -func NewIPAMStorage(dynClient dynamic.Interface, namespace string) (*IPAMStorage, error) { - klog.Infof("Init IPAM storage..") - ipamStorage := &IPAMStorage{} - ipamStorage.dynClient = dynClient - ipamStorage.namespace = namespace - - klog.Infof("Looking for Ipam resource..") - ipam, err := ipamStorage.retrieveConfig() - if err != nil && !errors.IsNotFound(err) { - return nil, err - } - - if errors.IsNotFound(err) { - klog.Infof("IPAM resource has not been found, creating a new one..") - if ipam, err = ipamStorage.createConfig(); err != nil { - return nil, err - } - - ipamStorage.storage = ipam - klog.Infof("Resource %s of type %s successfully created", ipam.GetName(), ipamv1alpha1.IpamStorageGroupVersionResource) - } else { - ipamStorage.storage = ipam - klog.Infof("Resource %s of type %s has been found", ipam.GetName(), ipamv1alpha1.IpamStorageGroupVersionResource) - } - klog.Infof("Ipam storage successfully configured") - return ipamStorage, nil -} - -// Name returns the name of the IPAMStorage implementation. -func (ipamStorage *IPAMStorage) Name() string { return "liqo" } - -// CreatePrefix creates a new Prefix in ipamStorage resource. -func (ipamStorage *IPAMStorage) CreatePrefix(_ context.Context, prefix goipam.Prefix) (goipam.Prefix, error) { - ipam := ipamStorage.getConfig() - if _, ok := ipam.Spec.Prefixes[prefix.Cidr]; ok { - return goipam.Prefix{}, fmt.Errorf("prefix already created:%v", prefix) - } - gob, err := prefix.GobEncode() - ipam.Spec.Prefixes[prefix.Cidr] = gob - if err != nil { - return goipam.Prefix{}, fmt.Errorf("failed to encode prefix %s: %w", prefix.Cidr, err) - } - if err = ipamStorage.updatePrefixes(ipam.Spec.Prefixes); err != nil { - klog.Errorf("cannot update ipam resource:%s", err.Error()) - return goipam.Prefix{}, err - } - return prefix, err -} - -// ReadPrefix retrieves a specific Prefix from ipamStorage resource. -func (ipamStorage *IPAMStorage) ReadPrefix(_ context.Context, prefix string) (goipam.Prefix, error) { - var p goipam.Prefix - ipam := ipamStorage.getConfig() - if _, ok := ipam.Spec.Prefixes[prefix]; !ok { - return goipam.Prefix{}, fmt.Errorf("prefix %s not found", prefix) - } - err := p.GobDecode(ipam.Spec.Prefixes[prefix]) - if err != nil { - return goipam.Prefix{}, err - } - return p, nil -} - -// ReadAllPrefixes retrieves all prefixes from ipamStorage resource. -func (ipamStorage *IPAMStorage) ReadAllPrefixes(_ context.Context) (goipam.Prefixes, error) { - ipam := ipamStorage.getConfig() - list := make(goipam.Prefixes, 0, len(ipam.Spec.Prefixes)) - for _, value := range ipam.Spec.Prefixes { - var p goipam.Prefix - err := p.GobDecode(value) - if err != nil { - return nil, err - } - list = append(list, p) - } - return list, nil -} - -// ReadAllPrefixCidrs retrieves all prefix CIDR from ipamStorage resource. -func (ipamStorage *IPAMStorage) ReadAllPrefixCidrs(_ context.Context) ([]string, error) { - list := make([]string, 0) - ipam := ipamStorage.getConfig() - for _, value := range ipam.Spec.Prefixes { - var p goipam.Prefix - err := p.GobDecode(value) - if err != nil { - return nil, err - } - list = append(list, p.Cidr) - } - return list, nil -} - -// UpdatePrefix updates a Prefix in ipamStorage resource. -func (ipamStorage *IPAMStorage) UpdatePrefix(_ context.Context, prefix goipam.Prefix) (goipam.Prefix, error) { - if prefix.Cidr == "" { - return goipam.Prefix{}, fmt.Errorf("prefix not present:%v", prefix) - } - ipam := ipamStorage.getConfig() - if _, ok := ipam.Spec.Prefixes[prefix.Cidr]; !ok { - return goipam.Prefix{}, fmt.Errorf("prefix %s not found", prefix.Cidr) - } - gob, err := prefix.GobEncode() - ipam.Spec.Prefixes[prefix.Cidr] = gob - if err != nil { - return goipam.Prefix{}, fmt.Errorf("cannot update prefix %s: %w", prefix.Cidr, err) - } - if err = ipamStorage.updatePrefixes(ipam.Spec.Prefixes); err != nil { - klog.Errorf("cannot update ipam resource:%s", err.Error()) - return goipam.Prefix{}, err - } - return prefix, nil -} - -// DeletePrefix deletes a Prefix from ipamStorage resource. -func (ipamStorage *IPAMStorage) DeletePrefix(_ context.Context, prefix goipam.Prefix) (goipam.Prefix, error) { - if prefix.Cidr == "" { - return goipam.Prefix{}, fmt.Errorf("prefix not present:%v", prefix) - } - ipam := ipamStorage.getConfig() - if _, ok := ipam.Spec.Prefixes[prefix.Cidr]; !ok { - return goipam.Prefix{}, fmt.Errorf("prefix %s not found", prefix.Cidr) - } - delete(ipam.Spec.Prefixes, prefix.Cidr) - if err := ipamStorage.updatePrefixes(ipam.Spec.Prefixes); err != nil { - klog.Errorf("cannot update ipam resource:%s", err.Error()) - return goipam.Prefix{}, err - } - return prefix, nil -} - -// DeleteAllPrefixes deletes all prefixes from ipamStorage resource. -func (ipamStorage *IPAMStorage) DeleteAllPrefixes(_ context.Context) error { - ipam := ipamStorage.getConfig() - ipam.Spec.Prefixes = make(map[string][]byte) - - if err := ipamStorage.updatePrefixes(ipam.Spec.Prefixes); err != nil { - klog.Errorf("cannot update ipam resource: %s", err.Error()) - return err - } - return nil -} - -func (ipamStorage *IPAMStorage) updateClusterSubnets(clusterSubnets map[string]ipamv1alpha1.Subnets) error { - return ipamStorage.updateConfig(clusterSubnetUpdate, clusterSubnets) -} - -func (ipamStorage *IPAMStorage) updatePools(pools []string) error { - return ipamStorage.updateConfig(poolsUpdate, pools) -} - -func (ipamStorage *IPAMStorage) updateReservedSubnets(subnet, operation string) error { - subnets := ipamStorage.getReservedSubnets() - switch operation { - case updateOpAdd: - subnets = append(subnets, subnet) - case updateOpRemove: - subnets = slice.Remove(subnets, subnet) - } - return ipamStorage.updateConfig(reservedSubnetsUpdate, subnets) -} - -func (ipamStorage *IPAMStorage) updatePrefixes(prefixes map[string][]byte) error { - return ipamStorage.updateConfig(prefixesUpdate, prefixes) -} - -func (ipamStorage *IPAMStorage) updateExternalCIDR(externalCIDR string) error { - return ipamStorage.updateConfig(externalCIDRUpdate, externalCIDR) -} - -func (ipamStorage *IPAMStorage) updateEndpointMappings(endpoints map[string]ipamv1alpha1.EndpointMapping) error { - return ipamStorage.updateConfig(endpointMappingsUpdate, endpoints) -} - -func (ipamStorage *IPAMStorage) updatePodCIDR(podCIDR string) error { - return ipamStorage.updateConfig(podCIDRUpdate, podCIDR) -} - -func (ipamStorage *IPAMStorage) updateServiceCIDR(serviceCIDR string) error { - return ipamStorage.updateConfig(serviceCIDRUpdate, serviceCIDR) -} - -func (ipamStorage *IPAMStorage) updateConfig(updateType string, data interface{}) error { - jsonData, err := json.Marshal(data) - if err != nil { - klog.Errorf("cannot marshal object: %s", err.Error()) - return err - } - - var b bytes.Buffer - patch := fmt.Sprintf( - `[{"op": "replace", "path": "/spec/%s", "value": `, - updateType) - b.WriteString(patch) - b.Write(jsonData) - b.WriteString("}]") - - unstr, err := ipamStorage.dynClient.Resource(ipamv1alpha1.IpamStorageGroupVersionResource).Namespace(ipamStorage.namespace). - Patch(context.Background(), ipamStorage.getConfigName(), types.JSONPatchType, b.Bytes(), metav1.PatchOptions{}) - if err != nil { - klog.Errorf("Failed to patch the IPAM resource: %v", err) - return err - } - - var storage ipamv1alpha1.IpamStorage - err = runtime.DefaultUnstructuredConverter.FromUnstructured(unstr.UnstructuredContent(), &storage) - utilruntime.Must(err) - - ipamStorage.m.Lock() - ipamStorage.storage = &storage - ipamStorage.m.Unlock() - - return nil -} - -func (ipamStorage *IPAMStorage) getPools() []string { - return ipamStorage.getConfig().Spec.Pools -} - -func (ipamStorage *IPAMStorage) getClusterSubnets() map[string]ipamv1alpha1.Subnets { - return ipamStorage.getConfig().Spec.ClusterSubnets -} - -func (ipamStorage *IPAMStorage) getExternalCIDR() string { - return ipamStorage.getConfig().Spec.ExternalCIDR -} - -func (ipamStorage *IPAMStorage) getEndpointMappings() map[string]ipamv1alpha1.EndpointMapping { - return ipamStorage.getConfig().Spec.EndpointMappings -} - -func (ipamStorage *IPAMStorage) getPodCIDR() string { - return ipamStorage.getConfig().Spec.PodCIDR -} - -func (ipamStorage *IPAMStorage) getServiceCIDR() string { - return ipamStorage.getConfig().Spec.ServiceCIDR -} - -func (ipamStorage *IPAMStorage) getReservedSubnets() []string { - return ipamStorage.getConfig().Spec.ReservedSubnets -} - -func (ipamStorage *IPAMStorage) getConfig() *ipamv1alpha1.IpamStorage { - ipamStorage.m.RLock() - defer ipamStorage.m.RUnlock() - - return ipamStorage.storage.DeepCopy() -} - -func (ipamStorage *IPAMStorage) getConfigName() string { - ipamStorage.m.RLock() - defer ipamStorage.m.RUnlock() - - return ipamStorage.storage.GetName() -} - -func (ipamStorage *IPAMStorage) retrieveConfig() (*ipamv1alpha1.IpamStorage, error) { - list, err := ipamStorage.dynClient. - Resource(ipamv1alpha1.IpamStorageGroupVersionResource).Namespace(ipamStorage.namespace). - List(context.Background(), metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", consts.IpamStorageResourceLabelKey, consts.IpamStorageResourceLabelValue), - }) - if err != nil { - klog.Errorf(err.Error()) - return nil, fmt.Errorf("unable to get configuration: %w", err) - } - - if len(list.Items) != 1 { - if len(list.Items) != 0 { - return nil, fmt.Errorf("multiple resources of type %s found", ipamv1alpha1.IpamStorageGroupVersionResource) - } - return nil, errors.NewNotFound(ipamv1alpha1.IpamStorageGroupResource, "") - } - - var storage ipamv1alpha1.IpamStorage - err = runtime.DefaultUnstructuredConverter.FromUnstructured(list.Items[0].UnstructuredContent(), &storage) - utilruntime.Must(err) - - return &storage, nil -} - -func (ipamStorage *IPAMStorage) createConfig() (*ipamv1alpha1.IpamStorage, error) { - ipam := &ipamv1alpha1.IpamStorage{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "ipam.liqo.io/v1alpha1", - Kind: "IpamStorage", - }, - ObjectMeta: metav1.ObjectMeta{ - GenerateName: ipamNamePrefix, - Namespace: ipamStorage.namespace, - Labels: map[string]string{consts.IpamStorageResourceLabelKey: consts.IpamStorageResourceLabelValue}, - }, - Spec: ipamv1alpha1.IpamSpec{ - Prefixes: make(map[string][]byte), - Pools: make([]string, 0), - ClusterSubnets: make(map[string]ipamv1alpha1.Subnets), - EndpointMappings: make(map[string]ipamv1alpha1.EndpointMapping), - ReservedSubnets: []string{}, - }, - } - - unstr, err := runtime.DefaultUnstructuredConverter.ToUnstructured(ipam) - utilruntime.Must(err) - - created, err := ipamStorage.dynClient.Resource(ipamv1alpha1.IpamStorageGroupVersionResource).Namespace(ipamStorage.namespace). - Create(context.Background(), &unstructured.Unstructured{Object: unstr}, metav1.CreateOptions{}) - if err != nil { - klog.Errorf("cannot create ipam resource: %s", err.Error()) - return nil, err - } - - var storage ipamv1alpha1.IpamStorage - err = runtime.DefaultUnstructuredConverter.FromUnstructured(created.UnstructuredContent(), &storage) - utilruntime.Must(err) - - return &storage, nil -} diff --git a/pkg/ipamold/ipam_grpc.pb.go b/pkg/ipamold/ipam_grpc.pb.go deleted file mode 100644 index c2b790fb6e..0000000000 --- a/pkg/ipamold/ipam_grpc.pb.go +++ /dev/null @@ -1,388 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.5.1 -// - protoc v5.28.3 -// source: pkg/ipamold/ipam.proto - -package ipam - -import ( - context "context" - - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.64.0 or later. -const _ = grpc.SupportPackageIsVersion9 - -const ( - Ipam_MapEndpointIP_FullMethodName = "/ipam/MapEndpointIP" - Ipam_UnmapEndpointIP_FullMethodName = "/ipam/UnmapEndpointIP" - Ipam_MapNetworkCIDR_FullMethodName = "/ipam/MapNetworkCIDR" - Ipam_UnmapNetworkCIDR_FullMethodName = "/ipam/UnmapNetworkCIDR" - Ipam_GetHomePodIP_FullMethodName = "/ipam/GetHomePodIP" - Ipam_BelongsToPodCIDR_FullMethodName = "/ipam/BelongsToPodCIDR" - Ipam_GetOrSetExternalCIDR_FullMethodName = "/ipam/GetOrSetExternalCIDR" - Ipam_SetSubnetsPerCluster_FullMethodName = "/ipam/SetSubnetsPerCluster" -) - -// IpamClient is the client API for Ipam service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type IpamClient interface { - MapEndpointIP(ctx context.Context, in *MapRequest, opts ...grpc.CallOption) (*MapResponse, error) - UnmapEndpointIP(ctx context.Context, in *UnmapRequest, opts ...grpc.CallOption) (*UnmapResponse, error) - MapNetworkCIDR(ctx context.Context, in *MapCIDRRequest, opts ...grpc.CallOption) (*MapCIDRResponse, error) - UnmapNetworkCIDR(ctx context.Context, in *UnmapCIDRRequest, opts ...grpc.CallOption) (*UnmapCIDRResponse, error) - GetHomePodIP(ctx context.Context, in *GetHomePodIPRequest, opts ...grpc.CallOption) (*GetHomePodIPResponse, error) - BelongsToPodCIDR(ctx context.Context, in *BelongsRequest, opts ...grpc.CallOption) (*BelongsResponse, error) - GetOrSetExternalCIDR(ctx context.Context, in *GetOrSetExtCIDRRequest, opts ...grpc.CallOption) (*GetOrSetExtCIDRResponse, error) - SetSubnetsPerCluster(ctx context.Context, in *SetSubnetsPerClusterRequest, opts ...grpc.CallOption) (*SetSubnetsPerClusterResponse, error) -} - -type ipamClient struct { - cc grpc.ClientConnInterface -} - -func NewIpamClient(cc grpc.ClientConnInterface) IpamClient { - return &ipamClient{cc} -} - -func (c *ipamClient) MapEndpointIP(ctx context.Context, in *MapRequest, opts ...grpc.CallOption) (*MapResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(MapResponse) - err := c.cc.Invoke(ctx, Ipam_MapEndpointIP_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *ipamClient) UnmapEndpointIP(ctx context.Context, in *UnmapRequest, opts ...grpc.CallOption) (*UnmapResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(UnmapResponse) - err := c.cc.Invoke(ctx, Ipam_UnmapEndpointIP_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *ipamClient) MapNetworkCIDR(ctx context.Context, in *MapCIDRRequest, opts ...grpc.CallOption) (*MapCIDRResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(MapCIDRResponse) - err := c.cc.Invoke(ctx, Ipam_MapNetworkCIDR_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *ipamClient) UnmapNetworkCIDR(ctx context.Context, in *UnmapCIDRRequest, opts ...grpc.CallOption) (*UnmapCIDRResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(UnmapCIDRResponse) - err := c.cc.Invoke(ctx, Ipam_UnmapNetworkCIDR_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *ipamClient) GetHomePodIP(ctx context.Context, in *GetHomePodIPRequest, opts ...grpc.CallOption) (*GetHomePodIPResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(GetHomePodIPResponse) - err := c.cc.Invoke(ctx, Ipam_GetHomePodIP_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *ipamClient) BelongsToPodCIDR(ctx context.Context, in *BelongsRequest, opts ...grpc.CallOption) (*BelongsResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(BelongsResponse) - err := c.cc.Invoke(ctx, Ipam_BelongsToPodCIDR_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *ipamClient) GetOrSetExternalCIDR(ctx context.Context, in *GetOrSetExtCIDRRequest, opts ...grpc.CallOption) (*GetOrSetExtCIDRResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(GetOrSetExtCIDRResponse) - err := c.cc.Invoke(ctx, Ipam_GetOrSetExternalCIDR_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *ipamClient) SetSubnetsPerCluster(ctx context.Context, in *SetSubnetsPerClusterRequest, opts ...grpc.CallOption) (*SetSubnetsPerClusterResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(SetSubnetsPerClusterResponse) - err := c.cc.Invoke(ctx, Ipam_SetSubnetsPerCluster_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -// IpamServer is the server API for Ipam service. -// All implementations must embed UnimplementedIpamServer -// for forward compatibility. -type IpamServer interface { - MapEndpointIP(context.Context, *MapRequest) (*MapResponse, error) - UnmapEndpointIP(context.Context, *UnmapRequest) (*UnmapResponse, error) - MapNetworkCIDR(context.Context, *MapCIDRRequest) (*MapCIDRResponse, error) - UnmapNetworkCIDR(context.Context, *UnmapCIDRRequest) (*UnmapCIDRResponse, error) - GetHomePodIP(context.Context, *GetHomePodIPRequest) (*GetHomePodIPResponse, error) - BelongsToPodCIDR(context.Context, *BelongsRequest) (*BelongsResponse, error) - GetOrSetExternalCIDR(context.Context, *GetOrSetExtCIDRRequest) (*GetOrSetExtCIDRResponse, error) - SetSubnetsPerCluster(context.Context, *SetSubnetsPerClusterRequest) (*SetSubnetsPerClusterResponse, error) - mustEmbedUnimplementedIpamServer() -} - -// UnimplementedIpamServer must be embedded to have -// forward compatible implementations. -// -// NOTE: this should be embedded by value instead of pointer to avoid a nil -// pointer dereference when methods are called. -type UnimplementedIpamServer struct{} - -func (UnimplementedIpamServer) MapEndpointIP(context.Context, *MapRequest) (*MapResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method MapEndpointIP not implemented") -} -func (UnimplementedIpamServer) UnmapEndpointIP(context.Context, *UnmapRequest) (*UnmapResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UnmapEndpointIP not implemented") -} -func (UnimplementedIpamServer) MapNetworkCIDR(context.Context, *MapCIDRRequest) (*MapCIDRResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method MapNetworkCIDR not implemented") -} -func (UnimplementedIpamServer) UnmapNetworkCIDR(context.Context, *UnmapCIDRRequest) (*UnmapCIDRResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UnmapNetworkCIDR not implemented") -} -func (UnimplementedIpamServer) GetHomePodIP(context.Context, *GetHomePodIPRequest) (*GetHomePodIPResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetHomePodIP not implemented") -} -func (UnimplementedIpamServer) BelongsToPodCIDR(context.Context, *BelongsRequest) (*BelongsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method BelongsToPodCIDR not implemented") -} -func (UnimplementedIpamServer) GetOrSetExternalCIDR(context.Context, *GetOrSetExtCIDRRequest) (*GetOrSetExtCIDRResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetOrSetExternalCIDR not implemented") -} -func (UnimplementedIpamServer) SetSubnetsPerCluster(context.Context, *SetSubnetsPerClusterRequest) (*SetSubnetsPerClusterResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method SetSubnetsPerCluster not implemented") -} -func (UnimplementedIpamServer) mustEmbedUnimplementedIpamServer() {} -func (UnimplementedIpamServer) testEmbeddedByValue() {} - -// UnsafeIpamServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to IpamServer will -// result in compilation errors. -type UnsafeIpamServer interface { - mustEmbedUnimplementedIpamServer() -} - -func RegisterIpamServer(s grpc.ServiceRegistrar, srv IpamServer) { - // If the following call pancis, it indicates UnimplementedIpamServer was - // embedded by pointer and is nil. This will cause panics if an - // unimplemented method is ever invoked, so we test this at initialization - // time to prevent it from happening at runtime later due to I/O. - if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { - t.testEmbeddedByValue() - } - s.RegisterService(&Ipam_ServiceDesc, srv) -} - -func _Ipam_MapEndpointIP_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MapRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).MapEndpointIP(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_MapEndpointIP_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).MapEndpointIP(ctx, req.(*MapRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Ipam_UnmapEndpointIP_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UnmapRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).UnmapEndpointIP(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_UnmapEndpointIP_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).UnmapEndpointIP(ctx, req.(*UnmapRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Ipam_MapNetworkCIDR_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MapCIDRRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).MapNetworkCIDR(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_MapNetworkCIDR_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).MapNetworkCIDR(ctx, req.(*MapCIDRRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Ipam_UnmapNetworkCIDR_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UnmapCIDRRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).UnmapNetworkCIDR(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_UnmapNetworkCIDR_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).UnmapNetworkCIDR(ctx, req.(*UnmapCIDRRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Ipam_GetHomePodIP_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetHomePodIPRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).GetHomePodIP(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_GetHomePodIP_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).GetHomePodIP(ctx, req.(*GetHomePodIPRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Ipam_BelongsToPodCIDR_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(BelongsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).BelongsToPodCIDR(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_BelongsToPodCIDR_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).BelongsToPodCIDR(ctx, req.(*BelongsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Ipam_GetOrSetExternalCIDR_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetOrSetExtCIDRRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).GetOrSetExternalCIDR(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_GetOrSetExternalCIDR_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).GetOrSetExternalCIDR(ctx, req.(*GetOrSetExtCIDRRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Ipam_SetSubnetsPerCluster_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SetSubnetsPerClusterRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(IpamServer).SetSubnetsPerCluster(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Ipam_SetSubnetsPerCluster_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(IpamServer).SetSubnetsPerCluster(ctx, req.(*SetSubnetsPerClusterRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Ipam_ServiceDesc is the grpc.ServiceDesc for Ipam service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Ipam_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "ipam", - HandlerType: (*IpamServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "MapEndpointIP", - Handler: _Ipam_MapEndpointIP_Handler, - }, - { - MethodName: "UnmapEndpointIP", - Handler: _Ipam_UnmapEndpointIP_Handler, - }, - { - MethodName: "MapNetworkCIDR", - Handler: _Ipam_MapNetworkCIDR_Handler, - }, - { - MethodName: "UnmapNetworkCIDR", - Handler: _Ipam_UnmapNetworkCIDR_Handler, - }, - { - MethodName: "GetHomePodIP", - Handler: _Ipam_GetHomePodIP_Handler, - }, - { - MethodName: "BelongsToPodCIDR", - Handler: _Ipam_BelongsToPodCIDR_Handler, - }, - { - MethodName: "GetOrSetExternalCIDR", - Handler: _Ipam_GetOrSetExternalCIDR_Handler, - }, - { - MethodName: "SetSubnetsPerCluster", - Handler: _Ipam_SetSubnetsPerCluster_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "pkg/ipamold/ipam.proto", -} diff --git a/pkg/ipamold/ipam_suite_test.go b/pkg/ipamold/ipam_suite_test.go deleted file mode 100644 index 62a5360910..0000000000 --- a/pkg/ipamold/ipam_suite_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ipam_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/liqotech/liqo/pkg/utils/testutil" -) - -func TestIpam(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Ipam Suite") -} - -var _ = BeforeSuite(func() { - testutil.LogsToGinkgoWriter() -}) diff --git a/pkg/ipamold/ipam_test.go b/pkg/ipamold/ipam_test.go deleted file mode 100644 index ffdd8f3245..0000000000 --- a/pkg/ipamold/ipam_test.go +++ /dev/null @@ -1,1217 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ipam - -import ( - "context" - "crypto/rand" - "errors" - "fmt" - "math/big" - "strings" - - "github.com/google/nftables" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - k8serrors "k8s.io/apimachinery/pkg/api/errors" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/dynamic/fake" - - ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" - "github.com/liqotech/liqo/pkg/consts" - ipamerrors "github.com/liqotech/liqo/pkg/ipamold/errors" - ipamutils "github.com/liqotech/liqo/pkg/ipamold/utils" -) - -const ( - clusterID1 = "cluster1" - clusterID2 = "cluster2" - clusterID3 = "cluster3" - remotePodCIDR = "10.50.0.0/16" - remoteExternalCIDR = "10.60.0.0/16" - homePodCIDR = "10.0.0.0/24" - homeExternalCIDR = "10.1.0.0/24" - localEndpointIP = "10.0.0.20" - localNATPodCIDR = "10.0.1.0/24" - localNATExternalCIDR = "192.168.30.0/24" - externalEndpointIP = "10.0.50.6" - endpointIP = "20.0.0.1" - invalidValue = "invalid value" - namespace = "test-namespace" -) - -var ( - ipam *IPAM - dynClient *fake.FakeDynamicClient - - ctx = context.Background() -) - -func fillNetworkPool(pool string, ipam *IPAM) error { - - // Get halves mask length - mask := ipamutils.GetMask(pool) - mask++ - - // Get first half CIDR - halfCidr := ipamutils.SetMask(pool, mask) - - err := ipam.AcquireReservedSubnet(halfCidr) - if err != nil { - return err - } - - // Get second half CIDR - halfCidr = ipamutils.Next(halfCidr) - err = ipam.AcquireReservedSubnet(halfCidr) - - return err -} - -func setDynClient() error { - scheme := runtime.NewScheme() - scheme.AddKnownTypeWithName(schema.GroupVersionKind{ - Group: "ipam.liqo.io", - Version: "v1alpha1", - Kind: "ipamstorages", - }, &ipamv1alpha1.IpamStorage{}) - - var m = make(map[schema.GroupVersionResource]string) - - m[schema.GroupVersionResource{ - Group: "ipam.liqo.io", - Version: "v1alpha1", - Resource: "ipamstorages", - }] = "ipamstoragesList" - - dynClient = fake.NewSimpleDynamicClientWithCustomListKinds(scheme, m) - return nil -} - -var _ = Describe("Ipam", func() { - BeforeEach(func() { - ipam = NewIPAM() - err := setDynClient() - Expect(err).To(BeNil()) - n, err := rand.Int(rand.Reader, big.NewInt(10000)) - Expect(err).To(BeNil()) - err = ipam.Init(Pools, dynClient, namespace) - Expect(err).To(BeNil()) - err = ipam.Serve(2000 + int(n.Int64())) - Expect(err).To(BeNil()) - }) - AfterEach(func() { - ipam.Terminate() - }) - - Describe("AcquireReservedSubnet", func() { - Context("When the reserved network equals a network pool", func() { - It("Should successfully reserve the subnet", func() { - // Reserve network - err := ipam.AcquireReservedSubnet("10.0.0.0/8") - Expect(err).To(BeNil()) - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.0.2.0/24", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).ToNot(HavePrefix("10.")) - }) - }) - Context("When the reserved network belongs to a pool", func() { - It("Should not be possible to acquire the same network for a cluster", func() { - err := ipam.AcquireReservedSubnet("10.244.0.0/24") - Expect(err).To(BeNil()) - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.244.0.0/24", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).ToNot(Equal("10.244.0.0/24")) - }) - It("Should not be possible to acquire a larger network that contains it for a cluster", func() { - err := ipam.AcquireReservedSubnet("10.0.0.0/24") - Expect(err).To(BeNil()) - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.0.0.0/16", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).ToNot(Equal("10.0.0.0/16")) - }) - It("Should not be possible to acquire a smaller network contained by it for a cluster", func() { - err := ipam.AcquireReservedSubnet("10.0.2.0/24") - Expect(err).To(BeNil()) - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.0.2.0/25", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).ToNot(Equal("10.0.2.0/25")) - }) - }) - }) - - Describe("FreeReservedSubnet", func() { - Context("Freeing a network that has been reserved previously", func() { - It("Should successfully free the subnet", func() { - err := ipam.AcquireReservedSubnet("10.0.1.0/24") - Expect(err).To(BeNil()) - err = ipam.FreeReservedSubnet("10.0.1.0/24") - Expect(err).To(BeNil()) - err = ipam.AcquireReservedSubnet("10.0.1.0/24") - Expect(err).To(BeNil()) - }) - }) - Context("Freeing a network that does not exists", func() { - It("Should return no errors", func() { - err := ipam.FreeReservedSubnet("10.0.1.0/24") - Expect(err).To(BeNil()) - }) - }) - Context("Freeing a reserved subnet equal to a network pool", func() { - It("Should make available the network pool", func() { - err := ipam.AcquireReservedSubnet("10.0.0.0/8") - Expect(err).To(BeNil()) - err = ipam.FreeReservedSubnet("10.0.0.0/8") - Expect(err).To(BeNil()) - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.0.0.0/16", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(Equal("10.0.0.0/16")) - }) - }) - }) - Describe("Restating manager manager idempotency", func() { - It("ipam should retrieve configuration by resource", func() { - // Assign networks - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.0.1.0/24", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(Equal("10.0.1.0/24")) - - // Simulate re-scheduling - ipam.Terminate() - ipam = NewIPAM() - n, err := rand.Int(rand.Reader, big.NewInt(2000)) - Expect(err).To(BeNil()) - err = ipam.Init(Pools, dynClient, namespace) - Expect(err).To(BeNil()) - err = ipam.Serve(2000 + int(n.Int64())) - Expect(err).To(BeNil()) - - // Ask for the same network again - res, err = ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.0.1.0/24", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).ToNot(Equal("10.0.1.0/24")) - }) - }) - Describe("AddNetworkPool", func() { - Context("Trying to add a default network pool", func() { - It("Should generate an error", func() { - err := ipam.AddNetworkPool("10.0.0.0/8") - Expect(err).ToNot(BeNil()) - }) - }) - Context("Trying to add twice the same network pool", func() { - It("Should generate an error", func() { - err := ipam.AddNetworkPool("11.0.0.0/8") - Expect(err).To(BeNil()) - err = ipam.AddNetworkPool("11.0.0.0/8") - Expect(err).ToNot(BeNil()) - }) - }) - Context("After adding a new network pool", func() { - It("Should be possible to use that pool for cluster networks", func() { - // Reserve default network pools - for _, network := range Pools { - err := fillNetworkPool(network, ipam) - Expect(err).To(BeNil()) - } - - // Add new network pool - err := ipam.AddNetworkPool("11.0.0.0/8") - Expect(err).To(BeNil()) - - // Reserve a given network - err = ipam.AcquireReservedSubnet("12.0.0.0/24") - Expect(err).To(BeNil()) - - // Reserve a given network - err = ipam.AcquireReservedSubnet("12.0.1.0/24") - Expect(err).To(BeNil()) - - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "12.0.0.0/24", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HavePrefix("11")) - Expect(res.Cidr).To(HaveSuffix("/24")) - }) - }) - Context("Trying to add a network pool that overlaps with a reserved network", func() { - It("Should generate an error", func() { - err := ipam.AcquireReservedSubnet("11.0.0.0/8") - Expect(err).To(BeNil()) - err = ipam.AddNetworkPool("11.0.0.0/16") - Expect(err).ToNot(BeNil()) - }) - }) - }) - Describe("RemoveNetworkPool", func() { - Context("Remove a network pool that does not exist", func() { - It("Should return an error", func() { - err := ipam.RemoveNetworkPool("11.0.0.0/8") - Expect(err).ToNot(BeNil()) - }) - }) - Context("Remove a network pool that exists", func() { - It("Should successfully remove the network pool", func() { - // Reserve default network pools - for _, network := range Pools { - err := ipam.AcquireReservedSubnet(network) - Expect(err).To(BeNil()) - } - - // Add new network pool - err := ipam.AddNetworkPool("11.0.0.0/8") - Expect(err).To(BeNil()) - - // Remove network pool - err = ipam.RemoveNetworkPool("11.0.0.0/8") - Expect(err).To(BeNil()) - - // Reserve a given network - err = ipam.AcquireReservedSubnet("12.0.0.0/24") - Expect(err).To(BeNil()) - - // Reserve a given network - err = ipam.AcquireReservedSubnet("12.0.1.0/24") - Expect(err).To(BeNil()) - - _, err = ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "12.0.0.0/24", - }) - Expect(err).To(HaveOccurred()) - }) - }) - Context("Remove a network pool that is a default one", func() { - It("Should generate an error", func() { - err := ipam.RemoveNetworkPool(Pools[0]) - Expect(err).ToNot(BeNil()) - }) - }) - }) - - Describe("GetExternalCIDR", func() { - Context("Invoking it twice", func() { - It("should return no errors", func() { - e, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(e).To(HaveSuffix("/24")) - _, err = ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - }) - }) - Context("Using a valid mask length", func() { - It("should return no errors", func() { - e, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(e).To(HaveSuffix("/24")) - }) - }) - Context("Using an invalid mask length", func() { - It("should return an error", func() { - _, err := ipam.GetExternalCIDR(33) - Expect(err).ToNot(BeNil()) - }) - }) - Context("Call after SetPodCIDR", func() { - It("should return no errors", func() { - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - externalCIDR, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(externalCIDR).To(Equal("10.0.1.0/24")) - }) - }) - Context("Call before SetPodCIDR", func() { - It("should produce an error in SetPodCIDR", func() { - externalCIDR, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(externalCIDR).To(Equal(homePodCIDR)) - // ExternalCIDR has been assigned "10.0.0.0/24", so the network - // is not available anymore. - err = ipam.SetPodCIDR(homePodCIDR) - Expect(err).ToNot(BeNil()) - }) - }) - }) - - Describe("SetPodCIDR", func() { - Context("Invoking func for the first time", func() { - It("should return no errors", func() { - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - }) - }) - Context("Later invocation with the same PodCIDR", func() { - It("should return no errors", func() { - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - err = ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - }) - }) - Context("Later invocation with a different PodCIDR", func() { - It("should return no errors", func() { - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - err = ipam.SetPodCIDR("18.0.0.0/24") - Expect(err).ToNot(BeNil()) - }) - }) - Context("Using a reserved network", func() { - It("should return an error", func() { - err := ipam.AcquireReservedSubnet("10.0.1.0/24") - Expect(err).To(BeNil()) - err = ipam.SetPodCIDR("10.0.1.0/24") - Expect(err).ToNot(BeNil()) - }) - }) - }) - Describe("SetServiceCIDR", func() { - Context("Invoking func for the first time", func() { - It("should return no errors", func() { - err := ipam.SetServiceCIDR("10.0.0.0/24") - Expect(err).To(BeNil()) - }) - }) - Context("Later invocation with the same ServiceCIDR", func() { - It("should return no errors", func() { - err := ipam.SetServiceCIDR("10.0.0.0/24") - Expect(err).To(BeNil()) - err = ipam.SetServiceCIDR("10.0.0.0/24") - Expect(err).To(BeNil()) - }) - }) - Context("Later invocation with a different ServiceCIDR", func() { - It("should return no errors", func() { - err := ipam.SetServiceCIDR("10.0.0.0/24") - Expect(err).To(BeNil()) - err = ipam.SetServiceCIDR("10.0.1.0/24") - Expect(err).ToNot(BeNil()) - }) - }) - Context("Using a reserved network", func() { - It("should return an error", func() { - err := ipam.AcquireReservedSubnet("10.0.1.0/24") - Expect(err).To(BeNil()) - err = ipam.SetServiceCIDR("10.0.1.0/24") - Expect(err).ToNot(BeNil()) - }) - }) - }) - Describe("MapEndpointIP", func() { - Context("If the endpoint IP does not belong to local PodCIDR", func() { - It("should map the endpoint IP to a new IP belonging to local ExternalCIDR", func() { - // Set PodCIDR - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - - // Get ExternalCIDR - externalCIDRResp, err := ipam.GetOrSetExternalCIDR(ctx, &GetOrSetExtCIDRRequest{ - DesiredExtCIDR: homeExternalCIDR, - }) - Expect(err).To(BeNil()) - externalCIDR := externalCIDRResp.GetRemappedExtCIDR() - Expect(externalCIDR).To(HaveSuffix("/24")) - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - response, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - slicedPrefix := strings.SplitN(externalCIDR, ".", 4) - slicedPrefix = slicedPrefix[:len(slicedPrefix)-1] - Expect(response.GetIp()).To(HavePrefix(strings.Join(slicedPrefix, "."))) - }) - It("should return the same IP if more remote clusters ask for the same endpoint", func() { - // Set PodCIDR - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - - // Get ExternalCIDR - externalCIDRResp, err := ipam.GetOrSetExternalCIDR(ctx, &GetOrSetExtCIDRRequest{ - DesiredExtCIDR: homeExternalCIDR, - }) - Expect(err).To(BeNil()) - externalCIDR := externalCIDRResp.GetRemappedExtCIDR() - Expect(externalCIDR).To(HaveSuffix("/24")) - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - resB, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(resB.Cidr).To(HaveSuffix("/16")) - - res2B, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2B.Cidr).To(HaveSuffix("/16")) - - subResB, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: resB.Cidr, - RemappedExternalCIDR: res2B.Cidr, - ClusterID: clusterID2, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subResB).ToNot(BeNil()) - - response, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - slicedPrefix := strings.SplitN(externalCIDR, ".", 4) - slicedPrefix = slicedPrefix[:len(slicedPrefix)-1] - Expect(response.GetIp()).To(HavePrefix(strings.Join(slicedPrefix, "."))) - - responseB, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: "cluster2", - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - slicedPrefix = strings.SplitN(externalCIDR, ".", 4) - slicedPrefix = slicedPrefix[:len(slicedPrefix)-1] - Expect(responseB.GetIp()).To(HavePrefix(strings.Join(slicedPrefix, "."))) - - Expect(response.GetIp()).To(Equal(responseB.GetIp())) - }) - Context("and the ExternalCIDR has not any more available IPs", func() { - It("should return an error", func() { - var response *MapResponse - var err error - // Set PodCIDR - err = ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - - // Get ExternalCIDR - externalCIDR, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(externalCIDR).To(HaveSuffix("/24")) - slicedPrefix := strings.SplitN(externalCIDR, ".", 4) - slicedPrefix = slicedPrefix[:len(slicedPrefix)-1] - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - // Fill up ExternalCIDR - for i := 0; i < 254; i++ { - response, err = ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: fmt.Sprintf("20.0.0.%d", i), - }) - Expect(err).To(BeNil()) - Expect(response.GetIp()).To(HavePrefix(strings.Join(slicedPrefix, "."))) - } - - _, err = ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: "3.100.0.9", - }) - Expect(err).ToNot(BeNil()) - }) - }) - Context("Passing invalid parameters", func() { - It("Empty clusterID", func() { - _, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: "", - Ip: localEndpointIP, - }) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s must be %s", consts.ClusterIDLabelName, ipamerrors.StringNotEmpty))) - }) - It("Non-existing clusterID", func() { - _, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID3, - Ip: localEndpointIP, - }) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s has not a network configuration", clusterID3))) - }) - It("Invalid IP", func() { - _, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID3, - Ip: "10.9.9", - }) - Expect(err.Error()).To(ContainSubstring("Endpoint IP must be a valid IP")) - }) - }) - Context("If the local PodCIDR is not set", func() { - It("should return an error", func() { - // Get ExternalCIDR - externalCIDR, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(externalCIDR).To(HaveSuffix("/24")) - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - _, err = ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: "30.0.4.9", - }) - Expect(err.Error()).To(ContainSubstring("cannot get cluster PodCIDR")) - }) - }) - Context("If the remote cluster has not a network configuration", func() { - It("should return an error", func() { - // Set PodCIDR - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - - _, err = ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: "10.0.0.9", - }) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("cluster %s has not a network configuration", clusterID1))) - }) - }) - }) - }) - - Describe("GetHomePodIP", func() { - Context("Pass function an invalid IP address", func() { - It("should return WrongParameter error", func() { - _, err := ipam.GetHomePodIP(ctx, - &GetHomePodIPRequest{ - Ip: invalidValue, - ClusterID: clusterID1, - }) - err = errors.Unwrap(err) - Expect(err).To(MatchError(fmt.Sprintf("%s must be %s", invalidValue, ipamerrors.ValidIP))) - }) - }) - Context("Pass function an empty cluster ID", func() { - It("should return WrongParameter error", func() { - _, err := ipam.GetHomePodIP(ctx, - &GetHomePodIPRequest{ - Ip: invalidValue, - ClusterID: "", - }) - err = errors.Unwrap(err) - Expect(err).To(MatchError(fmt.Sprintf("%s must be %s", consts.ClusterIDLabelName, ipamerrors.StringNotEmpty))) - }) - }) - Context("Invoking func without subnets init", func() { - It("should return WrongParameter error", func() { - _, err := ipam.GetHomePodIP(ctx, - &GetHomePodIPRequest{ - Ip: "10.0.0.1", - ClusterID: clusterID1, - }) - err = errors.Unwrap(err) - Expect(err).To(MatchError(fmt.Sprintf("cluster %s subnets are not set", clusterID1))) - }) - }) - Context(`When the remote Pod CIDR has not been remapped by home cluster - and the call refers to a remote Pod`, func() { - It("should return the same IP", func() { - ip, _, err := nftables.NetFirstAndLastIP(remotePodCIDR) - Expect(err).To(BeNil()) - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - // Home cluster has not remapped remote PodCIDR - Expect(res.Cidr).To(Equal(remotePodCIDR)) - - response, err := ipam.GetHomePodIP(ctx, - &GetHomePodIPRequest{ - Ip: ip.String(), - ClusterID: clusterID1, - }) - Expect(err).To(BeNil()) - Expect(response.GetHomeIP()).To(Equal(ip.String())) - }) - }) - Context(`When the remote Pod CIDR has been remapped by home cluster - and the call refers to a remote Pod`, func() { - It("should return the remapped IP", func() { - // Original Pod IP - ip, _, err := nftables.NetFirstAndLastIP(remotePodCIDR) - Expect(err).To(BeNil()) - - // Reserve original PodCIDR so that home cluster will remap it - err = ipam.AcquireReservedSubnet(remotePodCIDR) - Expect(err).To(BeNil()) - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - // Home cluster has remapped remote PodCIDR - Expect(res.Cidr).ToNot(Equal(remotePodCIDR)) - - response, err := ipam.GetHomePodIP(ctx, - &GetHomePodIPRequest{ - Ip: ip.String(), - ClusterID: clusterID1, - }) - Expect(err).To(BeNil()) - - // IP should be mapped to remoteNATPodCIDR - remappedIP, err := ipamutils.MapIPToNetwork(res.Cidr, ip.String()) - Expect(err).To(BeNil()) - Expect(response.GetHomeIP()).To(Equal(remappedIP)) - }) - }) - }) - - Describe("UnmapEndpointIP", func() { - Context("Passing invalid parameters", func() { - It("Empty clusterID", func() { - _, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: "", - Ip: localEndpointIP, - }) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s must be %s", consts.ClusterIDLabelName, ipamerrors.StringNotEmpty))) - }) - It("Non-existing clusterID", func() { - _, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID3, - Ip: localEndpointIP, - }) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s has not a network configuration", clusterID3))) - }) - It("Invalid IP", func() { - _, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID3, - Ip: "10.9.9", - }) - Expect(err.Error()).To(ContainSubstring("Endpoint IP must be a valid IP")) - }) - }) - Context("If there are no more clusters using an endpointIP", func() { - It("should free the relative IP", func() { - endpointIP := endpointIP - // Set PodCIDR - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - - // Get ExternalCIDR - externalCIDR, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(externalCIDR).To(HaveSuffix("/24")) - slicedPrefix := strings.SplitN(externalCIDR, ".", 4) - slicedPrefix = slicedPrefix[:len(slicedPrefix)-1] - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - resB, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(resB.Cidr).To(HaveSuffix("/16")) - - res2B, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2B.Cidr).To(HaveSuffix("/16")) - - subResB, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: resB.Cidr, - RemappedExternalCIDR: res2B.Cidr, - ClusterID: clusterID2, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subResB).ToNot(BeNil()) - - // Reflection in cluster1 - response, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - Expect(response.GetIp()).To(HavePrefix(strings.Join(slicedPrefix, "."))) - - // Reflection in cluster2 - _, err = ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID2, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - - // Terminate reflection in cluster1 - _, err = ipam.UnmapEndpointIP(ctx, &UnmapRequest{ - ClusterID: clusterID1, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - - // Terminate reflection in cluster2 - _, err = ipam.UnmapEndpointIP(ctx, &UnmapRequest{ - ClusterID: clusterID2, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - - // Get Ipam configuration - ipamConfig, err := getIpamStorageResource() - Expect(err).To(BeNil()) - - // Check if IP is freed - Expect(ipamConfig.Spec.EndpointMappings).To(HaveLen(0)) - }) - }) - Context("If there are other clusters using an endpointIP", func() { - It("should not free the relative IP", func() { - // Set PodCIDR - err := ipam.SetPodCIDR(homePodCIDR) - Expect(err).To(BeNil()) - - // Get ExternalCIDR - externalCIDR, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(externalCIDR).To(HaveSuffix("/24")) - slicedPrefix := strings.SplitN(externalCIDR, ".", 4) - slicedPrefix = slicedPrefix[:len(slicedPrefix)-1] - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - resB, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remotePodCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(resB.Cidr).To(HaveSuffix("/16")) - - res2B, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: remoteExternalCIDR, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2B.Cidr).To(HaveSuffix("/16")) - - subResB, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: resB.Cidr, - RemappedExternalCIDR: res2B.Cidr, - ClusterID: clusterID2, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subResB).ToNot(BeNil()) - - // Reflection in cluster1 - response, err := ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID1, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - Expect(response.GetIp()).To(HavePrefix(strings.Join(slicedPrefix, "."))) - ip := response.GetIp() - - // Reflection in cluster2 - _, err = ipam.MapEndpointIP(ctx, &MapRequest{ - ClusterID: clusterID2, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - - // Terminate reflection in cluster2 - _, err = ipam.UnmapEndpointIP(ctx, &UnmapRequest{ - ClusterID: clusterID2, - Ip: endpointIP, - }) - Expect(err).To(BeNil()) - - // Get Ipam configuration - ipamConfig, err := getIpamStorageResource() - Expect(err).To(BeNil()) - - // Check if IP is not freed - Expect(ipamConfig.Spec.EndpointMappings).To(HaveLen(1)) - Expect(ipamConfig.Spec.EndpointMappings[endpointIP].ExternalCIDROriginalIP).To(Equal(ip)) - }) - }) - }) - - Describe("SetReservedSubnets", func() { - var ( - toBeReservedSubnets1 []string - toBeReservedSubnets2 []string - toBeReservedSubnetsIncorrect1 []string - toBeReservedOverlapping1 []string - toBeReservedOverlapping2 []string - toBeReservedOverlapping3 []string - toBeReservedOverlapping4 []string - toBeReservedOverlapping5 []string - toBeReservedOverlapping6 []string - ) - - BeforeEach(func() { - var ( - serviceCidr = "10.210.0.0/16" - podCidr = "10.220.0.0/16" - externalCidr string - ) - Expect(ipam.SetPodCIDR(podCidr)).To(Succeed()) - Expect(ipam.SetServiceCIDR(serviceCidr)).To(Succeed()) - externalCidr, err := ipam.GetExternalCIDR(24) - Expect(err).To(BeNil()) - Expect(externalCidr).To(HaveSuffix("/24")) - - // Assign networks to cluster - res, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.0.0.0/16", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res.Cidr).To(HaveSuffix("/16")) - - res2, err := ipam.MapNetworkCIDR(ctx, &MapCIDRRequest{ - Cidr: "10.1.0.0/16", - }) - Expect(err).ToNot(HaveOccurred()) - Expect(res2.Cidr).To(HaveSuffix("/16")) - - subRes, err := ipam.SetSubnetsPerCluster(ctx, &SetSubnetsPerClusterRequest{ - RemappedPodCIDR: res.Cidr, - RemappedExternalCIDR: res2.Cidr, - ClusterID: clusterID1, - }) - Expect(err).ToNot(HaveOccurred()) - Expect(subRes).ToNot(BeNil()) - - toBeReservedSubnets1 = []string{"192.168.0.0/16", "100.200.0.0/16", "10.200.250.0/24"} - toBeReservedSubnets2 = []string{"192.168.1.0/24", "100.200.0.0/16", "172.16.34.0/24"} - toBeReservedSubnetsIncorrect1 = []string{"192.168.0.0/16", "100.200.0/16", "10.200.250.0/24"} - toBeReservedOverlapping1 = []string{"192.168.1.0/24", "192.168.0.0/16", "172.16.34.0/24"} - toBeReservedOverlapping2 = []string{"192.168.1.0/24", podCidr, "172.16.34.0/24"} - toBeReservedOverlapping3 = []string{"192.168.1.0/24", serviceCidr, "172.16.34.0/24"} - toBeReservedOverlapping4 = []string{"192.168.1.0/24", externalCidr, "172.16.34.0/24"} - toBeReservedOverlapping5 = []string{res.Cidr, "100.200.0/16", "172.16.34.0/24"} - toBeReservedOverlapping6 = []string{res2.Cidr, "100.200.0/16", "172.16.34.0/24"} - }) - - Context("Reserving subnets", func() { - When("Reserving subnets for the first time", func() { - It("should reserve all the the subnets and return nil", func() { - Expect(ipam.SetReservedSubnets(toBeReservedSubnets1)).To(Succeed()) - Expect(ipam.ipamStorage.getReservedSubnets()).To(ContainElements(toBeReservedSubnets1)) - checkForPrefixes(toBeReservedSubnets1) - }) - }) - - When("Reserving subnets multiple times", func() { - It("should return nil", func() { - // Reserving the first time. - Expect(ipam.SetReservedSubnets(toBeReservedSubnets1)).To(Succeed()) - Expect(ipam.ipamStorage.getReservedSubnets()).To(ContainElements(toBeReservedSubnets1)) - // Reserving the second time. - Expect(ipam.SetReservedSubnets(toBeReservedSubnets1)).To(Succeed()) - Expect(ipam.ipamStorage.getReservedSubnets()).To(ContainElements(toBeReservedSubnets1)) - checkForPrefixes(toBeReservedSubnets1) - }) - }) - - When("Reserving a list of subnets with incorrect ones", func() { - It("should reserve all the correct ones that comes before the incorrect one", func() { - Expect(ipam.SetReservedSubnets(toBeReservedSubnetsIncorrect1)).To(HaveOccurred()) - Expect(ipam.ipamStorage.getReservedSubnets()).To(HaveLen(1)) - Expect(ipam.ipamStorage.getReservedSubnets()).To(ContainElement(toBeReservedSubnetsIncorrect1[0])) - }) - }) - - When("A subnet has been added to the reserved list but non effectively acquired", func() { - It("should acquire the reserved subnet", func() { - Expect(ipam.SetReservedSubnets(toBeReservedSubnets1)).To(Succeed()) - Expect(ipam.ipamStorage.getReservedSubnets()).To(ContainElements(toBeReservedSubnets1)) - // Remove the prefix from. - _, err := ipam.ipamStorage.DeletePrefix(context.TODO(), *ipam.ipam.PrefixFrom(context.TODO(), toBeReservedSubnets1[1])) - Expect(err).To(BeNil()) - Expect(ipam.SetReservedSubnets(toBeReservedSubnets1)).To(Succeed()) - Expect(ipam.ipam.PrefixFrom(context.TODO(), toBeReservedSubnets1[1]).Cidr).To(Equal(toBeReservedSubnets1[1])) - }) - }) - - When("Subnets to be reserved overlaps with each other", func() { - It("should fail while reserving the subnet that overlaps", func() { - Expect(ipam.SetReservedSubnets(toBeReservedOverlapping1)).NotTo(Succeed()) - }) - }) - - When("Subnets to be reserved overlaps with pod CIDR ", func() { - It("should fail while reserving the subnet that overlaps", func() { - Expect(ipam.SetReservedSubnets(toBeReservedOverlapping2)).NotTo(Succeed()) - }) - }) - - When("Subnets to be reserved overlaps with service CIDR ", func() { - It("should fail while reserving the subnet that overlaps", func() { - Expect(ipam.SetReservedSubnets(toBeReservedOverlapping3)).NotTo(Succeed()) - }) - }) - - When("Subnets to be reserved overlaps with external CIDR ", func() { - It("should fail while reserving the subnet that overlaps", func() { - Expect(ipam.SetReservedSubnets(toBeReservedOverlapping4)).NotTo(Succeed()) - }) - }) - - When("Subnets to be reserved overlaps with pod CIDR of a remote cluster ", func() { - It("should fail while reserving the subnet that overlaps", func() { - Expect(ipam.SetReservedSubnets(toBeReservedOverlapping5)).NotTo(Succeed()) - }) - }) - - When("Subnets to be reserved overlaps with external CIDR of a remote cluster ", func() { - It("should fail while reserving the subnet that overlaps", func() { - Expect(ipam.SetReservedSubnets(toBeReservedOverlapping6)).NotTo(Succeed()) - }) - }) - }) - - Context("Making available subnets previously reserved", func() { - JustBeforeEach(func() { - // Reserve the subnets. - Expect(ipam.SetReservedSubnets(toBeReservedSubnets1)).To(Succeed()) - Expect(ipam.ipamStorage.getReservedSubnets()).To(ContainElements(toBeReservedSubnets1)) - checkForPrefixes(toBeReservedSubnets1) - }) - When("reserved subnets are no more needed", func() { - It("should remove all the previously reserved networks", func() { - Expect(ipam.SetReservedSubnets(nil)).To(BeNil()) - Expect(ipam.ipamStorage.getReservedSubnets()).Should(HaveLen(0)) - }) - }) - - When("new subnets are reserved and existing ones are freed", func() { - It("should return nil and update the reserved subnets", func() { - Expect(ipam.SetReservedSubnets(toBeReservedSubnets2)).To(Succeed()) - Expect(ipam.ipamStorage.getReservedSubnets()).To(ContainElements(toBeReservedSubnets2)) - checkForPrefixes(toBeReservedSubnets2) - }) - }) - }) - }) - - Describe("BelongsToPodCIDR", func() { - BeforeEach(func() { - Expect(ipam.ipamStorage.updatePodCIDR("10.244.0.0/16")).To(Succeed()) - }) - Context("Calling it on an IP in the pod CIDR", func() { - It("should return true", func() { - response, err := ipam.BelongsToPodCIDR(ctx, &BelongsRequest{Ip: "10.244.0.1"}) - Expect(err).ToNot(HaveOccurred()) - Expect(response.GetBelongs()).To(BeTrue()) - }) - }) - Context("Calling it on an IP not in the pod CIDR", func() { - It("should return false", func() { - response, err := ipam.BelongsToPodCIDR(ctx, &BelongsRequest{Ip: "1.2.3.4"}) - Expect(err).ToNot(HaveOccurred()) - Expect(response.GetBelongs()).To(BeFalse()) - }) - }) - Context("Calling it on an invalid IP", func() { - It("should return an error", func() { - _, err := ipam.BelongsToPodCIDR(ctx, &BelongsRequest{Ip: "10.9.9"}) - Expect(err).To(HaveOccurred()) - }) - }) - }) -}) - -func checkForPrefixes(subnets []string) { - for _, s := range subnets { - prefix, err := ipam.ipamStorage.ReadPrefix(context.TODO(), s) - Expect(err).ToNot(HaveOccurred()) - Expect(prefix.Cidr).To(Equal(s)) - } -} - -func getIpamStorageResource() (*ipamv1alpha1.IpamStorage, error) { - ipamConfig := &ipamv1alpha1.IpamStorage{} - list, err := dynClient.Resource(ipamv1alpha1.IpamStorageGroupVersionResource).Namespace(namespace).List( - ctx, - v1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", - consts.IpamStorageResourceLabelKey, - consts.IpamStorageResourceLabelValue), - }, - ) - if err != nil { - return nil, err - } - if len(list.Items) == 0 { - return nil, k8serrors.NewNotFound(ipamv1alpha1.IpamStorageGroupResource, "") - } - err = runtime.DefaultUnstructuredConverter.FromUnstructured(list.Items[0].Object, ipamConfig) - if err != nil { - return nil, err - } - return ipamConfig, nil -} diff --git a/pkg/ipamold/options.go b/pkg/ipamold/options.go deleted file mode 100644 index b0ac0cfc8d..0000000000 --- a/pkg/ipamold/options.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ipam - -import ( - "time" - - "github.com/liqotech/liqo/pkg/utils/args" -) - -// Options contains the options for the IPAM. -type Options struct { - PodCIDR args.CIDR - ServiceCIDR args.CIDR - - AdditionalPools args.CIDRList - ReservedPools args.CIDRList - - LeaseEnabled bool - LeaseDuration time.Duration - LeaseRenewDeadline time.Duration - LeaseRetryPeriod time.Duration - - LabelLeader bool -} - -// NewOptions returns a new Options struct. -func NewOptions() *Options { - return &Options{} -} diff --git a/pkg/ipamold/utils/doc.go b/pkg/ipamold/utils/doc.go deleted file mode 100644 index 9efbc00809..0000000000 --- a/pkg/ipamold/utils/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package utils contain utility functions for the IPAM package. -package utils diff --git a/pkg/ipamold/utils/utils.go b/pkg/ipamold/utils/utils.go deleted file mode 100644 index 68b1bb8ef1..0000000000 --- a/pkg/ipamold/utils/utils.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import ( - "fmt" - "net" - "net/netip" - - "go4.org/netipx" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - - "github.com/liqotech/liqo/pkg/consts" -) - -// MapIPToNetwork creates a new IP address obtained by means of the old IP address and the new network. -func MapIPToNetwork(newNetwork, oldIP string) (newIP string, err error) { - if newNetwork == consts.DefaultCIDRValue { - return oldIP, nil - } - // Parse newNetwork - ip, network, err := net.ParseCIDR(newNetwork) - if err != nil { - return "", err - } - // Get mask - mask := network.Mask - // Get slice of bytes for newNetwork - // Type net.IP has underlying type []byte - parsedNewIP := ip.To4() - // Get oldIP as slice of bytes - parsedOldIP := net.ParseIP(oldIP) - if parsedOldIP == nil { - return "", fmt.Errorf("cannot parse oldIP") - } - parsedOldIP = parsedOldIP.To4() - // Substitute the last 32-mask bits of newNetwork with bits taken by the old ip - for i := 0; i < len(mask); i++ { - // Step 1: NOT(mask[i]) = mask[i] ^ 0xff. They are the 'host' bits - // Step 2: BITWISE AND between the host bits and parsedOldIP[i] zeroes the network bits in parsedOldIP[i] - // Step 3: BITWISE OR copies the result of step 2 in newIP[i] - parsedNewIP[i] |= (mask[i] ^ 0xff) & parsedOldIP[i] - } - newIP = parsedNewIP.String() - return -} - -// GetMask retrieves the mask from a CIDR. -func GetMask(network string) uint8 { - _, subnet, err := net.ParseCIDR(network) - utilruntime.Must(err) - ones, _ := subnet.Mask.Size() - return uint8(ones) -} - -// SetMask forges a new cidr from a network cidr and a mask. -func SetMask(network string, mask uint8) string { - _, n, err := net.ParseCIDR(network) - utilruntime.Must(err) - newMask := net.CIDRMask(int(mask), 32) - n.Mask = newMask - return n.String() -} - -// Next used to get the second half of a given network. -func Next(network string) string { - prefix, err := netip.ParsePrefix(network) - utilruntime.Must(err) - // Step 1: Get last IP address of network - // Step 2: Get next IP address - firstIP := netipx.RangeOfPrefix(prefix).To().Next() - prefix = netip.PrefixFrom(firstIP, prefix.Bits()) - return prefix.String() -} - -// IsValidCIDR returns an error if the received CIDR is invalid. -func IsValidCIDR(cidr string) error { - _, _, err := net.ParseCIDR(cidr) - return err -} - -// GetTunnelIP returns the IP address of the tunnel, which is the first external CIDR ip. -func GetTunnelIP(externalCIDR string) (string, error) { - ipPrefix, err := netip.ParsePrefix(externalCIDR) - if err != nil { - return "", err - } - return ipPrefix.Addr().Next().String(), nil -} - -// SplitNetwork returns the two halves that make up a given network. -func SplitNetwork(network string) []string { - halves := make([]string, 2) - - // Get halves mask length. - mask := GetMask(network) - mask++ - - // Get first half CIDR. - halves[0] = SetMask(network, mask) - - // Get second half CIDR. - halves[1] = Next(halves[0]) - - return halves -} diff --git a/pkg/ipamold/utils/utils_suite_test.go b/pkg/ipamold/utils/utils_suite_test.go deleted file mode 100644 index 67d903d40c..0000000000 --- a/pkg/ipamold/utils/utils_suite_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestUtils(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Utils Suite") -} diff --git a/pkg/ipamold/utils/utils_test.go b/pkg/ipamold/utils/utils_test.go deleted file mode 100644 index c26240aa42..0000000000 --- a/pkg/ipamold/utils/utils_test.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019-2024 The Liqo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils_test - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - ipamutils "github.com/liqotech/liqo/pkg/ipamold/utils" -) - -const ( - invalidValue = "invalidValue" - CIDRAddressNetErr = "CIDR address" - labelKey = "ipam.liqo.io/LabelKey" - labelValue = "LabelValue" - annotationKey = "ipam.liqo.io/AnnotationKey" - annotationValue = "AnnotationValue" -) - -var ( - // corev1.Pod impements the client.Object interface. - testPod *corev1.Pod -) - -var _ = Describe("Mapping", func() { - JustBeforeEach(func() { - testPod = &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{ - labelKey: labelValue, - }, - Annotations: map[string]string{ - annotationKey: annotationValue, - }, - }} - }) - - DescribeTable("MapIPToNetwork", - func(oldIp, newPodCidr, expectedIP string, expectedErr string) { - ip, err := ipamutils.MapIPToNetwork(oldIp, newPodCidr) - if expectedErr != "" { - Expect(err.Error()).To(Equal(expectedErr)) - } else { - Expect(err).ToNot(HaveOccurred()) - } - Expect(ip).To(Equal(expectedIP)) - }, - Entry("Mapping 10.2.1.3 to 10.0.4.0/24", "10.0.4.0/24", "10.2.1.3", "10.0.4.3", ""), - Entry("Mapping 10.2.1.128 to 10.0.4.0/24", "10.0.4.0/24", "10.2.1.128", "10.0.4.128", ""), - Entry("Mapping 10.2.1.1 to 10.0.4.0/24", "10.0.4.0/24", "10.2.1.1", "10.0.4.1", ""), - Entry("Mapping 10.2.127.128 to 10.0.128.0/23", "10.0.128.0/23", "10.2.127.128", "10.0.129.128", ""), - Entry("Mapping 10.2.128.128 to 10.0.126.0/23", "10.0.127.0/23", "10.2.128.128", "10.0.127.128", ""), - Entry("Mapping 10.2.128.128 to 10.0.126.0/25", "10.0.126.0/25", "10.2.128.128", "10.0.126.0", ""), - Entry("Using an invalid newPodCidr", "10.0..0/25", "10.2.128.128", "", "invalid CIDR address: 10.0..0/25"), - Entry("Using an invalid oldIp", "10.0.0.0/25", "10.2...128", "", "cannot parse oldIP"), - ) -}) diff --git a/pkg/uninstaller/const.go b/pkg/uninstaller/const.go index 283a5513a3..2323d20a01 100644 --- a/pkg/uninstaller/const.go +++ b/pkg/uninstaller/const.go @@ -93,10 +93,5 @@ var ( labelSelector: metav1.LabelSelector{}, phase: PhaseCleanup, }, - { - gvr: ipamv1alpha1.IpamStorageGroupVersionResource, - labelSelector: metav1.LabelSelector{}, - phase: PhaseCleanup, - }, } ) diff --git a/pkg/uninstaller/deletion.go b/pkg/uninstaller/deletion.go index 0342fffe77..9efca1b50d 100644 --- a/pkg/uninstaller/deletion.go +++ b/pkg/uninstaller/deletion.go @@ -83,20 +83,3 @@ func DeleteIPs(ctx context.Context, client dynamic.Interface) error { return nil } - -// DeleteIpamStorage deletes the IpamStorage installed. -func DeleteIpamStorage(ctx context.Context, client dynamic.Interface) error { - r1 := client.Resource(ipamv1alpha1.IpamStorageGroupVersionResource) - unstructured, err := r1.List(ctx, metav1.ListOptions{}) - if err != nil { - return err - } - - for _, item := range unstructured.Items { - if err := r1.Namespace(item.GetNamespace()).Delete(ctx, item.GetName(), metav1.DeleteOptions{}); err != nil { - return err - } - } - - return nil -} diff --git a/pkg/utils/getters/dataGetters.go b/pkg/utils/getters/dataGetters.go index 1f83ab6ecb..2f74099719 100644 --- a/pkg/utils/getters/dataGetters.go +++ b/pkg/utils/getters/dataGetters.go @@ -22,10 +22,8 @@ import ( "golang.org/x/exp/maps" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/klog/v2" liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1" - ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1" liqoconsts "github.com/liqotech/liqo/pkg/consts" ) @@ -145,29 +143,6 @@ func retrievePortFromService(svc *corev1.Service, portName string, portType core portName, svc.Namespace, svc.Name, svc.Spec.Type) } -// RetrieveNetworkConfiguration returns the podCIDR, serviceCIDR, reservedSubnets and the externalCIDR -// as saved in the ipamstorages.ipam.liqo.io custom resource instance. -func RetrieveNetworkConfiguration(ipamS *ipamv1alpha1.IpamStorage) (*NetworkConfig, error) { - if ipamS.Spec.PodCIDR == "" { - return nil, fmt.Errorf("unable to get network configuration: podCIDR is not set in resource %q", klog.KObj(ipamS)) - } - - if ipamS.Spec.ServiceCIDR == "" { - return nil, fmt.Errorf("unable to get network configuration: serviceCIDR is not set in resource %q", klog.KObj(ipamS)) - } - - if ipamS.Spec.ExternalCIDR == "" { - return nil, fmt.Errorf("unable to get network configuration: externalCIDR is not set %q", klog.KObj(ipamS)) - } - - return &NetworkConfig{ - PodCIDR: ipamS.Spec.PodCIDR, - ServiceCIDR: ipamS.Spec.ServiceCIDR, - ExternalCIDR: ipamS.Spec.ExternalCIDR, - ReservedSubnets: ipamS.Spec.ReservedSubnets, - }, nil -} - // RetrieveClusterIDsFromVirtualNodes returns the remote cluster IDs in a list of VirtualNodes avoiding duplicates. func RetrieveClusterIDsFromVirtualNodes(virtualNodes *offloadingv1beta1.VirtualNodeList) []string { clusterIDs := make(map[string]interface{}) diff --git a/pkg/utils/getters/dataGetters_test.go b/pkg/utils/getters/dataGetters_test.go index 2ec548c500..e99d6ec4d4 100644 --- a/pkg/utils/getters/dataGetters_test.go +++ b/pkg/utils/getters/dataGetters_test.go @@ -22,7 +22,6 @@ import ( corev1 "k8s.io/api/core/v1" liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1" - ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" liqoconst "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/utils/getters" ) @@ -194,72 +193,4 @@ var _ = Describe("DataGetters", func() { }) }) - - Describe("retrieval of network configuration from ipamstorage", func() { - var ( - ipamStorage *ipamv1alpha1.IpamStorage - resNets = []string{"10.1.0.0/16", "192.168.0.0/16"} - podCIDR = "10.200.0.0/16" - serviceCIDR = "10.150.2.0/24" - externalCIDR = "10.201.0.0/16" - netConfig *getters.NetworkConfig - err error - ) - - checkOnError := func() { - Expect(netConfig).To(BeNil()) - Expect(err).To(HaveOccurred()) - } - - BeforeEach(func() { - ipamStorage = &ipamv1alpha1.IpamStorage{ - Spec: ipamv1alpha1.IpamSpec{ - ReservedSubnets: resNets, - ExternalCIDR: externalCIDR, - PodCIDR: podCIDR, - ServiceCIDR: serviceCIDR, - }, - } - }) - - JustBeforeEach(func() { - netConfig, err = getters.RetrieveNetworkConfiguration(ipamStorage) - }) - - Context("when podCIDR has not been set", func() { - BeforeEach(func() { - ipamStorage.Spec.PodCIDR = "" - }) - - It("should return error", checkOnError) - }) - - Context("when externalCIDR has not been set", func() { - BeforeEach(func() { - ipamStorage.Spec.ExternalCIDR = "" - }) - - It("should return error", checkOnError) - }) - - Context("when serviceCIDR has not been set", func() { - BeforeEach(func() { - ipamStorage.Spec.ServiceCIDR = "" - }) - - It("should return error", checkOnError) - }) - - Context("when all fields has been set", func() { - It("should return configuration and nil", func() { - Expect(err).NotTo(HaveOccurred()) - Expect(netConfig).NotTo(BeNil()) - Expect(netConfig.ServiceCIDR).To(Equal(serviceCIDR)) - Expect(netConfig.ExternalCIDR).To(Equal(externalCIDR)) - Expect(netConfig.PodCIDR).To(Equal(podCIDR)) - Expect(netConfig.ReservedSubnets).To(Equal(resNets)) - }) - }) - - }) }) diff --git a/pkg/utils/getters/k8sGetters.go b/pkg/utils/getters/k8sGetters.go index c7287625f1..6a7b4a6639 100644 --- a/pkg/utils/getters/k8sGetters.go +++ b/pkg/utils/getters/k8sGetters.go @@ -44,24 +44,6 @@ import ( vkforge "github.com/liqotech/liqo/pkg/vkMachinery/forge" ) -// GetIPAMStorageByLabel it returns a IPAMStorage instance that matches the given label selector. -func GetIPAMStorageByLabel(ctx context.Context, cl client.Client, lSelector labels.Selector) (*ipamv1alpha1.IpamStorage, error) { - list := new(ipamv1alpha1.IpamStorageList) - if err := cl.List(ctx, list, &client.ListOptions{LabelSelector: lSelector}); err != nil { - return nil, err - } - - switch len(list.Items) { - case 0: - return nil, kerrors.NewNotFound(ipamv1alpha1.IpamStorageGroupResource, ipamv1alpha1.IpamStorageResource) - case 1: - return &list.Items[0], nil - default: - return nil, fmt.Errorf("multiple resources of type %s found for label selector %s", - ipamv1alpha1.IpamStorageGroupVersionResource, lSelector.String()) - } -} - // GetNamespaceMapByLabel returns the NamespaceMapping with the given labels. func GetNamespaceMapByLabel(ctx context.Context, cl client.Client, ns string, lSelector labels.Selector) (*offloadingv1beta1.NamespaceMap, error) { diff --git a/pkg/utils/labels/labelSelectors.go b/pkg/utils/labels/labelSelectors.go index 81dd45e7e3..e53b1ac0b2 100644 --- a/pkg/utils/labels/labelSelectors.go +++ b/pkg/utils/labels/labelSelectors.go @@ -28,17 +28,6 @@ import ( ) var ( - // IPAMStorageLabelSelector selector used to get the ipam storage instance. - IPAMStorageLabelSelector = metav1.LabelSelector{ - MatchExpressions: []metav1.LabelSelectorRequirement{ - { - Key: liqoconst.IpamStorageResourceLabelKey, - Operator: metav1.LabelSelectorOpIn, - Values: []string{liqoconst.IpamStorageResourceLabelValue}, - }, - }, - } - // ClusterIDConfigMapLabelSelector selector used to get the cluster id configmap. ClusterIDConfigMapLabelSelector = metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ diff --git a/pkg/utils/testutil/kubernetes.go b/pkg/utils/testutil/kubernetes.go index 2d4b730401..ff532d7bb1 100644 --- a/pkg/utils/testutil/kubernetes.go +++ b/pkg/utils/testutil/kubernetes.go @@ -19,7 +19,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/record" - ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" liqoconsts "github.com/liqotech/liqo/pkg/consts" ) @@ -48,21 +47,6 @@ func FakeClusterIDConfigMap(namespace, clusterID string) *corev1.ConfigMap { } } -// FakeIPAM returns an IPAM with the specified namespace and name. -func FakeIPAM(namespace string) *ipamv1alpha1.IpamStorage { - return &ipamv1alpha1.IpamStorage{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - }, - Spec: ipamv1alpha1.IpamSpec{ - PodCIDR: PodCIDR, - ServiceCIDR: ServiceCIDR, - ExternalCIDR: ExternalCIDR, - ReservedSubnets: ReservedSubnets, - }, - } -} - // FakeEventRecorder returns an event recorder that can be used to capture events. func FakeEventRecorder(bufferSize int) *record.FakeRecorder { return record.NewFakeRecorder(bufferSize)