Skip to content

Commit

Permalink
fix: Add proxy registry key by dest server + name (cherry-pick #21791) (
Browse files Browse the repository at this point in the history
#21794)

Signed-off-by: Leonardo Luz Almeida <[email protected]>
Co-authored-by: Leonardo Luz Almeida <[email protected]>
  • Loading branch information
gcp-cherry-pick-bot[bot] and leoluz authored Feb 5, 2025
1 parent 3345d05 commit efd9c32
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
11 changes: 5 additions & 6 deletions docs/developer-guide/extensions/proxy-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,11 @@ the argocd-secret with key 'some.argocd.secret.key'.
If provided, and multiple services are configured, will have to match
the application destination name or server to have requests properly
forwarded to this service URL. If there are multiple backends for the
same extension this field is required. In this case at least one of
the two will be required: name or server. It is better to provide both
values to avoid problems with applications unable to send requests to
the proper backend service. If only one backend service is
configured, this field is ignored, and all requests are forwarded to
the configured one.
same extension this field is required. In this case, it is necessary
to provide both values to avoid problems with applications unable to
send requests to the proper backend service. If only one backend
service is configured, this field is ignored, and all requests are
forwarded to the configured one.

#### `extensions.backend.services.cluster.name` (*string*)
(optional)
Expand Down
8 changes: 8 additions & 0 deletions server/extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ func appendProxy(registry ProxyRegistry,
}
registry[key] = proxy
}
if service.Cluster.Name != "" && service.Cluster.Server != "" {
key := proxyKey(extName, service.Cluster.Name, service.Cluster.Server)
if _, exist := registry[key]; exist {
return fmt.Errorf("duplicated proxy configuration found for extension key %q", key)
}
registry[key] = proxy
}

return nil
}

Expand Down
26 changes: 17 additions & 9 deletions server/extension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ func TestCallExtension(t *testing.T) {

settings := &settings.ArgoCDSettings{
ExtensionConfig: map[string]string{
"": configYaml,
"ephemeral": "services:\n- url: http://some-server.com",
"": configYaml,
},
Secrets: secrets,
}
Expand Down Expand Up @@ -481,19 +482,21 @@ func TestCallExtension(t *testing.T) {

response1 := "response backend 1"
cluster1Name := "cluster1"
cluster1URL := "url1"
beSrv1 := startBackendTestSrv(response1)
defer beSrv1.Close()

response2 := "response backend 2"
cluster2URL := "cluster2"
cluster2Name := "cluster2"
cluster2URL := "url2"
beSrv2 := startBackendTestSrv(response2)
defer beSrv2.Close()

f.appGetterMock.On("Get", "ns1", "app1").Return(getApp(cluster1Name, "", defaultProjectName), nil)
f.appGetterMock.On("Get", "ns2", "app2").Return(getApp("", cluster2URL, defaultProjectName), nil)

withRbac(f, true, true)
withExtensionConfig(getExtensionConfigWith2Backends(extName, beSrv1.URL, cluster1Name, beSrv2.URL, cluster2URL), f)
withExtensionConfig(getExtensionConfigWith2Backends(extName, beSrv1.URL, cluster1Name, cluster1URL, beSrv2.URL, cluster2Name, cluster2URL), f)
withProject(getProjectWithDestinations("project-name", []string{cluster1Name}, []string{cluster2URL}), f)
withMetrics(f)
withUser(f, "some-user", []string{"group1", "group2"})
Expand Down Expand Up @@ -673,7 +676,7 @@ func TestCallExtension(t *testing.T) {
f.appGetterMock.On("Get", "ns1", "app1").Return(getApp(maliciousName, destinationServer, defaultProjectName), nil)

withRbac(f, true, true)
withExtensionConfig(getExtensionConfigWith2Backends(extName, "url1", "clusterName", "url2", "clusterURL"), f)
withExtensionConfig(getExtensionConfigWith2Backends(extName, "url1", "cluster1Name", "cluster1URL", "url2", "cluster2Name", "cluster2URL"), f)
withProject(getProjectWithDestinations("project-name", nil, []string{"srv1", destinationServer}), f)
withMetrics(f)
withUser(f, "some-user", []string{"group1", "group2"})
Expand Down Expand Up @@ -740,7 +743,7 @@ extensions:
return fmt.Sprintf(cfg, name, url)
}

func getExtensionConfigWith2Backends(name, url1, clusName, url2, clusURL string) string {
func getExtensionConfigWith2Backends(name, url1, clus1Name, clus1URL, url2, clus2Name, clus2URL string) string {
cfg := `
extensions:
- name: %s
Expand All @@ -752,17 +755,22 @@ extensions:
value: '$extension.auth.header'
cluster:
name: %s
server: %s
- url: %s
headers:
- name: Authorization
value: '$extension.auth.header2'
cluster:
name: %s
server: %s
- url: http://test.com
cluster:
name: cl1
- url: http://test2.com
cluster:
name: cl2
`
// second extension is configured with the cluster url rather
// than the cluster name so we can validate that both use-cases
// are working
return fmt.Sprintf(cfg, name, url1, clusName, url2, clusURL)
return fmt.Sprintf(cfg, name, url1, clus1Name, clus1URL, url2, clus2Name, clus2URL)
}

func getExtensionConfigString() string {
Expand Down

0 comments on commit efd9c32

Please sign in to comment.