mirror of https://github.com/status-im/consul.git
Preparation for changing where license management is done.
This commit is contained in:
parent
57e6c8a9e5
commit
234d0a3c2a
|
@ -457,6 +457,12 @@ func (a *Agent) Start(ctx context.Context) error {
|
|||
return fmt.Errorf("Failed to load TLS configurations after applying auto-config settings: %w", err)
|
||||
}
|
||||
|
||||
// we cannot use the context passed into this method as that context will be cancelled after the
|
||||
// agent finishes starting up which would cause the license manager to stop
|
||||
if err := a.startLicenseManager(&lib.StopChannelContext{StopCh: a.shutdownCh}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create the local state
|
||||
a.State = local.NewState(LocalConfig(c), a.logger, a.tokens)
|
||||
|
||||
|
@ -1339,6 +1345,8 @@ func (a *Agent) ShutdownAgent() error {
|
|||
// Stop the watches to avoid any notification/state change during shutdown
|
||||
a.stopAllWatches()
|
||||
|
||||
a.stopLicenseManager()
|
||||
|
||||
// this would be cancelled anyways (by the closing of the shutdown ch) but
|
||||
// this should help them to be stopped more quickly
|
||||
a.baseDeps.AutoConfig.Stop()
|
||||
|
@ -3071,6 +3079,17 @@ func (a *Agent) Stats() map[string]map[string]string {
|
|||
"version": a.config.Version,
|
||||
"prerelease": a.config.VersionPrerelease,
|
||||
}
|
||||
|
||||
for outerKey, outerValue := range a.enterpriseStats() {
|
||||
if _, ok := stats[outerKey]; ok {
|
||||
for innerKey, innerValue := range outerValue {
|
||||
stats[outerKey][innerKey] = innerValue
|
||||
}
|
||||
} else {
|
||||
stats[outerKey] = outerValue
|
||||
}
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/consul/agent/config"
|
||||
"github.com/hashicorp/consul/agent/consul"
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
|
@ -35,3 +37,16 @@ func enterpriseConsulConfig(_ *consul.Config, _ *config.RuntimeConfig) {
|
|||
// WriteEvent is a noop stub for the func defined agent_ent.go
|
||||
func (a *Agent) WriteEvent(eventType string, payload interface{}) {
|
||||
}
|
||||
|
||||
// startLicenseManager is used to start the license management process
|
||||
func (a *Agent) startLicenseManager(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// stopLicenseManager is used to stop the license management go routines
|
||||
func (a *Agent) stopLicenseManager() {}
|
||||
|
||||
// enterpriseStats outputs all the Agent stats specific to Consul Enterprise
|
||||
func (a *Agent) enterpriseStats() map[string]map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -318,9 +318,14 @@ func TestAgent_HTTPMaxHeaderBytes(t *testing.T) {
|
|||
},
|
||||
Cache: cache.New(cache.Options{}),
|
||||
}
|
||||
bd, err = initEnterpriseBaseDeps(bd, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
a, err := New(bd)
|
||||
require.NoError(t, err)
|
||||
|
||||
a.startLicenseManager(testutil.TestContext(t))
|
||||
|
||||
srvs, err := a.listenHTTP()
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -5182,9 +5187,15 @@ func TestAgent_ListenHTTP_MultipleAddresses(t *testing.T) {
|
|||
},
|
||||
Cache: cache.New(cache.Options{}),
|
||||
}
|
||||
|
||||
bd, err = initEnterpriseBaseDeps(bd, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
agent, err := New(bd)
|
||||
require.NoError(t, err)
|
||||
|
||||
agent.startLicenseManager(testutil.TestContext(t))
|
||||
|
||||
srvs, err := agent.listenHTTP()
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
|
|
|
@ -10,10 +10,6 @@ import (
|
|||
|
||||
"github.com/armon/go-metrics"
|
||||
"github.com/armon/go-metrics/prometheus"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/serf/serf"
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/hashicorp/consul/agent/pool"
|
||||
"github.com/hashicorp/consul/agent/router"
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
|
@ -21,6 +17,9 @@ import (
|
|||
"github.com/hashicorp/consul/logging"
|
||||
"github.com/hashicorp/consul/tlsutil"
|
||||
"github.com/hashicorp/consul/types"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/serf/serf"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
var ClientCounters = []prometheus.CounterDefinition{
|
||||
|
@ -116,7 +115,7 @@ func NewClient(config *Config, deps Deps) (*Client, error) {
|
|||
|
||||
c.rpcLimiter.Store(rate.NewLimiter(config.RPCRateLimit, config.RPCMaxBurst))
|
||||
|
||||
if err := c.initEnterprise(); err != nil {
|
||||
if err := c.initEnterprise(deps); err != nil {
|
||||
c.Shutdown()
|
||||
return nil, err
|
||||
}
|
||||
|
@ -381,16 +380,6 @@ func (c *Client) Stats() map[string]map[string]string {
|
|||
stats["consul"]["acl"] = "disabled"
|
||||
}
|
||||
|
||||
for outerKey, outerValue := range c.enterpriseStats() {
|
||||
if _, ok := stats[outerKey]; ok {
|
||||
for innerKey, innerValue := range outerValue {
|
||||
stats[outerKey][innerKey] = innerValue
|
||||
}
|
||||
} else {
|
||||
stats[outerKey] = outerValue
|
||||
}
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
|
|
|
@ -515,6 +515,7 @@ func newDefaultDeps(t *testing.T, c *Config) Deps {
|
|||
Tokens: new(token.Store),
|
||||
Router: r,
|
||||
ConnPool: connPool,
|
||||
EnterpriseDeps: newDefaultDepsEnterprise(t, logger, c),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
type EnterpriseClient struct{}
|
||||
|
||||
func (c *Client) initEnterprise() error {
|
||||
func (c *Client) initEnterprise(_ Deps) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,10 @@ func (c *Client) handleEnterpriseUserEvents(event serf.UserEvent) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (_ *Client) addEnterpriseSerfTags(_ map[string]string) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (c *Client) enterpriseStats() map[string]map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ var (
|
|||
|
||||
type EnterpriseServer struct{}
|
||||
|
||||
func (s *Server) initEnterprise() error {
|
||||
func (s *Server) initEnterprise(_ Deps) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,6 @@ func (s *Server) handleEnterpriseLeave() {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *Server) enterpriseStats() map[string]map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) establishEnterpriseLeadership() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// +build !consulent
|
||||
|
||||
package consul
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
func newDefaultDepsEnterprise(t *testing.T, _ hclog.Logger, _ *Config) EnterpriseDeps {
|
||||
t.Helper()
|
||||
return EnterpriseDeps{}
|
||||
}
|
|
@ -17,6 +17,7 @@ type Deps struct {
|
|||
Router *router.Router
|
||||
ConnPool *pool.ConnPool
|
||||
GRPCConnPool GRPCClientConner
|
||||
EnterpriseDeps
|
||||
}
|
||||
|
||||
type GRPCClientConner interface {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// +build !consulent
|
||||
|
||||
package consul
|
||||
|
||||
type EnterpriseDeps struct{}
|
|
@ -391,7 +391,7 @@ func NewServer(config *Config, flat Deps) (*Server, error) {
|
|||
}
|
||||
|
||||
// Initialize enterprise specific server functionality
|
||||
if err := s.initEnterprise(); err != nil {
|
||||
if err := s.initEnterprise(flat); err != nil {
|
||||
s.Shutdown()
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1353,16 +1353,6 @@ func (s *Server) Stats() map[string]map[string]string {
|
|||
stats["serf_wan"] = s.serfWAN.Stats()
|
||||
}
|
||||
|
||||
for outerKey, outerValue := range s.enterpriseStats() {
|
||||
if _, ok := stats[outerKey]; ok {
|
||||
for innerKey, innerValue := range outerValue {
|
||||
stats[outerKey][innerKey] = innerValue
|
||||
}
|
||||
} else {
|
||||
stats[outerKey] = outerValue
|
||||
}
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ func setupPrimaryServer(t *testing.T) *agent.TestAgent {
|
|||
return a
|
||||
}
|
||||
|
||||
func TestTestAgentLeaks_Server(t *testing.T) {
|
||||
func TestAgentLeaks_Server(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("too slow for testing.Short")
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer) (BaseDeps, error)
|
|||
return d, err
|
||||
}
|
||||
|
||||
return d, nil
|
||||
return initEnterpriseBaseDeps(d, cfg)
|
||||
}
|
||||
|
||||
// grpcLogInitOnce because the test suite will call NewBaseDeps in many tests and
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// +build !consulent
|
||||
|
||||
package agent
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/consul/agent/config"
|
||||
)
|
||||
|
||||
// initEnterpriseBaseDeps is responsible for initializing the enterprise dependencies that
|
||||
// will be utilized throughout the whole Consul Agent.
|
||||
func initEnterpriseBaseDeps(d BaseDeps, _ *config.RuntimeConfig) (BaseDeps, error) {
|
||||
return d, nil
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestContext(t *testing.T) context.Context {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
t.Cleanup(cancel)
|
||||
return ctx
|
||||
}
|
Loading…
Reference in New Issue