Skip to content

Commit 6c4b089

Browse files
giorio94adamjensenbot
authored andcommitted
Virtual kubelet: working queue-based endpointslice reflection
1 parent 3c649c2 commit 6c4b089

File tree

18 files changed

+924
-620
lines changed

18 files changed

+924
-620
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Package test provides a mock type for IPAM module
16-
package test
15+
// Package fake implements fake IPAM grpc interfaces for testing purposes.
16+
package fake

pkg/liqonet/ipam/fake/ipam.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2019-2021 The Liqo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package fake
16+
17+
import (
18+
"context"
19+
"fmt"
20+
21+
grpc "google.golang.org/grpc"
22+
23+
"github.com/liqotech/liqo/pkg/liqonet/ipam"
24+
"github.com/liqotech/liqo/pkg/liqonet/utils"
25+
)
26+
27+
// IPAMClient provides a mock implementation of the IPAMClient interface for testing purposes.
28+
type IPAMClient struct {
29+
localRemappedPodCIDR string
30+
remoteRemappedPodCIDR string
31+
enforceSingleRequest bool
32+
33+
pods map[string]string
34+
endpoints map[string]string
35+
}
36+
37+
// NewIPAMClient returns a new fake IPAMClient.
38+
func NewIPAMClient(localRemappedPodCIDR, remoteRemappedPodCIDR string, enforceSingleRequest bool) *IPAMClient {
39+
return &IPAMClient{
40+
localRemappedPodCIDR: localRemappedPodCIDR,
41+
remoteRemappedPodCIDR: remoteRemappedPodCIDR,
42+
enforceSingleRequest: true,
43+
44+
pods: make(map[string]string),
45+
endpoints: make(map[string]string),
46+
}
47+
}
48+
49+
// MapEndpointIP mocks the corresponding IPAMClient function.
50+
func (mock *IPAMClient) MapEndpointIP(_ context.Context, req *ipam.MapRequest, _ ...grpc.CallOption) (*ipam.MapResponse, error) {
51+
// Check first if the translation has already been computed.
52+
if translation, found := mock.endpoints[req.GetIp()]; found {
53+
if mock.enforceSingleRequest {
54+
return nil, fmt.Errorf("mapping for IP %v already requested", req.GetIp())
55+
}
56+
return &ipam.MapResponse{Ip: translation}, nil
57+
}
58+
59+
ip, err := utils.MapIPToNetwork(mock.localRemappedPodCIDR, req.GetIp())
60+
if err != nil {
61+
return nil, err
62+
}
63+
mock.endpoints[req.GetIp()] = ip
64+
return &ipam.MapResponse{Ip: ip}, nil
65+
}
66+
67+
// UnmapEndpointIP mocks the corresponding IPAMClient function.
68+
func (mock *IPAMClient) UnmapEndpointIP(_ context.Context, req *ipam.UnmapRequest, _ ...grpc.CallOption) (*ipam.UnmapResponse, error) {
69+
// Check first if the translation has already been removed.
70+
if _, found := mock.endpoints[req.GetIp()]; !found && mock.enforceSingleRequest {
71+
return nil, fmt.Errorf("unmapping for IP %v already requested", req.GetIp())
72+
}
73+
delete(mock.endpoints, req.GetIp())
74+
return &ipam.UnmapResponse{}, nil
75+
}
76+
77+
// IsEndpointTranslated returns whether the given endpoint has a valid translation.
78+
func (mock *IPAMClient) IsEndpointTranslated(ip string) bool {
79+
_, found := mock.endpoints[ip]
80+
return found
81+
}
82+
83+
// GetHomePodIP mocks the corresponding IPAMClient function.
84+
func (mock *IPAMClient) GetHomePodIP(_ context.Context, req *ipam.GetHomePodIPRequest, _ ...grpc.CallOption) (*ipam.GetHomePodIPResponse, error) {
85+
// Check first if the translation has already been computed.
86+
if translation, found := mock.pods[req.GetIp()]; found {
87+
if mock.enforceSingleRequest {
88+
return nil, fmt.Errorf("mapping for IP %v already requested", req.GetIp())
89+
}
90+
return &ipam.GetHomePodIPResponse{HomeIP: translation}, nil
91+
}
92+
93+
homeIP, err := utils.MapIPToNetwork(mock.remoteRemappedPodCIDR, req.GetIp())
94+
if err != nil {
95+
return nil, err
96+
}
97+
mock.pods[req.GetIp()] = homeIP
98+
return &ipam.GetHomePodIPResponse{HomeIP: homeIP}, nil
99+
}

pkg/liqonet/test/ipam_mock.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

pkg/virtualKubelet/apiReflection/const.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package apiReflection
1616

1717
const (
1818
Configmaps = iota
19-
EndpointSlices
2019
Pods
2120
ReplicaSets
2221
Secrets
@@ -25,11 +24,10 @@ const (
2524
type ApiType int
2625

2726
var ApiNames = map[ApiType]string{
28-
Configmaps: "configmaps",
29-
EndpointSlices: "endpointslices",
30-
Pods: "pods",
31-
ReplicaSets: "replicasets",
32-
Secrets: "secrets",
27+
Configmaps: "configmaps",
28+
Pods: "pods",
29+
ReplicaSets: "replicasets",
30+
Secrets: "secrets",
3331
}
3432

3533
type ApiEvent struct {

pkg/virtualKubelet/apiReflection/reflectors/blacklists.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,5 @@ type blackListType map[string]struct{}
2424
// the blacklist is generally checked in the `isAllowed` method of the reflectors
2525
// TODO: in a future version we could/should move to a dynamic blaklisting package with contexts.
2626
var Blacklist = map[apimgmt.ApiType]blackListType{
27-
apimgmt.EndpointSlices: {
28-
"default/kubernetes": struct{}{},
29-
},
3027
apimgmt.Pods: {},
3128
}

pkg/virtualKubelet/apiReflection/reflectors/outgoing/apiTypes.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,20 @@
1515
package outgoing
1616

1717
import (
18-
"fmt"
19-
20-
"google.golang.org/grpc"
21-
"k8s.io/klog/v2"
22-
23-
liqoconst "github.com/liqotech/liqo/pkg/consts"
24-
liqonetIpam "github.com/liqotech/liqo/pkg/liqonet/ipam"
2518
apimgmt "github.com/liqotech/liqo/pkg/virtualKubelet/apiReflection"
2619
ri "github.com/liqotech/liqo/pkg/virtualKubelet/apiReflection/reflectors/reflectorsInterfaces"
2720
"github.com/liqotech/liqo/pkg/virtualKubelet/options"
28-
"github.com/liqotech/liqo/pkg/virtualKubelet/options/types"
2921
)
3022

3123
var ReflectorBuilders = map[apimgmt.ApiType]func(reflector ri.APIReflector, opts map[options.OptionKey]options.Option) ri.OutgoingAPIReflector{
32-
apimgmt.Configmaps: configmapsReflectorBuilder,
33-
apimgmt.EndpointSlices: endpointslicesReflectorBuilder,
34-
apimgmt.Secrets: secretsReflectorBuilder,
24+
apimgmt.Configmaps: configmapsReflectorBuilder,
25+
apimgmt.Secrets: secretsReflectorBuilder,
3526
}
3627

3728
func configmapsReflectorBuilder(reflector ri.APIReflector, _ map[options.OptionKey]options.Option) ri.OutgoingAPIReflector {
3829
return &ConfigmapsReflector{APIReflector: reflector}
3930
}
4031

41-
func endpointslicesReflectorBuilder(reflector ri.APIReflector, opts map[options.OptionKey]options.Option) ri.OutgoingAPIReflector {
42-
conn, err := grpc.Dial(fmt.Sprintf("%s:%d", opts[options.OptionKey(types.LiqoIpamServer)].Value(), liqoconst.NetworkManagerIpamPort),
43-
grpc.WithInsecure(),
44-
grpc.WithBlock())
45-
if err != nil {
46-
klog.Error(err)
47-
}
48-
ipamClient := liqonetIpam.NewIpamClient(conn)
49-
50-
return &EndpointSlicesReflector{
51-
APIReflector: reflector,
52-
VirtualNodeName: opts[types.VirtualNodeName],
53-
IpamClient: ipamClient,
54-
}
55-
}
56-
5732
func secretsReflectorBuilder(reflector ri.APIReflector, _ map[options.OptionKey]options.Option) ri.OutgoingAPIReflector {
5833
return &SecretsReflector{APIReflector: reflector}
5934
}

0 commit comments

Comments
 (0)