mirror of https://github.com/status-im/consul.git
GH-20889 - put conditionals are hcp initialization for consul server (#20926)
* put conditionals are hcp initialization for consul server * put more things behind configuration flags * add changelog * TestServer_hcpManager * fix TestAgent_scadaProvider
This commit is contained in:
parent
2a2e773908
commit
39112c7a98
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
error running consul server in 1.18.0: failed to configure SCADA provider user's home directory path: $HOME is not defined
|
||||
```
|
|
@ -1320,7 +1320,7 @@ func (a *Agent) listenHTTP() ([]apiServer, error) {
|
|||
}
|
||||
|
||||
httpAddrs := a.config.HTTPAddrs
|
||||
if a.scadaProvider != nil {
|
||||
if a.config.IsCloudEnabled() && a.scadaProvider != nil {
|
||||
httpAddrs = append(httpAddrs, scada.CAPCoreAPI)
|
||||
}
|
||||
|
||||
|
|
|
@ -6341,6 +6341,7 @@ func TestAgent_scadaProvider(t *testing.T) {
|
|||
pvd.EXPECT().Listen(scada.CAPCoreAPI.Capability()).Return(l, nil).Once()
|
||||
pvd.EXPECT().Stop().Return(nil).Once()
|
||||
a := TestAgent{
|
||||
HCL: `cloud = { resource_id = "test-resource-id" client_id = "test-client-id" client_secret = "test-client-secret" }`,
|
||||
OverrideDeps: func(deps *BaseDeps) {
|
||||
deps.HCP.Provider = pvd
|
||||
},
|
||||
|
|
|
@ -1114,8 +1114,8 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
|
|||
LocalProxyConfigResyncInterval: 30 * time.Second,
|
||||
}
|
||||
|
||||
// host metrics are enabled by default to support HashiCorp Cloud Platform integration
|
||||
rt.Telemetry.EnableHostMetrics = boolValWithDefault(c.Telemetry.EnableHostMetrics, true)
|
||||
// host metrics are enabled if consul is configured with HashiCorp Cloud Platform integration
|
||||
rt.Telemetry.EnableHostMetrics = boolValWithDefault(c.Telemetry.EnableHostMetrics, rt.IsCloudEnabled())
|
||||
|
||||
rt.TLS, err = b.buildTLSConfig(rt, c.TLS)
|
||||
if err != nil {
|
||||
|
|
|
@ -595,6 +595,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
|
|||
StorageBackend: s.raftStorageBackend,
|
||||
})
|
||||
|
||||
if s.config.Cloud.IsConfigured() {
|
||||
s.hcpManager = hcp.NewManager(hcp.ManagerConfig{
|
||||
CloudConfig: flat.HCP.Config,
|
||||
StatusFn: s.hcpServerStatus(flat),
|
||||
|
@ -621,6 +622,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
|
|||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
var recorder *middleware.RequestRecorder
|
||||
if flat.NewRequestRecorderFunc != nil {
|
||||
|
@ -890,6 +892,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
|
|||
// to enable RPC forwarding.
|
||||
s.grpcLeaderForwarder = flat.LeaderForwarder
|
||||
|
||||
if s.config.Cloud.IsConfigured() {
|
||||
// Start watching HCP Link resource. This needs to be created after
|
||||
// the GRPC services are set up in order for the resource service client to
|
||||
// function. This uses the insecure grpc channel so that it doesn't need to
|
||||
|
@ -906,6 +909,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
|
|||
flat.HCP.DataDir,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
s.controllerManager = controller.NewManager(
|
||||
// Usage of the insecure + unsafe grpc chan is required for the controller
|
||||
|
@ -1008,6 +1012,7 @@ func isV1CatalogRequest(rpcName string) bool {
|
|||
}
|
||||
|
||||
func (s *Server) registerControllers(deps Deps, proxyUpdater ProxyUpdater) error {
|
||||
if s.config.Cloud.IsConfigured() {
|
||||
hcpctl.RegisterControllers(
|
||||
s.controllerManager, hcpctl.ControllerDependencies{
|
||||
ResourceApisEnabled: s.useV2Resources,
|
||||
|
@ -1015,6 +1020,7 @@ func (s *Server) registerControllers(deps Deps, proxyUpdater ProxyUpdater) error
|
|||
CloudConfig: deps.HCP.Config,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// When not enabled, the v1 tenancy bridge is used by default.
|
||||
if s.useV2Tenancy {
|
||||
|
@ -2075,8 +2081,10 @@ func (s *Server) trackLeaderChanges() {
|
|||
s.raftStorageBackend.LeaderChanged()
|
||||
s.controllerManager.SetRaftLeader(s.IsLeader())
|
||||
|
||||
if s.config.Cloud.IsConfigured() {
|
||||
// Trigger sending an update to HCP status
|
||||
s.hcpManager.SendUpdate()
|
||||
}
|
||||
case <-s.shutdownCh:
|
||||
s.raft.DeregisterObserver(observer)
|
||||
return
|
||||
|
|
|
@ -2100,6 +2100,9 @@ func TestServer_hcpManager(t *testing.T) {
|
|||
// Configure the server for the StatusFn
|
||||
conf1.BootstrapExpect = 1
|
||||
conf1.RPCAdvertise = &net.TCPAddr{IP: []byte{127, 0, 0, 2}, Port: conf1.RPCAddr.Port}
|
||||
conf1.Cloud.ClientID = "test-client-id"
|
||||
conf1.Cloud.ResourceID = "test-resource-id"
|
||||
conf1.Cloud.ClientSecret = "test-client-secret"
|
||||
hcp1 := hcpclient.NewMockClient(t)
|
||||
hcp1.EXPECT().PushServerStatus(mock.Anything, mock.MatchedBy(func(status *hcpclient.ServerStatus) bool {
|
||||
return status.ID == string(conf1.NodeID)
|
||||
|
|
|
@ -138,6 +138,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer, providedLogger hcl
|
|||
cfg.Telemetry.PrometheusOpts.SummaryDefinitions = summaries
|
||||
|
||||
var extraSinks []metrics.MetricSink
|
||||
if cfg.IsCloudEnabled() {
|
||||
// This values is set late within newNodeIDFromConfig above
|
||||
cfg.Cloud.NodeID = cfg.NodeID
|
||||
|
||||
|
@ -148,6 +149,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer, providedLogger hcl
|
|||
if d.HCP.Sink != nil {
|
||||
extraSinks = append(extraSinks, d.HCP.Sink)
|
||||
}
|
||||
}
|
||||
|
||||
d.MetricsConfig, err = lib.InitTelemetry(cfg.Telemetry, d.Logger, extraSinks...)
|
||||
if err != nil {
|
||||
|
|
|
@ -181,12 +181,9 @@ func (c *cmd) run(args []string) int {
|
|||
ui.Error(err.Error())
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
// We unconditionally add an Access Control header to our config in order to allow the HCP UI to work.
|
||||
// We do this unconditionally because the cluster can be linked to HCP at any time (not just at startup) and this
|
||||
// is simpler than selectively reloading parts of config at runtime.
|
||||
loader = hcpbootstrap.AddAclPolicyAccessControlHeader(loader)
|
||||
}
|
||||
|
||||
bd, err := agent.NewBaseDeps(loader, logGate, nil)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue