Skip to content

Commit c6112c0

Browse files
fix: Add proxy registry key by dest server + name (cherry-pick #21791) (#21793)
Signed-off-by: Leonardo Luz Almeida <[email protected]> Co-authored-by: Leonardo Luz Almeida <[email protected]>
1 parent 49771c1 commit c6112c0

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

docs/developer-guide/extensions/proxy-extensions.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,11 @@ the argocd-secret with key 'some.argocd.secret.key'.
181181
If provided, and multiple services are configured, will have to match
182182
the application destination name or server to have requests properly
183183
forwarded to this service URL. If there are multiple backends for the
184-
same extension this field is required. In this case at least one of
185-
the two will be required: name or server. It is better to provide both
186-
values to avoid problems with applications unable to send requests to
187-
the proper backend service. If only one backend service is
188-
configured, this field is ignored, and all requests are forwarded to
189-
the configured one.
184+
same extension this field is required. In this case, it is necessary
185+
to provide both values to avoid problems with applications unable to
186+
send requests to the proper backend service. If only one backend
187+
service is configured, this field is ignored, and all requests are
188+
forwarded to the configured one.
190189

191190
#### `extensions.backend.services.cluster.name` (*string*)
192191
(optional)

server/extension/extension.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,14 @@ func appendProxy(registry ProxyRegistry,
640640
}
641641
registry[key] = proxy
642642
}
643+
if service.Cluster.Name != "" && service.Cluster.Server != "" {
644+
key := proxyKey(extName, service.Cluster.Name, service.Cluster.Server)
645+
if _, exist := registry[key]; exist {
646+
return fmt.Errorf("duplicated proxy configuration found for extension key %q", key)
647+
}
648+
registry[key] = proxy
649+
}
650+
643651
return nil
644652
}
645653

server/extension/extension_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ func TestCallExtension(t *testing.T) {
369369

370370
settings := &settings.ArgoCDSettings{
371371
ExtensionConfig: map[string]string{
372-
"": configYaml,
372+
"ephemeral": "services:\n- url: http://some-server.com",
373+
"": configYaml,
373374
},
374375
Secrets: secrets,
375376
}
@@ -499,19 +500,21 @@ func TestCallExtension(t *testing.T) {
499500

500501
response1 := "response backend 1"
501502
cluster1Name := "cluster1"
503+
cluster1URL := "url1"
502504
beSrv1 := startBackendTestSrv(response1)
503505
defer beSrv1.Close()
504506

505507
response2 := "response backend 2"
506-
cluster2URL := "cluster2"
508+
cluster2Name := "cluster2"
509+
cluster2URL := "url2"
507510
beSrv2 := startBackendTestSrv(response2)
508511
defer beSrv2.Close()
509512

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

513516
withRbac(f, true, true)
514-
withExtensionConfig(getExtensionConfigWith2Backends(extName, beSrv1.URL, cluster1Name, beSrv2.URL, cluster2URL), f)
517+
withExtensionConfig(getExtensionConfigWith2Backends(extName, beSrv1.URL, cluster1Name, cluster1URL, beSrv2.URL, cluster2Name, cluster2URL), f)
515518
withProject(getProjectWithDestinations("project-name", []string{cluster1Name}, []string{cluster2URL}), f)
516519
withMetrics(f)
517520
withUser(f, "some-user", []string{"group1", "group2"})
@@ -691,7 +694,7 @@ func TestCallExtension(t *testing.T) {
691694
f.appGetterMock.On("Get", "ns1", "app1").Return(getApp(maliciousName, destinationServer, defaultProjectName), nil)
692695

693696
withRbac(f, true, true)
694-
withExtensionConfig(getExtensionConfigWith2Backends(extName, "url1", "clusterName", "url2", "clusterURL"), f)
697+
withExtensionConfig(getExtensionConfigWith2Backends(extName, "url1", "cluster1Name", "cluster1URL", "url2", "cluster2Name", "cluster2URL"), f)
695698
withProject(getProjectWithDestinations("project-name", nil, []string{"srv1", destinationServer}), f)
696699
withMetrics(f)
697700
withUser(f, "some-user", []string{"group1", "group2"})
@@ -758,7 +761,7 @@ extensions:
758761
return fmt.Sprintf(cfg, name, url)
759762
}
760763

761-
func getExtensionConfigWith2Backends(name, url1, clusName, url2, clusURL string) string {
764+
func getExtensionConfigWith2Backends(name, url1, clus1Name, clus1URL, url2, clus2Name, clus2URL string) string {
762765
cfg := `
763766
extensions:
764767
- name: %s
@@ -770,17 +773,22 @@ extensions:
770773
value: '$extension.auth.header'
771774
cluster:
772775
name: %s
776+
server: %s
773777
- url: %s
774778
headers:
775779
- name: Authorization
776780
value: '$extension.auth.header2'
777781
cluster:
782+
name: %s
778783
server: %s
784+
- url: http://test.com
785+
cluster:
786+
name: cl1
787+
- url: http://test2.com
788+
cluster:
789+
name: cl2
779790
`
780-
// second extension is configured with the cluster url rather
781-
// than the cluster name so we can validate that both use-cases
782-
// are working
783-
return fmt.Sprintf(cfg, name, url1, clusName, url2, clusURL)
791+
return fmt.Sprintf(cfg, name, url1, clus1Name, clus1URL, url2, clus2Name, clus2URL)
784792
}
785793

786794
func getExtensionConfigString() string {

0 commit comments

Comments
 (0)