cluster name (#1834)

This commit is contained in:
wasaga 2021-01-29 16:55:38 -05:00 committed by GitHub
parent 67f6030e1e
commit 66ff2cdaba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 19 deletions

View file

@ -243,6 +243,10 @@ func (srv *Server) buildControlPlanePrefixRoute(prefix string, protected bool) (
}
var getPolicyName = func(policy *config.Policy) string {
if policy.EnvoyOpts != nil && policy.EnvoyOpts.Name != "" {
return policy.EnvoyOpts.Name
}
id, _ := policy.RouteID()
return fmt.Sprintf("policy-%x", id)
}

View file

@ -6,6 +6,7 @@ import (
"testing"
"time"
envoy_config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_config_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -936,6 +937,11 @@ func Test_buildPolicyRouteRedirectAction(t *testing.T) {
})
}
func TestPolicyName(t *testing.T) {
assert.Greater(t, getPolicyName(&config.Policy{}), "policy-")
assert.Equal(t, getPolicyName(&config.Policy{EnvoyOpts: &envoy_config_cluster_v3.Cluster{Name: "my-pomerium-cluster"}}), "my-pomerium-cluster")
}
func mustParseURL(t *testing.T, str string) *url.URL {
u, err := url.Parse(str)
require.NoError(t, err, str)