mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 09:55:44 +03:00
Merge pull request #8461 from hashicorp/backport-ent-changes-20200720
Back-port Some Enterprise changes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// +build pro ent
|
||||
// +build ent
|
||||
|
||||
package api
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build pro ent
|
||||
// +build ent
|
||||
|
||||
package api
|
||||
|
||||
|
||||
@@ -430,6 +430,7 @@ func (a *Agent) finalizeServerConfig(c *nomad.Config) {
|
||||
// Setup the plugin loaders
|
||||
c.PluginLoader = a.pluginLoader
|
||||
c.PluginSingletonLoader = a.pluginSingletonLoader
|
||||
c.AgentShutdown = func() error { return a.Shutdown() }
|
||||
}
|
||||
|
||||
// clientConfig is used to generate a new client configuration struct for
|
||||
|
||||
@@ -385,35 +385,35 @@ func (c *Command) isValidConfig(config, cmdConfig *Config) bool {
|
||||
}
|
||||
|
||||
// setupLoggers is used to setup the logGate, and our logOutput
|
||||
func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer) {
|
||||
func SetupLoggers(ui cli.Ui, config *Config) (*logutils.LevelFilter, *gatedwriter.Writer, io.Writer) {
|
||||
// Setup logging. First create the gated log writer, which will
|
||||
// store logs until we're ready to show them. Then create the level
|
||||
// filter, filtering logs of the specified level.
|
||||
logGate := &gatedwriter.Writer{
|
||||
Writer: &cli.UiWriter{Ui: c.Ui},
|
||||
Writer: &cli.UiWriter{Ui: ui},
|
||||
}
|
||||
|
||||
c.logFilter = LevelFilter()
|
||||
c.logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.LogLevel))
|
||||
c.logFilter.Writer = logGate
|
||||
if !ValidateLevelFilter(c.logFilter.MinLevel, c.logFilter) {
|
||||
c.Ui.Error(fmt.Sprintf(
|
||||
logFilter := LevelFilter()
|
||||
logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.LogLevel))
|
||||
logFilter.Writer = logGate
|
||||
if !ValidateLevelFilter(logFilter.MinLevel, logFilter) {
|
||||
ui.Error(fmt.Sprintf(
|
||||
"Invalid log level: %s. Valid log levels are: %v",
|
||||
c.logFilter.MinLevel, c.logFilter.Levels))
|
||||
return nil, nil
|
||||
logFilter.MinLevel, logFilter.Levels))
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
// Create a log writer, and wrap a logOutput around it
|
||||
writers := []io.Writer{c.logFilter}
|
||||
writers := []io.Writer{logFilter}
|
||||
|
||||
// Check if syslog is enabled
|
||||
if config.EnableSyslog {
|
||||
l, err := gsyslog.NewLogger(gsyslog.LOG_NOTICE, config.SyslogFacility, "nomad")
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Syslog setup failed: %v", err))
|
||||
return nil, nil
|
||||
ui.Error(fmt.Sprintf("Syslog setup failed: %v", err))
|
||||
return nil, nil, nil
|
||||
}
|
||||
writers = append(writers, &SyslogWrapper{l, c.logFilter})
|
||||
writers = append(writers, &SyslogWrapper{l, logFilter})
|
||||
}
|
||||
|
||||
// Check if file logging is enabled
|
||||
@@ -430,8 +430,8 @@ func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer)
|
||||
if config.LogRotateDuration != "" {
|
||||
duration, err := time.ParseDuration(config.LogRotateDuration)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Failed to parse log rotation duration: %v", err))
|
||||
return nil, nil
|
||||
ui.Error(fmt.Sprintf("Failed to parse log rotation duration: %v", err))
|
||||
return nil, nil, nil
|
||||
}
|
||||
logRotateDuration = duration
|
||||
} else {
|
||||
@@ -440,7 +440,7 @@ func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer)
|
||||
}
|
||||
|
||||
logFile := &logFile{
|
||||
logFilter: c.logFilter,
|
||||
logFilter: logFilter,
|
||||
fileName: fileName,
|
||||
logPath: dir,
|
||||
duration: logRotateDuration,
|
||||
@@ -451,9 +451,9 @@ func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer)
|
||||
writers = append(writers, logFile)
|
||||
}
|
||||
|
||||
c.logOutput = io.MultiWriter(writers...)
|
||||
log.SetOutput(c.logOutput)
|
||||
return logGate, c.logOutput
|
||||
logOutput := io.MultiWriter(writers...)
|
||||
log.SetOutput(logOutput)
|
||||
return logFilter, logGate, logOutput
|
||||
}
|
||||
|
||||
// setupAgent is used to start the agent and various interfaces
|
||||
@@ -607,7 +607,9 @@ func (c *Command) Run(args []string) int {
|
||||
}
|
||||
|
||||
// Setup the log outputs
|
||||
logGate, logOutput := c.setupLoggers(config)
|
||||
logFilter, logGate, logOutput := SetupLoggers(c.Ui, config)
|
||||
c.logFilter = logFilter
|
||||
c.logOutput = logOutput
|
||||
if logGate == nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ func TestCommand_LicenseGet_OSSErr(t *testing.T) {
|
||||
code := cmd.Run([]string{"-address=" + url})
|
||||
if srv.Enterprise {
|
||||
require.Equal(t, 0, code)
|
||||
require.Contains(t, ui.OutputWriter.String(), "License Status = valid")
|
||||
} else {
|
||||
require.Equal(t, 1, code)
|
||||
require.Contains(t, ui.ErrorWriter.String(), "Nomad Enterprise only endpoint")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build pro ent
|
||||
// +build ent
|
||||
|
||||
package command
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build pro ent
|
||||
// +build ent
|
||||
|
||||
package command
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build pro ent
|
||||
// +build ent
|
||||
|
||||
package command
|
||||
|
||||
|
||||
@@ -573,7 +573,6 @@ func TestAgentProfile_RemoteClient(t *testing.T) {
|
||||
// Test that we prevent a forwarding loop if the requested
|
||||
// serverID does not exist in the requested region
|
||||
func TestAgentProfile_RemoteRegionMisMatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
|
||||
// start server and client
|
||||
@@ -611,7 +610,6 @@ func TestAgentProfile_RemoteRegionMisMatch(t *testing.T) {
|
||||
|
||||
// Test that Agent.Profile can forward to a different region
|
||||
func TestAgentProfile_RemoteRegion(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
|
||||
// start server and client
|
||||
@@ -649,7 +647,6 @@ func TestAgentProfile_RemoteRegion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAgentProfile_Server(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// start servers
|
||||
s1, cleanup := TestServer(t, func(c *Config) {
|
||||
|
||||
@@ -351,6 +351,10 @@ type Config struct {
|
||||
|
||||
// LicenseConfig is a tunable knob for enterprise license testing.
|
||||
LicenseConfig *LicenseConfig
|
||||
|
||||
// AgentShutdown is used to call agent.Shutdown from the context of a Server
|
||||
// It is used primarily for licensing
|
||||
AgentShutdown func() error
|
||||
}
|
||||
|
||||
// CheckVersion is used to check if the ProtocolVersion is valid
|
||||
|
||||
@@ -63,7 +63,6 @@ func testFSM(t *testing.T) *nomadFSM {
|
||||
if fsm == nil {
|
||||
t.Fatalf("missing fsm")
|
||||
}
|
||||
state.TestInitState(t, fsm.state)
|
||||
return fsm
|
||||
}
|
||||
|
||||
|
||||
@@ -319,6 +319,7 @@ func (op *Operator) SchedulerSetConfiguration(args *structs.SchedulerSetConfigRe
|
||||
if !ServersMeetMinimumVersion(op.srv.Members(), minSchedulerConfigVersion, false) {
|
||||
return fmt.Errorf("All servers should be running version %v to update scheduler config", minSchedulerConfigVersion)
|
||||
}
|
||||
|
||||
// Apply the update
|
||||
resp, index, err := op.srv.raftApply(structs.SchedulerConfigRequestType, args)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,5 +23,4 @@ func (s *Server) setupEnterprise(config *Config) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) startEnterpriseBackground() {}
|
||||
|
||||
@@ -80,6 +80,12 @@ func NewStateStore(config *StateStoreConfig) (*StateStore, error) {
|
||||
config: config,
|
||||
abandonCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
// Initialize the state store with required enterprise objects
|
||||
if err := s.enterpriseInit(); err != nil {
|
||||
return nil, fmt.Errorf("enterprise state store initialization failed: %v", err)
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@ import (
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
// enterpriseInit is used to initialize the state store with enterprise
|
||||
// objects.
|
||||
func (s *StateStore) enterpriseInit() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// namespaceExists returns whether a namespace exists
|
||||
func (s *StateStore) namespaceExists(txn *memdb.Txn, namespace string) (bool, error) {
|
||||
return namespace == structs.DefaultNamespace, nil
|
||||
|
||||
@@ -21,7 +21,6 @@ func TestStateStore(t testing.T) *StateStore {
|
||||
if state == nil {
|
||||
t.Fatalf("missing state")
|
||||
}
|
||||
TestInitState(t, state)
|
||||
return state
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
// +build !ent
|
||||
|
||||
package state
|
||||
|
||||
import (
|
||||
testing "github.com/mitchellh/go-testing-interface"
|
||||
)
|
||||
|
||||
func TestInitState(t testing.T, state *StateStore) {}
|
||||
Reference in New Issue
Block a user