Skip to content

Commit

Permalink
prevent Proxy namespace from being modified
Browse files Browse the repository at this point in the history
Previously, a 'metaKey' was generated for each Proxy being translated
and synced to envoy. This key was used as a 'tag' for tracing of the
translation/sync prcoess. It used a custom function that was almost exactly
matched how the SnapshotCacheKey used for xDS was generated; this function
also modified the actual Proxy's namespace, which broke assumptions of where
the proxy lives in the in-memory client.

By removing the namespace modification we fix various status error logs as
now the Proxy is located where the rest of the system expects (the write
namespace). Also, we can simply use the SnapshotCacheKey(...) to generate
a key with the same logic used for xds.
  • Loading branch information
lgadban authored Jun 17, 2024
1 parent 33f6334 commit 8c8747e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 83 deletions.
5 changes: 5 additions & 0 deletions changelog/v1.17.0-rc5/stop-status-spamming.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/solo-projects/issues/6252
resolvesIssue: true
description: Fix issue where Kube Gateway proxies would have errors regarding status logged constantly
21 changes: 2 additions & 19 deletions projects/gloo/pkg/syncer/envoy_translator_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ import (

"github.com/solo-io/go-utils/contextutils"
"github.com/solo-io/go-utils/hashutils"
"github.com/solo-io/solo-kit/pkg/api/v1/control-plane/cache"
envoycache "github.com/solo-io/solo-kit/pkg/api/v1/control-plane/cache"
"github.com/solo-io/solo-kit/pkg/api/v1/control-plane/types"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
"github.com/solo-io/solo-kit/pkg/api/v2/reporter"

"github.com/solo-io/gloo/pkg/utils/syncutil"
"github.com/solo-io/gloo/projects/gateway2/translator/translatorutils"
gloov1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
v1snap "github.com/solo-io/gloo/projects/gloo/pkg/api/v1/gloosnapshot"
"github.com/solo-io/gloo/projects/gloo/pkg/plugins"
syncerstats "github.com/solo-io/gloo/projects/gloo/pkg/syncer/stats"
"github.com/solo-io/gloo/projects/gloo/pkg/utils"
"github.com/solo-io/gloo/projects/gloo/pkg/xds"
)

Expand Down Expand Up @@ -58,7 +55,7 @@ func init() {
const emptyVersionKey = "empty"

var (
emptyResource = cache.Resources{
emptyResource = envoycache.Resources{
Version: emptyVersionKey,
Items: map[string]envoycache.Resource{},
}
Expand Down Expand Up @@ -128,7 +125,7 @@ func (s *translatorSyncer) syncEnvoy(ctx context.Context, snap *v1snap.ApiSnapsh
var proxiesWithReports []translatorutils.ProxyWithReports
for _, proxy := range snap.Proxies {
proxyCtx := ctx
metaKey := GetKeyFromProxyMeta(proxy)
metaKey := xds.SnapshotCacheKey(proxy)
if ctxWithTags, err := tag.New(proxyCtx, tag.Insert(syncerstats.ProxyNameKey, metaKey)); err == nil {
proxyCtx = ctxWithTags
}
Expand Down Expand Up @@ -234,17 +231,3 @@ func prettify(original interface{}) string {

return string(b)
}

func GetKeyFromProxyMeta(proxy *gloov1.Proxy) string {
meta := proxy.GetMetadata()
metaKey := meta.Ref().Key()
labels := proxy.GetMetadata().GetLabels()
if labels != nil && labels[utils.ProxyTypeKey] == utils.GatewayApiProxyValue {
proxyNamespace := labels[utils.GatewayNamespaceKey]
if proxyNamespace != "" {
meta.Namespace = proxyNamespace
metaKey = meta.Ref().Key()
}
}
return metaKey
}
64 changes: 0 additions & 64 deletions projects/gloo/pkg/syncer/translator_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/solo-io/gloo/projects/gloo/pkg/servers/iosnapshot"

"github.com/solo-io/gloo/pkg/bootstrap/leaderelector/singlereplica"
gloov1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/projects/gloo/pkg/utils"

gloo_translator "github.com/solo-io/gloo/projects/gloo/pkg/translator"

Expand Down Expand Up @@ -344,68 +342,6 @@ var _ = Describe("Translate multiple proxies with errors", func() {

Expect(xdsCache.Called).To(BeTrue())
})

Describe("correctl returns metaKey for proxies", func() {
It("returns the correct key", func() {
// Create a proxy with metadata and labels
proxy := &gloov1.Proxy{
Metadata: &core.Metadata{
Name: "test-proxy",
Namespace: "test-namespace",
Labels: map[string]string{
utils.ProxyTypeKey: utils.GatewayApiProxyValue,
utils.GatewayNamespaceKey: "custom-namespace",
},
},
}

key := GetKeyFromProxyMeta(proxy)

// Assert that the returned key matches the expected value
expectedKey := "custom-namespace.test-proxy"
Expect(key).To(Equal(expectedKey))
})

It("returns the correct key when proxy has no custom namespace label", func() {

// Create a proxy with metadata and labels
proxy := &gloov1.Proxy{
Metadata: &core.Metadata{
Name: "test-proxy",
Namespace: "test-namespace",
Labels: map[string]string{
utils.ProxyTypeKey: utils.GatewayApiProxyValue,
},
},
}

key := GetKeyFromProxyMeta(proxy)

// Assert that the returned key matches the expected value
expectedKey := "test-namespace.test-proxy"
Expect(key).To(Equal(expectedKey))
})

It("returns the correct key when proxy is not a Gloo gateway proxy", func() {
// Create a proxy with metadata and labels
proxy := &gloov1.Proxy{
Metadata: &core.Metadata{
Name: "test-proxy",
Namespace: "test-namespace",
Labels: map[string]string{
utils.ProxyTypeKey: "some-other-value",
utils.GatewayNamespaceKey: "custom-namespace",
},
},
}

key := GetKeyFromProxyMeta(proxy)

// Assert that the returned key matches the expected value
expectedKey := "test-namespace.test-proxy"
Expect(key).To(Equal(expectedKey))
})
})
})

type mockTranslator struct {
Expand Down

0 comments on commit 8c8747e

Please sign in to comment.