@@ -21,7 +21,7 @@ namespace Ocelot.UnitTests.Kubernetes
21
21
public class KubeServiceDiscoveryProviderTests : IDisposable
22
22
{
23
23
private IWebHost _fakeKubeBuilder ;
24
- private ServiceV1 _serviceEntries ;
24
+ private EndpointsV1 _endpointEntries ;
25
25
private Kube _provider ;
26
26
private readonly string _serviceName ;
27
27
private readonly string _namespaces ;
@@ -41,15 +41,15 @@ public KubeServiceDiscoveryProviderTests()
41
41
_port = 8001 ;
42
42
_kubeHost = "localhost" ;
43
43
_fakekubeServiceDiscoveryUrl = $ "http://{ _kubeHost } :{ _port } ";
44
- _serviceEntries = new ServiceV1 ( ) ;
44
+ _endpointEntries = new EndpointsV1 ( ) ;
45
45
_factory = new Mock < IOcelotLoggerFactory > ( ) ;
46
46
47
47
var option = new KubeClientOptions
48
48
{
49
49
ApiEndPoint = new Uri ( _fakekubeServiceDiscoveryUrl ) ,
50
50
AccessToken = "txpc696iUhbVoudg164r93CxDTrKRVWG" ,
51
51
AuthStrategy = KubeClient . KubeAuthStrategy . BearerToken ,
52
- AllowInsecure = true
52
+ AllowInsecure = true ,
53
53
} ;
54
54
55
55
_clientFactory = KubeApiClient . Create ( option ) ;
@@ -58,7 +58,7 @@ public KubeServiceDiscoveryProviderTests()
58
58
var config = new KubeRegistryConfiguration ( )
59
59
{
60
60
KeyOfServiceInK8s = _serviceName ,
61
- KubeNamespace = _namespaces
61
+ KubeNamespace = _namespaces ,
62
62
} ;
63
63
_provider = new Kube ( config , _factory . Object , _clientFactory ) ;
64
64
}
@@ -67,33 +67,29 @@ public KubeServiceDiscoveryProviderTests()
67
67
public void should_return_service_from_k8s ( )
68
68
{
69
69
var token = "Bearer txpc696iUhbVoudg164r93CxDTrKRVWG" ;
70
- var serviceEntryOne = new ServiceV1 ( )
70
+ var endPointEntryOne = new EndpointsV1
71
71
{
72
- Kind = "service " ,
72
+ Kind = "endpoint " ,
73
73
ApiVersion = "1.0" ,
74
74
Metadata = new ObjectMetaV1 ( )
75
75
{
76
- Namespace = "dev"
76
+ Namespace = "dev" ,
77
77
} ,
78
- Spec = new ServiceSpecV1 ( )
79
- {
80
- ClusterIP = "localhost"
81
- } ,
82
- Status = new ServiceStatusV1 ( )
83
- {
84
- LoadBalancer = new LoadBalancerStatusV1 ( )
85
- }
86
78
} ;
87
-
88
- serviceEntryOne . Spec . Ports . Add (
89
- new ServicePortV1 ( )
90
- {
91
- Port = 80
92
- }
93
- ) ;
79
+ var endpointSubsetV1 = new EndpointSubsetV1 ( ) ;
80
+ endpointSubsetV1 . Addresses . Add ( new EndpointAddressV1 ( )
81
+ {
82
+ Ip = "127.0.0.1" ,
83
+ Hostname = "localhost" ,
84
+ } ) ;
85
+ endpointSubsetV1 . Ports . Add ( new EndpointPortV1 ( )
86
+ {
87
+ Port = 80 ,
88
+ } ) ;
89
+ endPointEntryOne . Subsets . Add ( endpointSubsetV1 ) ;
94
90
95
91
this . Given ( x => GivenThereIsAFakeKubeServiceDiscoveryProvider ( _fakekubeServiceDiscoveryUrl , _serviceName , _namespaces ) )
96
- . And ( x => GivenTheServicesAreRegisteredWithKube ( serviceEntryOne ) )
92
+ . And ( x => GivenTheServicesAreRegisteredWithKube ( endPointEntryOne ) )
97
93
. When ( x => WhenIGetTheServices ( ) )
98
94
. Then ( x => ThenTheCountIs ( 1 ) )
99
95
. And ( _ => _receivedToken . ShouldBe ( token ) )
@@ -110,9 +106,9 @@ private void WhenIGetTheServices()
110
106
_services = _provider . Get ( ) . GetAwaiter ( ) . GetResult ( ) ;
111
107
}
112
108
113
- private void GivenTheServicesAreRegisteredWithKube ( ServiceV1 serviceEntries )
109
+ private void GivenTheServicesAreRegisteredWithKube ( EndpointsV1 endpointEntries )
114
110
{
115
- _serviceEntries = serviceEntries ;
111
+ _endpointEntries = endpointEntries ;
116
112
}
117
113
118
114
private void GivenThereIsAFakeKubeServiceDiscoveryProvider ( string url , string serviceName , string namespaces )
@@ -127,14 +123,14 @@ private void GivenThereIsAFakeKubeServiceDiscoveryProvider(string url, string se
127
123
{
128
124
app . Run ( async context =>
129
125
{
130
- if ( context . Request . Path . Value == $ "/api/v1/namespaces/{ namespaces } /services /{ serviceName } ")
126
+ if ( context . Request . Path . Value == $ "/api/v1/namespaces/{ namespaces } /endpoints /{ serviceName } ")
131
127
{
132
128
if ( context . Request . Headers . TryGetValue ( "Authorization" , out var values ) )
133
129
{
134
130
_receivedToken = values . First ( ) ;
135
131
}
136
132
137
- var json = JsonConvert . SerializeObject ( _serviceEntries ) ;
133
+ var json = JsonConvert . SerializeObject ( _endpointEntries ) ;
138
134
context . Response . Headers . Add ( "Content-Type" , "application/json" ) ;
139
135
await context . Response . WriteAsync ( json ) ;
140
136
}
0 commit comments