@ -595,32 +595,34 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
StorageBackend : s . raftStorageBackend ,
StorageBackend : s . raftStorageBackend ,
} )
} )
s . hcpManager = hcp . NewManager ( hcp . ManagerConfig {
if s . config . Cloud . IsConfigured ( ) {
CloudConfig : flat . HCP . Config ,
s . hcpManager = hcp . NewManager ( hcp . ManagerConfig {
StatusFn : s . hcpServerStatus ( flat ) ,
CloudConfig : flat . HCP . Config ,
Logger : logger . Named ( "hcp_manager" ) ,
StatusFn : s . hcpServerStatus ( flat ) ,
SCADAProvider : flat . HCP . Provider ,
Logger : logger . Named ( "hcp_manager" ) ,
TelemetryProvider : flat . HCP . TelemetryProvider ,
SCADAProvider : flat . HCP . Provider ,
ManagementTokenUpserterFn : func ( name , secretId string ) error {
TelemetryProvider : flat . HCP . TelemetryProvider ,
// Check the state of the server before attempting to upsert the token. Otherwise,
ManagementTokenUpserterFn : func ( name , secretId string ) error {
// the upsert will fail and log errors that do not require action from the user.
// Check the state of the server before attempting to upsert the token. Otherwise,
if s . config . ACLsEnabled && s . IsLeader ( ) && s . InPrimaryDatacenter ( ) {
// the upsert will fail and log errors that do not require action from the user.
// Idea for improvement: Upsert a token with a well-known accessorId here instead
if s . config . ACLsEnabled && s . IsLeader ( ) && s . InPrimaryDatacenter ( ) {
// of a randomly generated one. This would prevent any possible insertion collision between
// Idea for improvement: Upsert a token with a well-known accessorId here instead
// this and the insertion that happens during the ACL initialization process (initializeACLs function)
// of a randomly generated one. This would prevent any possible insertion collision between
return s . upsertManagementToken ( name , secretId )
// this and the insertion that happens during the ACL initialization process (initializeACLs function)
}
return s . upsertManagementToken ( name , secretId )
return nil
}
} ,
return nil
ManagementTokenDeleterFn : func ( secretId string ) error {
} ,
// Check the state of the server before attempting to delete the token.Otherwise,
ManagementTokenDeleterFn : func ( secretId string ) error {
// the delete will fail and log errors that do not require action from the user.
// Check the state of the server before attempting to delete the token.Otherwise,
if s . config . ACLsEnabled && s . IsLeader ( ) && s . InPrimaryDatacenter ( ) {
// the delete will fail and log errors that do not require action from the user.
return s . deleteManagementToken ( secretId )
if s . config . ACLsEnabled && s . IsLeader ( ) && s . InPrimaryDatacenter ( ) {
}
return s . deleteManagementToken ( secretId )
return nil
}
} ,
return nil
} )
} ,
} )
}
var recorder * middleware . RequestRecorder
var recorder * middleware . RequestRecorder
if flat . NewRequestRecorderFunc != nil {
if flat . NewRequestRecorderFunc != nil {
@ -890,22 +892,24 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
// to enable RPC forwarding.
// to enable RPC forwarding.
s . grpcLeaderForwarder = flat . LeaderForwarder
s . grpcLeaderForwarder = flat . LeaderForwarder
// Start watching HCP Link resource. This needs to be created after
if s . config . Cloud . IsConfigured ( ) {
// the GRPC services are set up in order for the resource service client to
// Start watching HCP Link resource. This needs to be created after
// function. This uses the insecure grpc channel so that it doesn't need to
// the GRPC services are set up in order for the resource service client to
// present a valid ACL token.
// function. This uses the insecure grpc channel so that it doesn't need to
go hcp . RunHCPLinkWatcher (
// present a valid ACL token.
& lib . StopChannelContext { StopCh : shutdownCh } ,
go hcp . RunHCPLinkWatcher (
logger . Named ( "hcp-link-watcher" ) ,
& lib . StopChannelContext { StopCh : shutdownCh } ,
pbresource . NewResourceServiceClient ( s . insecureSafeGRPCChan ) ,
logger . Named ( "hcp-link-watcher" ) ,
hcp . HCPManagerLifecycleFn (
pbresource . NewResourceServiceClient ( s . insecureSafeGRPCChan ) ,
s . hcpManager ,
hcp . HCPManagerLifecycleFn (
hcpclient . NewClient ,
s . hcpManager ,
bootstrap . LoadManagementToken ,
hcpclient . NewClient ,
flat . HCP . Config ,
bootstrap . LoadManagementToken ,
flat . HCP . DataDir ,
flat . HCP . Config ,
) ,
flat . HCP . DataDir ,
)
) ,
)
}
s . controllerManager = controller . NewManager (
s . controllerManager = controller . NewManager (
// Usage of the insecure + unsafe grpc chan is required for the controller
// Usage of the insecure + unsafe grpc chan is required for the controller
@ -1008,13 +1012,15 @@ func isV1CatalogRequest(rpcName string) bool {
}
}
func ( s * Server ) registerControllers ( deps Deps , proxyUpdater ProxyUpdater ) error {
func ( s * Server ) registerControllers ( deps Deps , proxyUpdater ProxyUpdater ) error {
hcpctl . RegisterControllers (
if s . config . Cloud . IsConfigured ( ) {
s . controllerManager , hcpctl . ControllerDependencies {
hcpctl . RegisterControllers (
ResourceApisEnabled : s . useV2Resources ,
s . controllerManager , hcpctl . ControllerDependencies {
HCPAllowV2ResourceApis : s . hcpAllowV2Resources ,
ResourceApisEnabled : s . useV2Resources ,
CloudConfig : deps . HCP . Config ,
HCPAllowV2ResourceApis : s . hcpAllowV2Resources ,
} ,
CloudConfig : deps . HCP . Config ,
)
} ,
)
}
// When not enabled, the v1 tenancy bridge is used by default.
// When not enabled, the v1 tenancy bridge is used by default.
if s . useV2Tenancy {
if s . useV2Tenancy {
@ -2075,8 +2081,10 @@ func (s *Server) trackLeaderChanges() {
s . raftStorageBackend . LeaderChanged ( )
s . raftStorageBackend . LeaderChanged ( )
s . controllerManager . SetRaftLeader ( s . IsLeader ( ) )
s . controllerManager . SetRaftLeader ( s . IsLeader ( ) )
// Trigger sending an update to HCP status
if s . config . Cloud . IsConfigured ( ) {
s . hcpManager . SendUpdate ( )
// Trigger sending an update to HCP status
s . hcpManager . SendUpdate ( )
}
case <- s . shutdownCh :
case <- s . shutdownCh :
s . raft . DeregisterObserver ( observer )
s . raft . DeregisterObserver ( observer )
return
return