Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2374,7 +2374,7 @@ func (a *Agent) addServiceLocked(req addServiceLockedRequest) error {
}
}

req.Service.EnterpriseMeta.Normalize()
req.Service.Normalize()

if err := a.validateService(req.Service, req.chkTypes); err != nil {
return err
Expand Down Expand Up @@ -2855,7 +2855,7 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
func (a *Agent) addCheckLocked(check *structs.HealthCheck, chkType *structs.CheckType, persist bool, token string, source configSource) error {
var service *structs.NodeService

check.EnterpriseMeta.Normalize()
check.Normalize()

if check.ServiceID != "" {
cid := check.CompoundServiceID()
Expand Down Expand Up @@ -3630,7 +3630,7 @@ func (a *Agent) storePid() error {

// Write out the PID
pid := os.Getpid()
_, err = pidFile.WriteString(fmt.Sprintf("%d", pid))
_, err = fmt.Fprintf(pidFile, "%d", pid)
if err != nil {
return fmt.Errorf("Could not write to pid file: %s", err)
}
Expand Down Expand Up @@ -3674,8 +3674,8 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig, snap map[structs.CheckI
// Register the services from config
for _, service := range conf.Services {
// Default service partition to the same as agent
if service.EnterpriseMeta.PartitionOrEmpty() == "" {
service.EnterpriseMeta.OverridePartition(a.AgentEnterpriseMeta().PartitionOrDefault())
if service.PartitionOrEmpty() == "" {
service.OverridePartition(a.AgentEnterpriseMeta().PartitionOrDefault())
}

ns := service.NodeService()
Expand Down Expand Up @@ -3801,7 +3801,7 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig, snap map[structs.CheckI
} else if !acl.EqualPartitions(a.AgentEnterpriseMeta().PartitionOrDefault(), p.Service.PartitionOrDefault()) {
a.logger.Info("Purging service file in wrong partition",
"file", file,
"partition", p.Service.EnterpriseMeta.PartitionOrDefault(),
"partition", p.Service.PartitionOrDefault(),
)
if err := os.Remove(file); err != nil {
a.logger.Error("Failed purging service file",
Expand Down
16 changes: 8 additions & 8 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ func test_createAlias(t *testing.T, agent *TestAgent, chk *structs.CheckType, ex
found = true
assert.Equal(t, expectedResult, c.Check.Status, "Check state should be %s, was %s in %#v", expectedResult, c.Check.Status, c.Check)
srvID := structs.NewServiceID(srv.ID, structs.WildcardEnterpriseMetaInDefaultPartition())
if err := agent.Agent.State.RemoveService(srvID); err != nil {
if err := agent.State.RemoveService(srvID); err != nil {
fmt.Println("[DEBUG] Fail to remove service", srvID, ", err:=", err)
}
fmt.Println("[DEBUG] Service Removed", srvID, ", err:=", err)
Expand Down Expand Up @@ -2273,7 +2273,7 @@ func TestAgent_HTTPCheck_EnableAgentTLSForChecks(t *testing.T) {
Status: api.HealthCritical,
}

addr, err := firstAddr(a.Agent.apiServers, "https")
addr, err := firstAddr(a.apiServers, "https")
require.NoError(t, err)
url := fmt.Sprintf("https://%s/v1/agent/self", addr.String())
chk := &structs.CheckType{
Expand Down Expand Up @@ -5378,7 +5378,7 @@ func TestAutoConfig_Integration(t *testing.T) {
defer client.Shutdown()

retry.Run(t, func(r *retry.R) {
require.NotNil(r, client.Agent.tlsConfigurator.Cert())
require.NotNil(r, client.tlsConfigurator.Cert())
})

// when this is successful we managed to get the gossip key and serf addresses to bind to
Expand All @@ -5390,7 +5390,7 @@ func TestAutoConfig_Integration(t *testing.T) {
require.NotEmpty(t, client.tokens.AgentToken())

// grab the existing cert
cert1 := client.Agent.tlsConfigurator.Cert()
cert1 := client.tlsConfigurator.Cert()
require.NotNil(t, cert1)

// force a roots rotation by updating the CA config
Expand All @@ -5414,7 +5414,7 @@ func TestAutoConfig_Integration(t *testing.T) {

// ensure that a new cert gets generated and pushed into the TLS configurator
retry.Run(t, func(r *retry.R) {
require.NotEqual(r, cert1, client.Agent.tlsConfigurator.Cert())
require.NotEqual(r, cert1, client.tlsConfigurator.Cert())

// check that the on disk certs match expectations
data, err := os.ReadFile(filepath.Join(client.DataDir, "auto-config.json"))
Expand All @@ -5428,7 +5428,7 @@ func TestAutoConfig_Integration(t *testing.T) {

actual, err := tls.X509KeyPair([]byte(resp.Certificate.CertPEM), []byte(resp.Certificate.PrivateKeyPEM))
require.NoError(r, err)
require.Equal(r, client.Agent.tlsConfigurator.Cert(), &actual)
require.Equal(r, client.tlsConfigurator.Cert(), &actual)
})
}

Expand Down Expand Up @@ -5527,7 +5527,7 @@ func TestSharedRPCRouter(t *testing.T) {

testrpc.WaitForTestAgent(t, srv.RPC, "dc1")

mgr, server := srv.Agent.baseDeps.Router.FindLANRoute()
mgr, server := srv.baseDeps.Router.FindLANRoute()
require.NotNil(t, mgr)
require.NotNil(t, server)

Expand All @@ -5539,7 +5539,7 @@ func TestSharedRPCRouter(t *testing.T) {

testrpc.WaitForTestAgent(t, client.RPC, "dc1")

mgr, server = client.Agent.baseDeps.Router.FindLANRoute()
mgr, server = client.baseDeps.Router.FindLANRoute()
require.NotNil(t, mgr)
require.NotNil(t, server)
}
Expand Down
2 changes: 1 addition & 1 deletion agent/auto-config/auto_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func New(config Config) (*AutoConfig, error) {
}
}

if err := config.EnterpriseConfig.validateAndFinalize(); err != nil {
if err := config.validateAndFinalize(); err != nil {
return nil, err
}

Expand Down
18 changes: 9 additions & 9 deletions agent/auto-config/auto_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestInitialConfiguration_cancelled(t *testing.T) {
}
verify_outgoing = true
`)
mcfg.Config.Loader = loader.Load
mcfg.Loader = loader.Load

expectedRequest := pbautoconf.AutoConfigRequest{
Datacenter: "dc1",
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestInitialConfiguration_restored(t *testing.T) {
verify_outgoing = true
`)

mcfg.Config.Loader = loader.Load
mcfg.Loader = loader.Load

indexedRoots, cert, extraCACerts := mcfg.setupInitialTLS(t, "autoconf", "dc1", "secret")

Expand Down Expand Up @@ -344,7 +344,7 @@ func TestInitialConfiguration_success(t *testing.T) {
}
verify_outgoing = true
`)
mcfg.Config.Loader = loader.Load
mcfg.Loader = loader.Load

indexedRoots, cert, extraCerts := mcfg.setupInitialTLS(t, "autoconf", "dc1", "secret")

Expand Down Expand Up @@ -423,10 +423,10 @@ func TestInitialConfiguration_retries(t *testing.T) {
}
verify_outgoing = true
`)
mcfg.Config.Loader = loader.Load
mcfg.Loader = loader.Load

// reduce the retry wait times to make this test run faster
mcfg.Config.Waiter = &retry.Waiter{MinFailures: 2, MaxWait: time.Millisecond}
mcfg.Waiter = &retry.Waiter{MinFailures: 2, MaxWait: time.Millisecond}

indexedRoots, cert, extraCerts := mcfg.setupInitialTLS(t, "autoconf", "dc1", "secret")

Expand Down Expand Up @@ -535,7 +535,7 @@ func TestGoRoutineManagement(t *testing.T) {
}
verify_outgoing = true
`)
mcfg.Config.Loader = loader.Load
mcfg.Loader = loader.Load

// prepopulation is going to grab the token to populate the correct cache key
mcfg.tokens.On("AgentToken").Return("secret").Times(0)
Expand Down Expand Up @@ -604,7 +604,7 @@ func TestGoRoutineManagement(t *testing.T) {
waitForContexts := func() bool {
ctxLock.Lock()
defer ctxLock.Unlock()
return !(rootsCtx == nil || leafCtx == nil)
return rootsCtx != nil && leafCtx != nil
}

// wait for the cache notifications to get started
Expand Down Expand Up @@ -676,8 +676,8 @@ func startedAutoConfig(t *testing.T, autoEncrypt bool) testAutoConfig {
verify_outgoing = true
`)
}
mcfg.Config.Loader = loader.Load
mcfg.Config.FallbackLeeway = time.Nanosecond
mcfg.Loader = loader.Load
mcfg.FallbackLeeway = time.Nanosecond

originalToken := "a5deaa25-11ca-48bf-a979-4c3a7aa4b9a9"

Expand Down
4 changes: 2 additions & 2 deletions agent/auto-config/auto_encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestAutoEncrypt_InitialCerts(t *testing.T) {
resp.VerifyServerHostname = true
})

mcfg.Config.Waiter = &retry.Waiter{MinFailures: 2, MaxWait: time.Millisecond}
mcfg.Waiter = &retry.Waiter{MinFailures: 2, MaxWait: time.Millisecond}

ac := AutoConfig{
config: &config.RuntimeConfig{
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestAutoEncrypt_InitialConfiguration(t *testing.T) {
}
`)
loader.opts.FlagValues.NodeName = &nodeName
mcfg.Config.Loader = loader.Load
mcfg.Loader = loader.Load

indexedRoots, cert, extraCerts := mcfg.setupInitialTLS(t, nodeName, datacenter, token)

Expand Down
9 changes: 5 additions & 4 deletions agent/auto-config/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ func newMockDirectRPC(t *testing.T) *mockDirectRPC {

func (m *mockDirectRPC) RPC(dc string, node string, addr net.Addr, method string, args interface{}, reply interface{}) error {
var retValues mock.Arguments
if method == "AutoConfig.InitialConfiguration" {
switch method {
case "AutoConfig.InitialConfiguration":
req := args.(*pbautoconf.AutoConfigRequest)
csr := req.CSR
req.CSR = ""
retValues = m.Called(dc, node, addr, method, args, reply)
req.CSR = csr
} else if method == "AutoEncrypt.Sign" {
case "AutoEncrypt.Sign":
req := args.(*structs.CASignRequest)
csr := req.CSR
req.CSR = ""
retValues = m.Called(dc, node, addr, method, args, reply)
req.CSR = csr
} else {
default:
retValues = m.Called(dc, node, addr, method, args, reply)
}

Expand Down Expand Up @@ -383,7 +384,7 @@ func (m *mockedConfig) expectInitialTLS(t *testing.T, agentName, datacenter, tok
true,
).Return(nil).Once()

rootRes := cache.FetchResult{Value: indexedRoots, Index: indexedRoots.QueryMeta.Index}
rootRes := cache.FetchResult{Value: indexedRoots, Index: indexedRoots.Index}
rootsReq := structs.DCSpecificRequest{Datacenter: datacenter}

// we should prepopulate the cache with the CA roots
Expand Down
2 changes: 1 addition & 1 deletion agent/auto-config/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (ac *AutoConfig) run(ctx context.Context, exit chan struct{}) {
return -1
}
expiry := cert.NotAfter.Add(ac.acConfig.FallbackLeeway)
return expiry.Sub(time.Now())
return time.Until(expiry)
}
fallbackTimer := time.NewTimer(calcFallbackInterval())

Expand Down
4 changes: 2 additions & 2 deletions agent/auto-config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (ac *AutoConfig) populateCertificateCache(certs *structs.SignedResponse) er
}

// prepolutate roots cache
rootRes := cache.FetchResult{Value: &certs.ConnectCARoots, Index: certs.ConnectCARoots.QueryMeta.Index}
rootRes := cache.FetchResult{Value: &certs.ConnectCARoots, Index: certs.ConnectCARoots.Index}
rootsReq := ac.caRootsRequest()
// getting the roots doesn't require a token so in order to potentially share the cache with another
if err := ac.acConfig.Cache.Prepopulate(cachetype.ConnectCARootName, rootRes, ac.config.Datacenter, structs.DefaultPeerKeyword, "", rootsReq.CacheInfo().Key); err != nil {
Expand All @@ -110,7 +110,7 @@ func (ac *AutoConfig) populateCertificateCache(certs *structs.SignedResponse) er
err = ac.acConfig.LeafCertManager.Prepopulate(
context.Background(),
leafReq.Key(),
certs.IssuedCert.RaftIndex.ModifyIndex,
certs.IssuedCert.ModifyIndex,
&certs.IssuedCert,
connect.EncodeSigningKeyID(cert.AuthorityKeyId),
)
Expand Down
30 changes: 15 additions & 15 deletions agent/catalog_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *HTTPHandlers) CatalogDatacenters(resp http.ResponseWriter, req *http.Re
parseCacheControl(resp, req, &args.QueryOptions)
var out []string

if args.QueryOptions.UseCache {
if args.UseCache {
raw, m, err := s.agent.cache.Get(req.Context(), cachetype.CatalogDatacentersName, &args)
if err != nil {
metrics.IncrCounterWithLabels([]string{"client", "rpc", "error", "catalog_datacenters"}, 1,
Expand Down Expand Up @@ -251,12 +251,12 @@ RETRY_ONCE:
if err := s.agent.RPC(req.Context(), "Catalog.ListNodes", &args, &out); err != nil {
return nil, err
}
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
if args.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
args.AllowStale = false
args.MaxStaleDuration = 0
goto RETRY_ONCE
}
out.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
out.ConsistencyLevel = args.ConsistencyLevel()

s.agent.TranslateAddresses(args.Datacenter, out.Nodes, dnsutil.TranslateAddressAcceptAny)

Expand Down Expand Up @@ -285,7 +285,7 @@ func (s *HTTPHandlers) CatalogServices(resp http.ResponseWriter, req *http.Reque
var out structs.IndexedServices
defer setMeta(resp, &out.QueryMeta)

if args.QueryOptions.UseCache {
if args.UseCache {
raw, m, err := s.agent.cache.Get(req.Context(), cachetype.CatalogListServicesName, &args)
if err != nil {
metrics.IncrCounterWithLabels([]string{"client", "rpc", "error", "catalog_services"}, 1,
Expand All @@ -306,14 +306,14 @@ func (s *HTTPHandlers) CatalogServices(resp http.ResponseWriter, req *http.Reque
s.nodeMetricsLabels())
return nil, err
}
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
if args.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
args.AllowStale = false
args.MaxStaleDuration = 0
goto RETRY_ONCE
}
}

out.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
out.ConsistencyLevel = args.ConsistencyLevel()

// Use empty map instead of nil
if out.Services == nil {
Expand Down Expand Up @@ -377,7 +377,7 @@ func (s *HTTPHandlers) catalogServiceNodes(resp http.ResponseWriter, req *http.R
var out structs.IndexedServiceNodes
defer setMeta(resp, &out.QueryMeta)

if args.QueryOptions.UseCache {
if args.UseCache {
raw, m, err := s.agent.cache.Get(req.Context(), cachetype.CatalogServicesName, &args)
if err != nil {
metrics.IncrCounterWithLabels([]string{"client", "rpc", "error", "catalog_service_nodes"}, 1,
Expand All @@ -398,14 +398,14 @@ func (s *HTTPHandlers) catalogServiceNodes(resp http.ResponseWriter, req *http.R
s.nodeMetricsLabels())
return nil, err
}
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
if args.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
args.AllowStale = false
args.MaxStaleDuration = 0
goto RETRY_ONCE
}
}

out.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
out.ConsistencyLevel = args.ConsistencyLevel()
s.agent.TranslateAddresses(args.Datacenter, out.ServiceNodes, dnsutil.TranslateAddressAcceptAny)

// Use empty list instead of nil
Expand Down Expand Up @@ -453,12 +453,12 @@ RETRY_ONCE:
s.nodeMetricsLabels())
return nil, err
}
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
if args.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
args.AllowStale = false
args.MaxStaleDuration = 0
goto RETRY_ONCE
}
out.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
out.ConsistencyLevel = args.ConsistencyLevel()
if out.NodeServices != nil {
s.agent.TranslateAddresses(args.Datacenter, out.NodeServices, dnsutil.TranslateAddressAcceptAny)
}
Expand Down Expand Up @@ -518,12 +518,12 @@ RETRY_ONCE:
s.nodeMetricsLabels())
return nil, err
}
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
if args.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
args.AllowStale = false
args.MaxStaleDuration = 0
goto RETRY_ONCE
}
out.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
out.ConsistencyLevel = args.ConsistencyLevel()
s.agent.TranslateAddresses(args.Datacenter, &out.NodeServices, dnsutil.TranslateAddressAcceptAny)

// Use empty list instead of nil
Expand Down Expand Up @@ -565,12 +565,12 @@ RETRY_ONCE:
s.nodeMetricsLabels())
return nil, err
}
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
if args.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < out.LastContact {
args.AllowStale = false
args.MaxStaleDuration = 0
goto RETRY_ONCE
}
out.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
out.ConsistencyLevel = args.ConsistencyLevel()

metrics.IncrCounterWithLabels([]string{"client", "api", "success", "catalog_gateway_services"}, 1,
s.nodeMetricsLabels())
Expand Down
Loading
Loading