Giter VIP home page Giter VIP logo

Comments (14)

shcant avatar shcant commented on June 7, 2024 2

You are right. It will be better if ports have different hosts, but in some special cases we can use custom provider to override it. I would like once again to thank you for your patience.

from ocelot.

shcant avatar shcant commented on June 7, 2024 1

I'm sorry for the late reply. For example, my web service on k8s expose two ports: https for 443 and http for 80, like this:

Name:         example-web
Namespace:    default
Subsets:
  Addresses:          10.1.161.59
  Ports:
    Name   Port  Protocol
    ----   ----  --------
    https  443  TCP
    http   80  TCP

I use ocelot as the entry of my service. If I access some API like 'http://example-web/api/example/1', ocelot will redirect the request to the address like 'http://10.1.161.59:443' . The hostname can be parsed correctly, but port is wrong.

I try to specify DownstreamScheme=http in ocelot but k8s provider still choose the https port:

    {
      "DownstreamPathTemplate": "/{url}",
      "DownstreamScheme": "http",
      "UpstreamPathTemplate": "/api/example/{url}",
      "ServiceName": "example-web",
      "UpstreamHttpMethod": [ "Get"]
    }

Then I check the source code, find k8s service discovery only select the first one :

services.AddRange(subset.Addresses.Select(address => new Service(endpoint.Metadata.Name,
    new ServiceHostAndPort(address.Ip, subset.Ports.First().Port),
    endpoint.Metadata.Uid, string.Empty, Enumerable.Empty<string>())));

It will be fine if we can use the port with specific name, like 'https' or 'http'.

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

I don't understand you!

Describe your user scenario in details please!
Attach all artifacts!

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

Is this issue a bug, a feature or an idea?

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

@RaynaldM Any ideas?
What is this author talking about? ๐Ÿ˜„

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

Thank you for explanation!

So, the problematic method:

private static List<Service> BuildServices(EndpointsV1 endpoint)
{
var services = new List<Service>();
foreach (var subset in endpoint.Subsets)
{
services.AddRange(subset.Addresses.Select(address => new Service(endpoint.Metadata.Name,
new ServiceHostAndPort(address.Ip, subset.Ports.First().Port),
endpoint.Metadata.Uid, string.Empty, Enumerable.Empty<string>())));
}
return services;
}

and especially this line of the code:

new ServiceHostAndPort(address.Ip, subset.Ports.First().Port),

where we read subset.Ports.First().Port from the 1st element of Ports collection.
So, the issue is clear now in general: the code works correctly if collection has single port only (count = 1), if count > 1 then the code can behave incorrectly.
But from the view point of the design it is unclear how to build Service object having multiple ports?
Should we create a separate Service objects? And will these Service object be mapped to DownstreamHostAndPort objects?
A lot of questions...

Will you contribute to redesign Kube provider? Do you have draft version of a new solution?

My understanding, we have to decouple Service object creation logic to a new interface and inject it, or introduce a new interface with a new BuildServices method, like this ๐Ÿ‘‰

Design 1

using KubeClient.Models;

public interface IKubeServiceCreator
{
    IEnumerable<Service> Create(EndpointsV1 endpoint, EndpointSubsetV1 subset);
}

// class Kube
private readonly IKubeServiceCreator _serviceCreator;

public Kube(
    KubeRegistryConfiguration kubeRegistryConfiguration, IOcelotLoggerFactory factory, IKubeApiClient kubeApi, // old injections
    IKubeServiceCreator serviceCreator) // new injected service object
{
        // ...
        _serviceCreator = serviceCreator;
}

// We have to rewrite Build method
private List<Service> BuildServices(EndpointsV1 endpoint)
{
        var services = new List<Service>();

        foreach (var subset in endpoint.Subsets)
        {
            services.AddRange(_serviceCreator.Create(endpoint, subset));
        }

        return services;
}

But... My personal preference is wrapping logic of entire BuildServices method

Design 2

using KubeClient.Models;

public interface IKubeServiceBuilder
{
    IEnumerable<Service> BuildServices(EndpointsV1 endpoint);
}

// class Kube
private readonly IKubeServiceBuilder _serviceBuilder;

public Kube(
    KubeRegistryConfiguration kubeRegistryConfiguration, IOcelotLoggerFactory factory, IKubeApiClient kubeApi, // old injections
    IKubeServiceBuilder serviceBuilder) // new injected service object
{
        // ...
        _serviceBuilder = serviceBuilder;
}

// We have to remove static Build method and rewrite GetAsync method
public async Task<List<Service>> GetAsync()
{
        // ...
        if (endpoint != null && endpoint.Subsets.Any())
        {
            services.AddRange(_serviceBuilder.BuildServices(endpoint));
        }
        // ...
        return services;
}

@shcant
Which design do you like?

I have additional 3rd idea for Design 3... ๐Ÿ˜‰ having an options of feature.

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

Oh, I forgot about absolutely independent design and development by your own of a Custom Provider! ๐Ÿ˜„

You can develop new type of SD provider even without us. You need to copy-paste Kube class and redevelop, or inherit Kube class and override methods, and inject required objects by instructions in our docs

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

But you define multiple downstream service ports of one route.
In theory one endpoint can have multiple bounded protocols (ports) but it is overhead deployments.
Seems it should be one route with multiple downstream pairs of host & port of this property of the DownstreamRoute class:

public List<DownstreamHostAndPort> DownstreamAddresses { get; }

if the host will be the same part ports are different then it is a bit strange for load balancing scenario...
My understanding hosts should be different. But Yes, in theory one service instances have different ports of the same host...
Seems there is no issue...

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

Hi @shcant! What's your full name and LinkedIn?
Did/Do not you have an intention to contribute?

I've decided to re-open the issue because I want to re-design K8s provider and introduce more flexibility in the provider. So, we will decouple the current default implementation into 1 or 2 additional interfaces with adding to DI.
My proposals are here in my past comment with draft design!

from ocelot.

shcant avatar shcant commented on June 7, 2024

Hi raman, thank you for your kindness again. I may not contribute due to my personal schedule, but still pay attention to the feature and provide feedback. I am very honored to your invitation. @raman-m

from ocelot.

raman-m avatar raman-m commented on June 7, 2024

@shcant Lazy bones! ๐Ÿ˜‰
๐Ÿ†— I will open a PR when started work for March'24 release by my own. The issue is assigned to me. So, I'll care about...
But I will ask you to review hoping that you'll have enough time for that, cause you are the author of the issue.

from ocelot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.