mirror of https://github.com/status-im/consul.git
Refactor `resolveListenerSDSConfig` to pass in whole config
This commit is contained in:
parent
d779a4fc2c
commit
6faf85bccd
|
@ -28,7 +28,7 @@ func (s *ResourceGenerator) makeIngressGatewayListeners(address string, cfgSnap
|
|||
connectTLSEnabled := cfgSnap.IngressGateway.TLSConfig.Enabled ||
|
||||
(listenerCfg.TLS != nil && listenerCfg.TLS.Enabled)
|
||||
|
||||
sdsCfg, err := resolveListenerSDSConfig(cfgSnap, listenerKey)
|
||||
sdsCfg, err := resolveListenerSDSConfig(cfgSnap, listenerCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func (s *ResourceGenerator) makeIngressGatewayListeners(address string, cfgSnap
|
|||
return resources, nil
|
||||
}
|
||||
|
||||
func resolveListenerSDSConfig(cfgSnap *proxycfg.ConfigSnapshot, listenerKey proxycfg.IngressListenerKey) (*structs.GatewayTLSSDSConfig, error) {
|
||||
func resolveListenerSDSConfig(cfgSnap *proxycfg.ConfigSnapshot, listenerCfg structs.IngressListener) (*structs.GatewayTLSSDSConfig, error) {
|
||||
var mergedCfg structs.GatewayTLSSDSConfig
|
||||
|
||||
gwSDS := cfgSnap.IngressGateway.TLSConfig.SDS
|
||||
|
@ -136,11 +136,6 @@ func resolveListenerSDSConfig(cfgSnap *proxycfg.ConfigSnapshot, listenerKey prox
|
|||
mergedCfg.CertResource = gwSDS.CertResource
|
||||
}
|
||||
|
||||
listenerCfg, ok := cfgSnap.IngressGateway.Listeners[listenerKey]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no listener config found for listener on port %d", listenerKey.Port)
|
||||
}
|
||||
|
||||
if listenerCfg.TLS != nil && listenerCfg.TLS.SDS != nil {
|
||||
if listenerCfg.TLS.SDS.ClusterName != "" {
|
||||
mergedCfg.ClusterName = listenerCfg.TLS.SDS.ClusterName
|
||||
|
@ -161,10 +156,10 @@ func resolveListenerSDSConfig(cfgSnap *proxycfg.ConfigSnapshot, listenerKey prox
|
|||
return &mergedCfg, nil
|
||||
|
||||
case mergedCfg.ClusterName == "" && mergedCfg.CertResource != "":
|
||||
return nil, fmt.Errorf("missing SDS cluster name for listener on port %d", listenerKey.Port)
|
||||
return nil, fmt.Errorf("missing SDS cluster name for listener on port %d", listenerCfg.Port)
|
||||
|
||||
case mergedCfg.ClusterName != "" && mergedCfg.CertResource == "":
|
||||
return nil, fmt.Errorf("missing SDS cert resource for listener on port %d", listenerKey.Port)
|
||||
return nil, fmt.Errorf("missing SDS cert resource for listener on port %d", listenerCfg.Port)
|
||||
}
|
||||
|
||||
return &mergedCfg, nil
|
||||
|
|
|
@ -1172,7 +1172,7 @@ func TestResolveListenerSDSConfig(t *testing.T) {
|
|||
snap := proxycfg.TestConfigSnapshotIngressWithGatewaySDS(t)
|
||||
// Override TLS configs
|
||||
snap.IngressGateway.TLSConfig.SDS = tc.gwSDS
|
||||
var key proxycfg.IngressListenerKey
|
||||
var listenerCfg structs.IngressListener
|
||||
for k, lisCfg := range snap.IngressGateway.Listeners {
|
||||
if tc.lisSDS == nil {
|
||||
lisCfg.TLS = nil
|
||||
|
@ -1183,12 +1183,11 @@ func TestResolveListenerSDSConfig(t *testing.T) {
|
|||
}
|
||||
// Override listener cfg in map
|
||||
snap.IngressGateway.Listeners[k] = lisCfg
|
||||
// Save the last key doesn't matter which as we set same listener config
|
||||
// for all.
|
||||
key = k
|
||||
// Save the last cfg doesn't matter which as we set same for all.
|
||||
listenerCfg = lisCfg
|
||||
}
|
||||
|
||||
got, err := resolveListenerSDSConfig(snap, key)
|
||||
got, err := resolveListenerSDSConfig(snap, listenerCfg)
|
||||
if tc.wantErr != "" {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), tc.wantErr)
|
||||
|
|
Loading…
Reference in New Issue