Skip to content

Commit da0f35a

Browse files
authored
bugfix: propagate eds changes when annotations change. (#10411)
1 parent 5b41985 commit da0f35a

File tree

7 files changed

+54
-5
lines changed

7 files changed

+54
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
changelog:
2+
- type: NON_USER_FACING
3+
issueLink: https://github.com/solo-io/solo-projects/issues/7301
4+
resolvesIssue: true
5+
description: >-
6+
Fixes a bug where EDS updates were not triggered when adding annotations to a service.
7+
Non-user-facing as this was in unreleased version.

projects/gateway2/krtcollections/endpoints.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ type EndpointsForUpstream struct {
136136
func NewEndpointsForUpstream(us UpstreamWrapper, logger *zap.Logger) *EndpointsForUpstream {
137137
// start with a hash of the cluster name. technically we dont need it for krt, as we can compare the upstream name. but it helps later
138138
// to compute the hash we present envoy with.
139+
// add the upstream hash to the clustername, so that if it changes the envoy cluster will become warm again.
140+
clusterName := GetEndpointClusterName(us.Inner)
141+
139142
h := fnv.New64()
140143
h.Write([]byte(us.Inner.GetMetadata().Ref().String()))
144+
// As long as we hash the upstream in the cluster name (due to envoy cluster warming bug), we
145+
// also need to include that in the hash
146+
// see: https://github.com/envoyproxy/envoy/issues/13009
147+
h.Write([]byte(clusterName))
141148
upstreamHash := h.Sum64()
142149

143-
// add the upstream hash to the clustername, so that if it changes the envoy cluster will become warm again.
144-
clusterName := GetEndpointClusterName(us.Inner)
145150
return &EndpointsForUpstream{
146151
LbEps: make(map[PodLocality][]EndpointWithMd),
147152
ClusterName: clusterName,

projects/gateway2/krtcollections/endpoints_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,39 @@ func TestEndpointsForUpstreamWithDiscoveredUpstream(t *testing.T) {
240240
g.Expect(h1).NotTo(Equal(h2), "not expected %v, got %v", h1, h2)
241241
}
242242

243+
// Note: if we find out the envoy bug was fixed (where changed clusters don't warm until EDS updates)
244+
// this test can be removed.
245+
func TestEndpointsForUpstreamWhenUpstreamLabelsAdded(t *testing.T) {
246+
g := gomega.NewWithT(t)
247+
248+
usGen := func() UpstreamWrapper {
249+
return UpstreamWrapper{
250+
Inner: &gloov1.Upstream{
251+
Metadata: &core.Metadata{Name: "name", Namespace: "ns"},
252+
UpstreamType: &gloov1.Upstream_Kube{
253+
Kube: &kubernetes.UpstreamSpec{
254+
ServiceName: "svc",
255+
ServiceNamespace: "ns",
256+
ServicePort: 8080,
257+
},
258+
},
259+
},
260+
}
261+
}
262+
// 2 copies
263+
us1 := usGen()
264+
us2 := usGen()
265+
us2.Inner.DiscoveryMetadata = &gloov1.DiscoveryMetadata{
266+
Labels: map[string]string{
267+
"extra": "label",
268+
},
269+
}
270+
efu1 := NewEndpointsForUpstream(us1, nil)
271+
efu2 := NewEndpointsForUpstream(us2, nil)
272+
273+
g.Expect(efu1.LbEpsEqualityHash).NotTo(Equal(efu2.LbEpsEqualityHash))
274+
}
275+
243276
func TestEndpoints(t *testing.T) {
244277
testCases := []struct {
245278
name string

projects/gateway2/proxy_syncer/cla.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ func (c EndpointResources) Equals(in EndpointResources) bool {
3131

3232
// TODO: this is needed temporary while we don't have the per-upstream translation done.
3333
// once the plugins are fixed to support it, we can have the proxy translation skip upstreams/endpoints and remove this collection
34-
func newEnvoyEndpoints(glooEndpoints krt.Collection[krtcollections.EndpointsForUpstream]) krt.Collection[EndpointResources] {
34+
func newEnvoyEndpoints(glooEndpoints krt.Collection[krtcollections.EndpointsForUpstream], dbg *krt.DebugHandler) krt.Collection[EndpointResources] {
3535
clas := krt.NewCollection(glooEndpoints, func(_ krt.HandlerContext, ep krtcollections.EndpointsForUpstream) *EndpointResources {
3636
return TransformEndpointToResources(ep)
37-
})
37+
}, krt.WithDebugging(dbg), krt.WithName("EnvoyEndpoints"))
3838
return clas
3939
}
4040

projects/gateway2/proxy_syncer/proxy_syncer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func (s *ProxySyncer) Init(ctx context.Context, dbg *krt.DebugHandler) error {
406406
s.k8sGwExtensions.KRTExtensions().Endpoints()...,
407407
), withDebug, krt.WithName("EndpointIRs"))
408408

409-
clas := newEnvoyEndpoints(endpointIRs)
409+
clas := newEnvoyEndpoints(endpointIRs, dbg)
410410

411411
kubeGateways := SetupCollectionDynamic[gwv1.Gateway](
412412
ctx,

projects/gateway2/setup/ggv2setup_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func init() {
115115
}
116116

117117
func TestScenarios(t *testing.T) {
118+
t.Skip("skipping test till we deflake it")
119+
118120
writer.set(t)
119121
os.Setenv("POD_NAMESPACE", "gwtest")
120122
testEnv := &envtest.Environment{

projects/gloo/pkg/translator/translator.go

+2
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ func GetEndpointClusterName(clusterName string, upstream *v1.Upstream) (string,
415415
if err != nil {
416416
return "", err
417417
}
418+
//note: we add the upstream hash here because of
419+
// https://github.com/envoyproxy/envoy/issues/13009
418420
endpointClusterName := fmt.Sprintf("%s-%d", clusterName, hash)
419421
return endpointClusterName, nil
420422
}

0 commit comments

Comments
 (0)