api: support GetMeta() and GetNamespace() on all config entry kinds (#8764)
Fixes #8755 Since I was updating the interface, i also added the missing `GetNamespace()`. Depending upon how you look at it, this is a breaking change since it adds methods to the exported interface `api.ConfigEntry`. Given that you cannot define your own config entry kinds, and all of the machinery of the `api.Client` acts like a factory to construct the canned ones from the rest of the module, this feels like it's not a problematic change as it would only break someone who had reimplemented the `ConfigEntry` interface themselves for no apparent utility?
This commit is contained in:
parent
450540af33
commit
e84c032ea7
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
api: support GetMeta() and GetNamespace() on all config entry kinds
|
||||||
|
```
|
|
@ -26,6 +26,8 @@ const (
|
||||||
type ConfigEntry interface {
|
type ConfigEntry interface {
|
||||||
GetKind() string
|
GetKind() string
|
||||||
GetName() string
|
GetName() string
|
||||||
|
GetNamespace() string
|
||||||
|
GetMeta() map[string]string
|
||||||
GetCreateIndex() uint64
|
GetCreateIndex() uint64
|
||||||
GetModifyIndex() uint64
|
GetModifyIndex() uint64
|
||||||
}
|
}
|
||||||
|
@ -108,6 +110,14 @@ func (s *ServiceConfigEntry) GetName() string {
|
||||||
return s.Name
|
return s.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServiceConfigEntry) GetNamespace() string {
|
||||||
|
return s.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceConfigEntry) GetMeta() map[string]string {
|
||||||
|
return s.Meta
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ServiceConfigEntry) GetCreateIndex() uint64 {
|
func (s *ServiceConfigEntry) GetCreateIndex() uint64 {
|
||||||
return s.CreateIndex
|
return s.CreateIndex
|
||||||
}
|
}
|
||||||
|
@ -136,6 +146,14 @@ func (p *ProxyConfigEntry) GetName() string {
|
||||||
return p.Name
|
return p.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ProxyConfigEntry) GetNamespace() string {
|
||||||
|
return p.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProxyConfigEntry) GetMeta() map[string]string {
|
||||||
|
return p.Meta
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ProxyConfigEntry) GetCreateIndex() uint64 {
|
func (p *ProxyConfigEntry) GetCreateIndex() uint64 {
|
||||||
return p.CreateIndex
|
return p.CreateIndex
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,12 @@ type ServiceRouterConfigEntry struct {
|
||||||
ModifyIndex uint64
|
ModifyIndex uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ServiceRouterConfigEntry) GetKind() string { return e.Kind }
|
func (e *ServiceRouterConfigEntry) GetKind() string { return e.Kind }
|
||||||
func (e *ServiceRouterConfigEntry) GetName() string { return e.Name }
|
func (e *ServiceRouterConfigEntry) GetName() string { return e.Name }
|
||||||
func (e *ServiceRouterConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
func (e *ServiceRouterConfigEntry) GetNamespace() string { return e.Namespace }
|
||||||
func (e *ServiceRouterConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
func (e *ServiceRouterConfigEntry) GetMeta() map[string]string { return e.Meta }
|
||||||
|
func (e *ServiceRouterConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
||||||
|
func (e *ServiceRouterConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
||||||
|
|
||||||
type ServiceRoute struct {
|
type ServiceRoute struct {
|
||||||
Match *ServiceRouteMatch `json:",omitempty"`
|
Match *ServiceRouteMatch `json:",omitempty"`
|
||||||
|
@ -117,10 +119,12 @@ type ServiceSplitterConfigEntry struct {
|
||||||
ModifyIndex uint64
|
ModifyIndex uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ServiceSplitterConfigEntry) GetKind() string { return e.Kind }
|
func (e *ServiceSplitterConfigEntry) GetKind() string { return e.Kind }
|
||||||
func (e *ServiceSplitterConfigEntry) GetName() string { return e.Name }
|
func (e *ServiceSplitterConfigEntry) GetName() string { return e.Name }
|
||||||
func (e *ServiceSplitterConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
func (e *ServiceSplitterConfigEntry) GetNamespace() string { return e.Namespace }
|
||||||
func (e *ServiceSplitterConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
func (e *ServiceSplitterConfigEntry) GetMeta() map[string]string { return e.Meta }
|
||||||
|
func (e *ServiceSplitterConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
||||||
|
func (e *ServiceSplitterConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
||||||
|
|
||||||
type ServiceSplit struct {
|
type ServiceSplit struct {
|
||||||
Weight float32
|
Weight float32
|
||||||
|
@ -185,10 +189,12 @@ func (e *ServiceResolverConfigEntry) UnmarshalJSON(data []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ServiceResolverConfigEntry) GetKind() string { return e.Kind }
|
func (e *ServiceResolverConfigEntry) GetKind() string { return e.Kind }
|
||||||
func (e *ServiceResolverConfigEntry) GetName() string { return e.Name }
|
func (e *ServiceResolverConfigEntry) GetName() string { return e.Name }
|
||||||
func (e *ServiceResolverConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
func (e *ServiceResolverConfigEntry) GetNamespace() string { return e.Namespace }
|
||||||
func (e *ServiceResolverConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
func (e *ServiceResolverConfigEntry) GetMeta() map[string]string { return e.Meta }
|
||||||
|
func (e *ServiceResolverConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
||||||
|
func (e *ServiceResolverConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
||||||
|
|
||||||
type ServiceResolverSubset struct {
|
type ServiceResolverSubset struct {
|
||||||
Filter string `json:",omitempty"`
|
Filter string `json:",omitempty"`
|
||||||
|
|
|
@ -32,6 +32,9 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
||||||
require.NotNil(t, qm)
|
require.NotNil(t, qm)
|
||||||
require.NotEqual(t, 0, qm.RequestTime)
|
require.NotEqual(t, 0, qm.RequestTime)
|
||||||
|
|
||||||
|
// generic verification
|
||||||
|
require.Equal(t, testEntry.Meta, entry.GetMeta())
|
||||||
|
|
||||||
// verify it
|
// verify it
|
||||||
readResolver, ok := entry.(*ServiceResolverConfigEntry)
|
readResolver, ok := entry.(*ServiceResolverConfigEntry)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -61,6 +64,9 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
||||||
require.NotNil(t, qm)
|
require.NotNil(t, qm)
|
||||||
require.NotEqual(t, 0, qm.RequestTime)
|
require.NotEqual(t, 0, qm.RequestTime)
|
||||||
|
|
||||||
|
// generic verification
|
||||||
|
require.Equal(t, testEntry.Meta, entry.GetMeta())
|
||||||
|
|
||||||
// verify it
|
// verify it
|
||||||
readSplitter, ok := entry.(*ServiceSplitterConfigEntry)
|
readSplitter, ok := entry.(*ServiceSplitterConfigEntry)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -90,6 +96,9 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
||||||
require.NotNil(t, qm)
|
require.NotNil(t, qm)
|
||||||
require.NotEqual(t, 0, qm.RequestTime)
|
require.NotEqual(t, 0, qm.RequestTime)
|
||||||
|
|
||||||
|
// generic verification
|
||||||
|
require.Equal(t, testEntry.Meta, entry.GetMeta())
|
||||||
|
|
||||||
// verify it
|
// verify it
|
||||||
readRouter, ok := entry.(*ServiceRouterConfigEntry)
|
readRouter, ok := entry.(*ServiceRouterConfigEntry)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -150,6 +159,10 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ConnectTimeout: 5 * time.Second,
|
ConnectTimeout: 5 * time.Second,
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"gir": "zim",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
verify: verifyResolver,
|
verify: verifyResolver,
|
||||||
},
|
},
|
||||||
|
@ -187,6 +200,10 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
||||||
Namespace: defaultNamespace,
|
Namespace: defaultNamespace,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"gir": "zim",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
verify: verifySplitter,
|
verify: verifySplitter,
|
||||||
},
|
},
|
||||||
|
@ -221,6 +238,10 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"gir": "zim",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
verify: verifyRouter,
|
verify: verifyRouter,
|
||||||
},
|
},
|
||||||
|
|
|
@ -96,6 +96,14 @@ func (i *IngressGatewayConfigEntry) GetName() string {
|
||||||
return i.Name
|
return i.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *IngressGatewayConfigEntry) GetNamespace() string {
|
||||||
|
return i.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IngressGatewayConfigEntry) GetMeta() map[string]string {
|
||||||
|
return i.Meta
|
||||||
|
}
|
||||||
|
|
||||||
func (i *IngressGatewayConfigEntry) GetCreateIndex() uint64 {
|
func (i *IngressGatewayConfigEntry) GetCreateIndex() uint64 {
|
||||||
return i.CreateIndex
|
return i.CreateIndex
|
||||||
}
|
}
|
||||||
|
@ -165,6 +173,14 @@ func (g *TerminatingGatewayConfigEntry) GetName() string {
|
||||||
return g.Name
|
return g.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *TerminatingGatewayConfigEntry) GetNamespace() string {
|
||||||
|
return g.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *TerminatingGatewayConfigEntry) GetMeta() map[string]string {
|
||||||
|
return g.Meta
|
||||||
|
}
|
||||||
|
|
||||||
func (g *TerminatingGatewayConfigEntry) GetCreateIndex() uint64 {
|
func (g *TerminatingGatewayConfigEntry) GetCreateIndex() uint64 {
|
||||||
return g.CreateIndex
|
return g.CreateIndex
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,10 @@ func TestAPI_ConfigEntries_IngressGateway(t *testing.T) {
|
||||||
ingress1 := &IngressGatewayConfigEntry{
|
ingress1 := &IngressGatewayConfigEntry{
|
||||||
Kind: IngressGateway,
|
Kind: IngressGateway,
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"gir": "zim",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ingress2 := &IngressGatewayConfigEntry{
|
ingress2 := &IngressGatewayConfigEntry{
|
||||||
|
@ -62,6 +66,8 @@ func TestAPI_ConfigEntries_IngressGateway(t *testing.T) {
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, ingress1.Kind, readIngress.Kind)
|
require.Equal(t, ingress1.Kind, readIngress.Kind)
|
||||||
require.Equal(t, ingress1.Name, readIngress.Name)
|
require.Equal(t, ingress1.Name, readIngress.Name)
|
||||||
|
require.Equal(t, ingress1.Meta, readIngress.Meta)
|
||||||
|
require.Equal(t, ingress1.Meta, readIngress.GetMeta())
|
||||||
|
|
||||||
// update it
|
// update it
|
||||||
ingress1.Listeners = []IngressListener{
|
ingress1.Listeners = []IngressListener{
|
||||||
|
@ -164,6 +170,10 @@ func TestAPI_ConfigEntries_TerminatingGateway(t *testing.T) {
|
||||||
terminating1 := &TerminatingGatewayConfigEntry{
|
terminating1 := &TerminatingGatewayConfigEntry{
|
||||||
Kind: TerminatingGateway,
|
Kind: TerminatingGateway,
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"gir": "zim",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
terminating2 := &TerminatingGatewayConfigEntry{
|
terminating2 := &TerminatingGatewayConfigEntry{
|
||||||
|
@ -194,6 +204,8 @@ func TestAPI_ConfigEntries_TerminatingGateway(t *testing.T) {
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, terminating1.Kind, readTerminating.Kind)
|
require.Equal(t, terminating1.Kind, readTerminating.Kind)
|
||||||
require.Equal(t, terminating1.Name, readTerminating.Name)
|
require.Equal(t, terminating1.Name, readTerminating.Name)
|
||||||
|
require.Equal(t, terminating1.Meta, readTerminating.Meta)
|
||||||
|
require.Equal(t, terminating1.Meta, readTerminating.GetMeta())
|
||||||
|
|
||||||
// update it
|
// update it
|
||||||
terminating1.Services = []LinkedService{
|
terminating1.Services = []LinkedService{
|
||||||
|
|
|
@ -23,6 +23,10 @@ func TestAPI_ConfigEntries(t *testing.T) {
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"bar": 1.0,
|
"bar": 1.0,
|
||||||
},
|
},
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"gir": "zim",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// set it
|
// set it
|
||||||
|
@ -43,6 +47,8 @@ func TestAPI_ConfigEntries(t *testing.T) {
|
||||||
require.Equal(t, global_proxy.Kind, readProxy.Kind)
|
require.Equal(t, global_proxy.Kind, readProxy.Kind)
|
||||||
require.Equal(t, global_proxy.Name, readProxy.Name)
|
require.Equal(t, global_proxy.Name, readProxy.Name)
|
||||||
require.Equal(t, global_proxy.Config, readProxy.Config)
|
require.Equal(t, global_proxy.Config, readProxy.Config)
|
||||||
|
require.Equal(t, global_proxy.Meta, readProxy.Meta)
|
||||||
|
require.Equal(t, global_proxy.Meta, readProxy.GetMeta())
|
||||||
|
|
||||||
global_proxy.Config["baz"] = true
|
global_proxy.Config["baz"] = true
|
||||||
// CAS update fail
|
// CAS update fail
|
||||||
|
@ -92,6 +98,10 @@ func TestAPI_ConfigEntries(t *testing.T) {
|
||||||
Kind: ServiceDefaults,
|
Kind: ServiceDefaults,
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Protocol: "udp",
|
Protocol: "udp",
|
||||||
|
Meta: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
"gir": "zim",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
service2 := &ServiceConfigEntry{
|
service2 := &ServiceConfigEntry{
|
||||||
|
@ -124,6 +134,8 @@ func TestAPI_ConfigEntries(t *testing.T) {
|
||||||
require.Equal(t, service.Kind, readService.Kind)
|
require.Equal(t, service.Kind, readService.Kind)
|
||||||
require.Equal(t, service.Name, readService.Name)
|
require.Equal(t, service.Name, readService.Name)
|
||||||
require.Equal(t, service.Protocol, readService.Protocol)
|
require.Equal(t, service.Protocol, readService.Protocol)
|
||||||
|
require.Equal(t, service.Meta, readService.Meta)
|
||||||
|
require.Equal(t, service.Meta, readService.GetMeta())
|
||||||
|
|
||||||
// update it
|
// update it
|
||||||
service.Protocol = "tcp"
|
service.Protocol = "tcp"
|
||||||
|
|
Loading…
Reference in New Issue