istio icon indicating copy to clipboard operation
istio copied to clipboard

Fix Sidecarscope service and destinationrule map

Open hzxuzhonghu opened this issue 1 year ago • 10 comments

Please provide a description of this PR:

Added namespace key for service and dr map, without namespace, istio can ignore some configs if there are many for same hostname but reside in different namespace

Fix #40952

To help us figure out who should review this PR, please put an X in all the areas that this PR affects.

  • [ ] Ambient
  • [ ] Configuration Infrastructure
  • [ ] Docs
  • [ ] Installation
  • [ ] Networking
  • [ ] Performance and Scalability
  • [ ] Policies and Telemetry
  • [ ] Security
  • [ ] Test and Release
  • [ ] User Experience
  • [ ] Developer Infrastructure

Please check any characteristics that apply to this pull request.

  • [ ] Does not have any user-facing changes. This may include CLI changes, API changes, behavior changes, performance improvements, etc.

hzxuzhonghu avatar Sep 20 '22 07:09 hzxuzhonghu

How will this fix https://github.com/istio/istio/issues/40952 ? How did it work earlier? That seems to be caused by some regression?

ramaraochavali avatar Sep 20 '22 08:09 ramaraochavali

I have tested with https://github.com/istio/istio/issues/40952#issuecomment-1246698194

What regression do you mean?

hzxuzhonghu avatar Sep 20 '22 09:09 hzxuzhonghu

I have tested with https://github.com/istio/istio/issues/40952#issuecomment-1246698194

What regression do you mean?

OK. Wondering how did it work on 1.13.2 but not on 1.14.3.? So thought some thing regressed. This change is not there in 1.13.2 also

ramaraochavali avatar Sep 20 '22 09:09 ramaraochavali

@ramaraochavali see this comment https://github.com/istio/istio/issues/40952#issuecomment-1247866691 i figured out

hzxuzhonghu avatar Sep 20 '22 10:09 hzxuzhonghu

see this comment https://github.com/istio/istio/issues/40952#issuecomment-1247866691 i figured out

Got it.

ramaraochavali avatar Sep 20 '22 10:09 ramaraochavali

The intent is that sidecar scope only sees 1 Service per hostname. It's not clear to me why that invariant needs to be violated here?

On Tue, Sep 20, 2022, 6:32 PM Zhonghu Xu @.***> wrote:

@.**** commented on this pull request.

In pilot/pkg/model/push_context.go https://github.com/istio/istio/pull/41062#discussion_r975955595:

func (ps *PushContext) ServiceForHostname(proxy *Proxy, hostname host.Name) *Service { if proxy != nil && proxy.SidecarScope != nil {

  • return proxy.SidecarScope.servicesByHostname[hostname]
    
  • // first return the service from proxy namespace
    
  • if proxy.SidecarScope.servicesByHostname[hostname][proxy.ConfigNamespace] != nil {
    
  • 	return proxy.SidecarScope.servicesByHostname[hostname][proxy.ConfigNamespace]
    
  • }
    
  • // return arbitrary service
    
  • for _, svc := range proxy.SidecarScope.servicesByHostname[hostname] {
    

@howardjohn https://github.com/howardjohn updated comment, actually it is return a service of hostname from other namespaces, but it is also exported to this proxy.

— Reply to this email directly, view it on GitHub https://github.com/istio/istio/pull/41062#discussion_r975955595, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEYGXJZCEONCM4HXKHDFG3V7JQS5ANCNFSM6AAAAAAQQZACKA . You are receiving this because you were mentioned.Message ID: @.***>

howardjohn avatar Sep 21 '22 01:09 howardjohn

The intent is that sidecar scope only sees 1 Service per hostname.

Why, in the issue case, it should see two services with same hostname but in different nses

hzxuzhonghu avatar Sep 21 '22 01:09 hzxuzhonghu

The intent is that sidecar scope only sees 1 Service per hostname.

Why, in the issue case, it should see two services with same hostname but in different nses

Or see 1 Service with 2 destination rules? It seems like perhaps we are attaching the DR hostname to a specific Service too early, before it's filtered by sidecarscope.

Since this is a regression, and we historically used 1 Service in SidecarScope, it seems we should be able to keep that model?

howardjohn avatar Sep 21 '22 02:09 howardjohn

DR selection is very related to proxy namespace and service namespace, I am concerned if changing this could introduce other regresssions

hzxuzhonghu avatar Sep 21 '22 02:09 hzxuzhonghu

@howardjohn WDYT about dr selection?

hzxuzhonghu avatar Sep 22 '22 09:09 hzxuzhonghu

Having SidecarScope have 2 services for 1 hostname is not acceptable imo, it violates the design. We previously had it working, so seems there must be another way

howardjohn avatar Sep 22 '22 19:09 howardjohn

Previously, we donot use sidecar scope for gateway, should we make gateway behave differently with sidecar?

hzxuzhonghu avatar Sep 23 '22 01:09 hzxuzhonghu

Previously, we donot use sidecar scope for gateway, should we make gateway behave differently with sidecar?

Is that how it worked in 1.13.2? I thought we have been using sidecar scope for gateway much before that?

ramaraochavali avatar Sep 23 '22 10:09 ramaraochavali

Is that how it worked in 1.13.2? I thought we have been using sidecar scope for gateway much before that?

Yes, I am super sure, because I tested different commits manually. And figured it out

hzxuzhonghu avatar Sep 24 '22 02:09 hzxuzhonghu

@howardjohn @GregHanson We need to come to a consensus on this, otherwise, my work is a waste.

hzxuzhonghu avatar Sep 24 '22 02:09 hzxuzhonghu

SidecarScope should have 1 service per hostname. If we can keep that constraint I am open to other options, including reverting the PR that originally broke it (I believe it was mine and was meant to just be a refactoring)

howardjohn avatar Sep 26 '22 14:09 howardjohn

TBH, it is also weird for a gateway to see multi services with same hostname in different namespaces. With that, user define a vs bound to the gateway, and traffic can go to any backend service instances across namespaces. The target can be random.

From the security view, if a namespace is owned by a different tenant, the isolation could be very weak. So I doubt how we we should do all that kind of work

hzxuzhonghu avatar Sep 27 '22 02:09 hzxuzhonghu

Hi all, as mentioned in issue#41319 servicesByHostname map[host.Name]*Service can cause issue, so is it okay if consider that make the map key host.Name should be the longest hostname of the service? For example, simpleserver should not be the key, but simpleserver.default.svc.cluster.local can be. does it make sense?

zhlsunshine avatar Oct 18 '22 04:10 zhlsunshine

Currently host.Name is a FQDN

hzxuzhonghu avatar Oct 18 '22 06:10 hzxuzhonghu

@hzxuzhonghu: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

istio-testing avatar Oct 18 '22 22:10 istio-testing