From 6ba0661caf99544fa4233a7e1183d9b04b0971db Mon Sep 17 00:00:00 2001 From: Sreeram Narayanan Date: Thu, 28 Aug 2025 15:41:23 +0530 Subject: [PATCH] fix: golangci-lint issues --- acl/enterprisemeta_ce.go | 6 +- agent/agent_endpoint_test.go | 57 ++++++++-------- agent/auto-config/auto_config_test.go | 2 +- agent/auto-config/auto_encrypt_test.go | 2 +- agent/auto-config/config_ce.go | 2 +- agent/auto-config/mock_test.go | 4 +- agent/cache-types/catalog_list_services.go | 12 ++-- .../cache-types/catalog_list_services_test.go | 8 +-- agent/cache-types/catalog_service_list.go | 6 +- .../cache-types/catalog_service_list_test.go | 6 +- agent/cache-types/catalog_services.go | 6 +- agent/cache-types/catalog_services_test.go | 6 +- agent/cache-types/config_entry.go | 12 ++-- agent/cache-types/config_entry_test.go | 12 ++-- agent/cache-types/connect_ca_root.go | 6 +- agent/cache-types/connect_ca_root_test.go | 6 +- agent/cache-types/discovery_chain.go | 6 +- agent/cache-types/discovery_chain_test.go | 6 +- agent/cache-types/exported_peered_services.go | 6 +- .../exported_peered_services_test.go | 6 +- .../federation_state_list_gateways.go | 6 +- .../federation_state_list_gateways_test.go | 6 +- agent/cache-types/gateway_services.go | 6 +- agent/cache-types/gateway_services_test.go | 6 +- agent/cache-types/health_services.go | 6 +- agent/cache-types/health_services_test.go | 6 +- agent/cache-types/intention_upstreams.go | 6 +- .../intention_upstreams_destination.go | 6 +- .../intention_upstreams_destination_test.go | 6 +- agent/cache-types/intention_upstreams_test.go | 6 +- agent/cache-types/node_services.go | 6 +- agent/cache-types/node_services_test.go | 6 +- agent/cache-types/peered_upstreams.go | 6 +- agent/cache-types/peered_upstreams_test.go | 2 +- agent/cache-types/peerings.go | 6 +- agent/cache-types/prepared_query.go | 2 +- agent/cache-types/prepared_query_test.go | 2 +- agent/cache-types/resolved_service_config.go | 6 +- .../resolved_service_config_test.go | 6 +- agent/cache-types/service_dump.go | 6 +- agent/cache-types/service_dump_test.go | 6 +- agent/cache-types/service_gateways.go | 6 +- agent/cache-types/service_gateways_test.go | 6 +- agent/cache-types/trust_bundle.go | 6 +- agent/cache-types/trust_bundles.go | 6 +- agent/checks/check_test.go | 5 +- agent/config/builder.go | 12 ++-- agent/config/deprecated.go | 68 +++++++++---------- agent/config/deprecated_test.go | 3 +- agent/config/file_watcher_test.go | 2 +- agent/config/flags.go | 4 +- agent/config_endpoint.go | 4 +- agent/configentry/merge_service_config.go | 2 +- agent/connect/ca/provider_aws_test.go | 36 +++++----- agent/dns.go | 7 +- .../get_envoy_bootstrap_params_test.go | 28 ++++---- .../services/peerstream/replication.go | 3 +- .../services/peerstream/stream_test.go | 3 +- .../resource/mutate_and_validate_test.go | 6 +- .../resource/write_mav_common_test.go | 36 +--------- .../services/resource/write_status.go | 3 - .../services/resource/write_test.go | 6 +- .../services/subscribe/subscribe_test.go | 12 ++-- agent/hcp/testing.go | 2 +- agent/http.go | 11 --- agent/leafcert/leafcert_test.go | 38 +++++------ agent/metrics_test.go | 9 ++- agent/notify_test.go | 10 +-- agent/peering_endpoint.go | 4 +- agent/prepared_query_endpoint.go | 8 +-- agent/proxycfg/api_gateway.go | 2 - agent/session_endpoint.go | 2 - agent/structs/config_entry.go | 2 +- .../structs/config_entry_jwt_provider_test.go | 2 +- agent/xds/clusters.go | 2 +- agent/xds/listeners.go | 2 +- agent/xds/xds_protocol_helpers_test.go | 4 +- command/monitor/monitor.go | 11 ++- command/peering/read/read.go | 4 +- command/tls/cert/create/tls_cert_create.go | 4 +- command/version/formatter.go | 4 +- .../go-sso/oidcauth/oidcauthtest/testing.go | 10 +-- internal/resource/reaper/controller_test.go | 3 +- tlsutil/config_test.go | 5 -- 84 files changed, 313 insertions(+), 381 deletions(-) diff --git a/acl/enterprisemeta_ce.go b/acl/enterprisemeta_ce.go index 7262e79b6dc6..4636b36c8eac 100644 --- a/acl/enterprisemeta_ce.go +++ b/acl/enterprisemeta_ce.go @@ -84,9 +84,9 @@ func (m *EnterpriseMeta) MergeNoWildcard(_ *EnterpriseMeta) { // do nothing } -func (_ *EnterpriseMeta) Normalize() {} -func (_ *EnterpriseMeta) NormalizePartition() {} -func (_ *EnterpriseMeta) NormalizeNamespace() {} +func (*EnterpriseMeta) Normalize() {} +func (*EnterpriseMeta) NormalizePartition() {} +func (*EnterpriseMeta) NormalizeNamespace() {} func (m *EnterpriseMeta) Matches(_ *EnterpriseMeta) bool { return true diff --git a/agent/agent_endpoint_test.go b/agent/agent_endpoint_test.go index 451c412b4b1c..ca4b60ab4220 100644 --- a/agent/agent_endpoint_test.go +++ b/agent/agent_endpoint_test.go @@ -40,7 +40,6 @@ import ( "github.com/hashicorp/consul/agent/local" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/token" - tokenStore "github.com/hashicorp/consul/agent/token" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/envoyextensions/xdscommon" "github.com/hashicorp/consul/lib" @@ -1728,7 +1727,7 @@ func newDefaultBaseDeps(t *testing.T) BaseDeps { func TestHTTPHandlers_AgentMetricsStream_ACLDeny(t *testing.T) { t.Skip("this test panics without a license manager in enterprise") bd := newDefaultBaseDeps(t) - bd.Tokens = new(tokenStore.Store) + bd.Tokens = new(token.Store) sink := metrics.NewInmemSink(30*time.Millisecond, time.Second) bd.MetricsConfig = &lib.MetricsConfig{ Handler: sink, @@ -1760,7 +1759,7 @@ func TestHTTPHandlers_AgentMetricsStream_ACLDeny(t *testing.T) { func TestHTTPHandlers_AgentMetricsStream(t *testing.T) { t.Skip("this test panics without a license manager in enterprise") bd := newDefaultBaseDeps(t) - bd.Tokens = new(tokenStore.Store) + bd.Tokens = new(token.Store) sink := metrics.NewInmemSink(20*time.Millisecond, time.Second) bd.MetricsConfig = &lib.MetricsConfig{ Handler: sink, @@ -6479,15 +6478,15 @@ func TestAgent_Token(t *testing.T) { type tokens struct { user string - userSource tokenStore.TokenSource + userSource token.TokenSource agent string - agentSource tokenStore.TokenSource + agentSource token.TokenSource agentRecovery string - agentRecoverySource tokenStore.TokenSource + agentRecoverySource token.TokenSource repl string - replSource tokenStore.TokenSource + replSource token.TokenSource registration string - registrationSource tokenStore.TokenSource + registrationSource token.TokenSource } resetTokens := func(init tokens) { @@ -6538,7 +6537,7 @@ func TestAgent_Token(t *testing.T) { url: "acl_token", body: body("U"), code: http.StatusOK, - raw: tokens{user: "U", userSource: tokenStore.TokenSourceAPI}, + raw: tokens{user: "U", userSource: token.TokenSourceAPI}, effective: tokens{user: "U", agent: "U"}, }, { @@ -6547,7 +6546,7 @@ func TestAgent_Token(t *testing.T) { url: "default", body: body("U"), code: http.StatusOK, - raw: tokens{user: "U", userSource: tokenStore.TokenSourceAPI}, + raw: tokens{user: "U", userSource: token.TokenSourceAPI}, effective: tokens{user: "U", agent: "U"}, }, { @@ -6557,7 +6556,7 @@ func TestAgent_Token(t *testing.T) { body: body("A"), code: http.StatusOK, init: tokens{user: "U", agent: "U"}, - raw: tokens{user: "U", agent: "A", agentSource: tokenStore.TokenSourceAPI}, + raw: tokens{user: "U", agent: "A", agentSource: token.TokenSourceAPI}, effective: tokens{user: "U", agent: "A"}, }, { @@ -6567,7 +6566,7 @@ func TestAgent_Token(t *testing.T) { body: body("A"), code: http.StatusOK, init: tokens{user: "U", agent: "U"}, - raw: tokens{user: "U", agent: "A", agentSource: tokenStore.TokenSourceAPI}, + raw: tokens{user: "U", agent: "A", agentSource: token.TokenSourceAPI}, effective: tokens{user: "U", agent: "A"}, }, { @@ -6576,7 +6575,7 @@ func TestAgent_Token(t *testing.T) { url: "acl_agent_master_token", body: body("M"), code: http.StatusOK, - raw: tokens{agentRecovery: "M", agentRecoverySource: tokenStore.TokenSourceAPI}, + raw: tokens{agentRecovery: "M", agentRecoverySource: token.TokenSourceAPI}, effective: tokens{agentRecovery: "M"}, }, { @@ -6585,7 +6584,7 @@ func TestAgent_Token(t *testing.T) { url: "agent_master", body: body("M"), code: http.StatusOK, - raw: tokens{agentRecovery: "M", agentRecoverySource: tokenStore.TokenSourceAPI}, + raw: tokens{agentRecovery: "M", agentRecoverySource: token.TokenSourceAPI}, effective: tokens{agentRecovery: "M"}, }, { @@ -6594,8 +6593,8 @@ func TestAgent_Token(t *testing.T) { url: "agent_recovery", body: body("R"), code: http.StatusOK, - raw: tokens{agentRecovery: "R", agentRecoverySource: tokenStore.TokenSourceAPI}, - effective: tokens{agentRecovery: "R", agentRecoverySource: tokenStore.TokenSourceAPI}, + raw: tokens{agentRecovery: "R", agentRecoverySource: token.TokenSourceAPI}, + effective: tokens{agentRecovery: "R", agentRecoverySource: token.TokenSourceAPI}, }, { name: "set repl legacy", @@ -6603,7 +6602,7 @@ func TestAgent_Token(t *testing.T) { url: "acl_replication_token", body: body("R"), code: http.StatusOK, - raw: tokens{repl: "R", replSource: tokenStore.TokenSourceAPI}, + raw: tokens{repl: "R", replSource: token.TokenSourceAPI}, effective: tokens{repl: "R"}, }, { @@ -6612,7 +6611,7 @@ func TestAgent_Token(t *testing.T) { url: "replication", body: body("R"), code: http.StatusOK, - raw: tokens{repl: "R", replSource: tokenStore.TokenSourceAPI}, + raw: tokens{repl: "R", replSource: token.TokenSourceAPI}, effective: tokens{repl: "R"}, }, { @@ -6621,7 +6620,7 @@ func TestAgent_Token(t *testing.T) { url: "config_file_service_registration", body: body("G"), code: http.StatusOK, - raw: tokens{registration: "G", registrationSource: tokenStore.TokenSourceAPI}, + raw: tokens{registration: "G", registrationSource: token.TokenSourceAPI}, effective: tokens{registration: "G"}, }, { @@ -6631,7 +6630,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{user: "U"}, - raw: tokens{userSource: tokenStore.TokenSourceAPI}, + raw: tokens{userSource: token.TokenSourceAPI}, }, { name: "clear default", @@ -6640,7 +6639,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{user: "U"}, - raw: tokens{userSource: tokenStore.TokenSourceAPI}, + raw: tokens{userSource: token.TokenSourceAPI}, }, { name: "clear agent legacy", @@ -6649,7 +6648,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{agent: "A"}, - raw: tokens{agentSource: tokenStore.TokenSourceAPI}, + raw: tokens{agentSource: token.TokenSourceAPI}, }, { name: "clear agent", @@ -6658,7 +6657,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{agent: "A"}, - raw: tokens{agentSource: tokenStore.TokenSourceAPI}, + raw: tokens{agentSource: token.TokenSourceAPI}, }, { name: "clear master legacy", @@ -6667,7 +6666,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{agentRecovery: "M"}, - raw: tokens{agentRecoverySource: tokenStore.TokenSourceAPI}, + raw: tokens{agentRecoverySource: token.TokenSourceAPI}, }, { name: "clear master", @@ -6676,7 +6675,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{agentRecovery: "M"}, - raw: tokens{agentRecoverySource: tokenStore.TokenSourceAPI}, + raw: tokens{agentRecoverySource: token.TokenSourceAPI}, }, { name: "clear recovery", @@ -6685,7 +6684,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{agentRecovery: "R"}, - raw: tokens{agentRecoverySource: tokenStore.TokenSourceAPI}, + raw: tokens{agentRecoverySource: token.TokenSourceAPI}, }, { name: "clear repl legacy", @@ -6694,7 +6693,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{repl: "R"}, - raw: tokens{replSource: tokenStore.TokenSourceAPI}, + raw: tokens{replSource: token.TokenSourceAPI}, }, { name: "clear repl", @@ -6703,7 +6702,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{repl: "R"}, - raw: tokens{replSource: tokenStore.TokenSourceAPI}, + raw: tokens{replSource: token.TokenSourceAPI}, }, { name: "clear registration", @@ -6712,7 +6711,7 @@ func TestAgent_Token(t *testing.T) { body: body(""), code: http.StatusOK, init: tokens{registration: "G"}, - raw: tokens{registrationSource: tokenStore.TokenSourceAPI}, + raw: tokens{registrationSource: token.TokenSourceAPI}, }, } for _, tt := range tests { diff --git a/agent/auto-config/auto_config_test.go b/agent/auto-config/auto_config_test.go index 596208eb6f82..6e112e27593c 100644 --- a/agent/auto-config/auto_config_test.go +++ b/agent/auto-config/auto_config_test.go @@ -1091,7 +1091,7 @@ func TestFallback(t *testing.T) { // auto-config response which is how the Fallback for auto-config works testAC.mcfg.tokens.On("UpdateAgentToken", testAC.originalToken, token.TokenSourceConfig).Return(true).Once() - testAC.mcfg.expectInitialTLS(t, "autoconf", "dc1", testAC.originalToken, secondCA, secondRoots, thirdCert, testAC.extraCerts) + testAC.mcfg.expectInitialTLS("autoconf", "dc1", testAC.originalToken, secondCA, secondRoots, thirdCert, testAC.extraCerts) // after the second RPC we now will use the new certs validity period in the next run loop iteration testAC.mcfg.tlsCfg.On("AutoEncryptCert").Return(&x509.Certificate{ diff --git a/agent/auto-config/auto_encrypt_test.go b/agent/auto-config/auto_encrypt_test.go index 09eef3bb2537..4084af68f493 100644 --- a/agent/auto-config/auto_encrypt_test.go +++ b/agent/auto-config/auto_encrypt_test.go @@ -569,7 +569,7 @@ func TestAutoEncrypt_Fallback(t *testing.T) { &expectedRequest, &structs.SignedResponse{}).Return(nil).Run(populateResponse).Once() - testAC.mcfg.expectInitialTLS(t, "autoconf", "dc1", testAC.originalToken, secondCA, &secondRoots, thirdCert, testAC.extraCerts) + testAC.mcfg.expectInitialTLS("autoconf", "dc1", testAC.originalToken, secondCA, &secondRoots, thirdCert, testAC.extraCerts) // after the second RPC we now will use the new certs validity period in the next run loop iteration testAC.mcfg.tlsCfg.On("AutoEncryptCert").Return(&x509.Certificate{ diff --git a/agent/auto-config/config_ce.go b/agent/auto-config/config_ce.go index 5d699f32a498..d582de15b1ab 100644 --- a/agent/auto-config/config_ce.go +++ b/agent/auto-config/config_ce.go @@ -9,6 +9,6 @@ package autoconf type EnterpriseConfig struct{} // finalize is a noop for CE -func (_ *EnterpriseConfig) validateAndFinalize() error { +func (*EnterpriseConfig) validateAndFinalize() error { return nil } diff --git a/agent/auto-config/mock_test.go b/agent/auto-config/mock_test.go index 2d39c9b608ef..01159101444a 100644 --- a/agent/auto-config/mock_test.go +++ b/agent/auto-config/mock_test.go @@ -360,7 +360,7 @@ func newMockedConfig(t *testing.T) *mockedConfig { } } -func (m *mockedConfig) expectInitialTLS(t *testing.T, agentName, datacenter, token string, ca *structs.CARoot, indexedRoots *structs.IndexedCARoots, cert *structs.IssuedCert, extraCerts []string) { +func (m *mockedConfig) expectInitialTLS(agentName, datacenter, token string, ca *structs.CARoot, indexedRoots *structs.IndexedCARoots, cert *structs.IssuedCert, extraCerts []string) { var pems []string for _, root := range indexedRoots.Roots { pems = append(pems, root.RootCert) @@ -430,6 +430,6 @@ func (m *mockedConfig) setupInitialTLS(t *testing.T, agentName, datacenter, toke ca2 := connect.TestCA(t, nil) extraCerts := []string{ca2.RootCert} - m.expectInitialTLS(t, agentName, datacenter, token, ca, indexedRoots, cert, extraCerts) + m.expectInitialTLS(agentName, datacenter, token, ca, indexedRoots, cert, extraCerts) return indexedRoots, cert, extraCerts } diff --git a/agent/cache-types/catalog_list_services.go b/agent/cache-types/catalog_list_services.go index 0a14ed3ef120..990011243900 100644 --- a/agent/cache-types/catalog_list_services.go +++ b/agent/cache-types/catalog_list_services.go @@ -35,17 +35,17 @@ func (c *CatalogListServices) Fetch(opts cache.FetchOptions, req cache.Request) reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This // allows cached service-discover to automatically read scale across all // servers too. - reqReal.QueryOptions.AllowStale = true + reqReal.AllowStale = true if opts.LastResult != nil { - reqReal.QueryOptions.AllowNotModifiedResponse = true + reqReal.AllowNotModifiedResponse = true } var reply structs.IndexedServices @@ -54,7 +54,7 @@ func (c *CatalogListServices) Fetch(opts cache.FetchOptions, req cache.Request) } result.Value = &reply - result.Index = reply.QueryMeta.Index - result.NotModified = reply.QueryMeta.NotModified + result.Index = reply.Index + result.NotModified = reply.NotModified return result, nil } diff --git a/agent/cache-types/catalog_list_services_test.go b/agent/cache-types/catalog_list_services_test.go index 623cda2cee3c..65d7ee4083c4 100644 --- a/agent/cache-types/catalog_list_services_test.go +++ b/agent/cache-types/catalog_list_services_test.go @@ -25,8 +25,8 @@ func TestCatalogListServices(t *testing.T) { rpc.On("RPC", mock.Anything, "Catalog.ListServices", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.DCSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) reply := args.Get(3).(*structs.IndexedServices) @@ -34,7 +34,7 @@ func TestCatalogListServices(t *testing.T) { "foo": {"prod", "linux"}, "bar": {"qa", "windows"}, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) @@ -86,7 +86,7 @@ func TestCatalogListServices_IntegrationWithCache_NotModifiedResponse(t *testing require.True(t, req.AllowNotModifiedResponse) reply := args.Get(3).(*structs.IndexedServices) - reply.QueryMeta.Index = 44 + reply.Index = 44 reply.NotModified = true }) diff --git a/agent/cache-types/catalog_service_list.go b/agent/cache-types/catalog_service_list.go index 37ac4ba0f813..ac6461061744 100644 --- a/agent/cache-types/catalog_service_list.go +++ b/agent/cache-types/catalog_service_list.go @@ -35,8 +35,8 @@ func (c *CatalogServiceList) Fetch(opts cache.FetchOptions, req cache.Request) ( reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -51,6 +51,6 @@ func (c *CatalogServiceList) Fetch(opts cache.FetchOptions, req cache.Request) ( } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/catalog_service_list_test.go b/agent/cache-types/catalog_service_list_test.go index eb686193cc3c..89c050ba8b77 100644 --- a/agent/cache-types/catalog_service_list_test.go +++ b/agent/cache-types/catalog_service_list_test.go @@ -24,8 +24,8 @@ func TestCatalogServiceList(t *testing.T) { rpc.On("RPC", mock.Anything, "Catalog.ServiceList", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.DCSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) reply := args.Get(3).(*structs.IndexedServiceList) @@ -37,7 +37,7 @@ func TestCatalogServiceList(t *testing.T) { Name: "bar", }, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/catalog_services.go b/agent/cache-types/catalog_services.go index 8e04997b9f62..2ae2b63b2116 100644 --- a/agent/cache-types/catalog_services.go +++ b/agent/cache-types/catalog_services.go @@ -36,8 +36,8 @@ func (c *CatalogServices) Fetch(opts cache.FetchOptions, req cache.Request) (cac reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -52,6 +52,6 @@ func (c *CatalogServices) Fetch(opts cache.FetchOptions, req cache.Request) (cac } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/catalog_services_test.go b/agent/cache-types/catalog_services_test.go index c084de67ccaa..192325638d82 100644 --- a/agent/cache-types/catalog_services_test.go +++ b/agent/cache-types/catalog_services_test.go @@ -25,8 +25,8 @@ func TestCatalogServices(t *testing.T) { rpc.On("RPC", mock.Anything, "Catalog.ServiceNodes", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.Equal(t, "web", req.ServiceName) require.True(t, req.AllowStale) @@ -34,7 +34,7 @@ func TestCatalogServices(t *testing.T) { reply.ServiceNodes = []*structs.ServiceNode{ {ServiceTags: req.ServiceTags}, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/config_entry.go b/agent/cache-types/config_entry.go index 98443363c1b8..20e02830be90 100644 --- a/agent/cache-types/config_entry.go +++ b/agent/cache-types/config_entry.go @@ -38,8 +38,8 @@ func (c *ConfigEntryList) Fetch(opts cache.FetchOptions, req cache.Request) (cac reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and endup arbitrarily stale anyway. This @@ -54,7 +54,7 @@ func (c *ConfigEntryList) Fetch(opts cache.FetchOptions, req cache.Request) (cac } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } @@ -79,8 +79,8 @@ func (c *ConfigEntry) Fetch(opts cache.FetchOptions, req cache.Request) (cache.F reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and endup arbitrarily stale anyway. This @@ -95,6 +95,6 @@ func (c *ConfigEntry) Fetch(opts cache.FetchOptions, req cache.Request) (cache.F } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/config_entry_test.go b/agent/cache-types/config_entry_test.go index d892b069e4c7..d47548522f12 100644 --- a/agent/cache-types/config_entry_test.go +++ b/agent/cache-types/config_entry_test.go @@ -24,8 +24,8 @@ func TestConfigEntries(t *testing.T) { rpc.On("RPC", mock.Anything, "ConfigEntry.List", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ConfigEntryQuery) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) require.Equal(t, structs.ServiceResolver, req.Kind) require.Equal(t, "", req.Name) @@ -36,7 +36,7 @@ func TestConfigEntries(t *testing.T) { &structs.ServiceResolverConfigEntry{Kind: structs.ServiceResolver, Name: "foo"}, &structs.ServiceResolverConfigEntry{Kind: structs.ServiceResolver, Name: "bar"}, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) @@ -67,8 +67,8 @@ func TestConfigEntry(t *testing.T) { rpc.On("RPC", mock.Anything, "ConfigEntry.Get", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ConfigEntryQuery) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) require.Equal(t, structs.ServiceResolver, req.Kind) require.Equal(t, "foo", req.Name) @@ -79,7 +79,7 @@ func TestConfigEntry(t *testing.T) { } reply := args.Get(3).(*structs.ConfigEntryResponse) reply.Entry = entry - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/connect_ca_root.go b/agent/cache-types/connect_ca_root.go index 9ba1dab0b7dc..b3c44a3fd267 100644 --- a/agent/cache-types/connect_ca_root.go +++ b/agent/cache-types/connect_ca_root.go @@ -38,8 +38,8 @@ func (c *ConnectCARoot) Fetch(opts cache.FetchOptions, req cache.Request) (cache reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Fetch var reply structs.IndexedCARoots @@ -48,6 +48,6 @@ func (c *ConnectCARoot) Fetch(opts cache.FetchOptions, req cache.Request) (cache } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/connect_ca_root_test.go b/agent/cache-types/connect_ca_root_test.go index 74aa53c31a4c..7e02790ffc63 100644 --- a/agent/cache-types/connect_ca_root_test.go +++ b/agent/cache-types/connect_ca_root_test.go @@ -25,11 +25,11 @@ func TestConnectCARoot(t *testing.T) { rpc.On("RPC", mock.Anything, "ConnectCA.Roots", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.DCSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) reply := args.Get(3).(*structs.IndexedCARoots) - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/discovery_chain.go b/agent/cache-types/discovery_chain.go index e27b621061e1..2f2ef6623179 100644 --- a/agent/cache-types/discovery_chain.go +++ b/agent/cache-types/discovery_chain.go @@ -36,8 +36,8 @@ func (c *CompiledDiscoveryChain) Fetch(opts cache.FetchOptions, req cache.Reques reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and endup arbitrarily stale anyway. This @@ -52,6 +52,6 @@ func (c *CompiledDiscoveryChain) Fetch(opts cache.FetchOptions, req cache.Reques } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/discovery_chain_test.go b/agent/cache-types/discovery_chain_test.go index a9c9783e882b..e71ef662206e 100644 --- a/agent/cache-types/discovery_chain_test.go +++ b/agent/cache-types/discovery_chain_test.go @@ -28,13 +28,13 @@ func TestCompiledDiscoveryChain(t *testing.T) { rpc.On("RPC", mock.Anything, "DiscoveryChain.Get", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.DiscoveryChainRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) reply := args.Get(3).(*structs.DiscoveryChainResponse) reply.Chain = chain - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/exported_peered_services.go b/agent/cache-types/exported_peered_services.go index 69bd2d92ba71..b027368bbced 100644 --- a/agent/cache-types/exported_peered_services.go +++ b/agent/cache-types/exported_peered_services.go @@ -34,8 +34,8 @@ func (c *ExportedPeeredServices) Fetch(opts cache.FetchOptions, req cache.Reques reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -50,6 +50,6 @@ func (c *ExportedPeeredServices) Fetch(opts cache.FetchOptions, req cache.Reques } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/exported_peered_services_test.go b/agent/cache-types/exported_peered_services_test.go index a2d618bb60c5..a4c4675dbbe7 100644 --- a/agent/cache-types/exported_peered_services_test.go +++ b/agent/cache-types/exported_peered_services_test.go @@ -24,8 +24,8 @@ func TestExportedPeeredServices(t *testing.T) { rpc.On("RPC", mock.Anything, "Internal.ExportedPeeredServices", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.DCSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) reply := args.Get(3).(*structs.IndexedExportedServiceList) @@ -39,7 +39,7 @@ func TestExportedPeeredServices(t *testing.T) { }, }, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/federation_state_list_gateways.go b/agent/cache-types/federation_state_list_gateways.go index 501a8bcead28..0b112c97612f 100644 --- a/agent/cache-types/federation_state_list_gateways.go +++ b/agent/cache-types/federation_state_list_gateways.go @@ -35,8 +35,8 @@ func (c *FederationStateListMeshGateways) Fetch(opts cache.FetchOptions, req cac reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -51,6 +51,6 @@ func (c *FederationStateListMeshGateways) Fetch(opts cache.FetchOptions, req cac } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/federation_state_list_gateways_test.go b/agent/cache-types/federation_state_list_gateways_test.go index 04bd661e80fc..5718e19c7b09 100644 --- a/agent/cache-types/federation_state_list_gateways_test.go +++ b/agent/cache-types/federation_state_list_gateways_test.go @@ -25,8 +25,8 @@ func TestFederationStateListMeshGateways(t *testing.T) { rpc.On("RPC", mock.Anything, "FederationState.ListMeshGateways", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.DCSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) reply := args.Get(3).(*structs.DatacenterIndexedCheckServiceNodes) @@ -78,7 +78,7 @@ func TestFederationStateListMeshGateways(t *testing.T) { }, }, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/gateway_services.go b/agent/cache-types/gateway_services.go index 9c13800beeee..be4643bc5d45 100644 --- a/agent/cache-types/gateway_services.go +++ b/agent/cache-types/gateway_services.go @@ -35,8 +35,8 @@ func (g *GatewayServices) Fetch(opts cache.FetchOptions, req cache.Request) (cac reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -51,6 +51,6 @@ func (g *GatewayServices) Fetch(opts cache.FetchOptions, req cache.Request) (cac } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/gateway_services_test.go b/agent/cache-types/gateway_services_test.go index 49be4edf4780..2bb09e70c2bb 100644 --- a/agent/cache-types/gateway_services_test.go +++ b/agent/cache-types/gateway_services_test.go @@ -24,8 +24,8 @@ func TestGatewayServices(t *testing.T) { rpc.On("RPC", mock.Anything, "Catalog.GatewayServices", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) require.Equal(t, "foo", req.ServiceName) @@ -43,7 +43,7 @@ func TestGatewayServices(t *testing.T) { } reply := args.Get(3).(*structs.IndexedGatewayServices) reply.Services = services - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/health_services.go b/agent/cache-types/health_services.go index ae8369364743..e627d4410175 100644 --- a/agent/cache-types/health_services.go +++ b/agent/cache-types/health_services.go @@ -36,8 +36,8 @@ func (c *HealthServices) Fetch(opts cache.FetchOptions, req cache.Request) (cach reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and endup arbitrarily stale anyway. This @@ -52,6 +52,6 @@ func (c *HealthServices) Fetch(opts cache.FetchOptions, req cache.Request) (cach } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/health_services_test.go b/agent/cache-types/health_services_test.go index 6e83ec9a4018..8454a3d03a53 100644 --- a/agent/cache-types/health_services_test.go +++ b/agent/cache-types/health_services_test.go @@ -25,8 +25,8 @@ func TestHealthServices(t *testing.T) { rpc.On("RPC", mock.Anything, "Health.ServiceNodes", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.Equal(t, "web", req.ServiceName) require.True(t, req.AllowStale) @@ -34,7 +34,7 @@ func TestHealthServices(t *testing.T) { reply.Nodes = []structs.CheckServiceNode{ {Service: &structs.NodeService{Tags: req.ServiceTags}}, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/intention_upstreams.go b/agent/cache-types/intention_upstreams.go index a0e1ea0c0fd3..64773bbcbabd 100644 --- a/agent/cache-types/intention_upstreams.go +++ b/agent/cache-types/intention_upstreams.go @@ -35,8 +35,8 @@ func (i *IntentionUpstreams) Fetch(opts cache.FetchOptions, req cache.Request) ( reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -51,6 +51,6 @@ func (i *IntentionUpstreams) Fetch(opts cache.FetchOptions, req cache.Request) ( } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/intention_upstreams_destination.go b/agent/cache-types/intention_upstreams_destination.go index 1b5200a163c2..eda1325958e1 100644 --- a/agent/cache-types/intention_upstreams_destination.go +++ b/agent/cache-types/intention_upstreams_destination.go @@ -35,8 +35,8 @@ func (i *IntentionUpstreamsDestination) Fetch(opts cache.FetchOptions, req cache reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -51,6 +51,6 @@ func (i *IntentionUpstreamsDestination) Fetch(opts cache.FetchOptions, req cache } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/intention_upstreams_destination_test.go b/agent/cache-types/intention_upstreams_destination_test.go index 32852891846f..00b2dfa94146 100644 --- a/agent/cache-types/intention_upstreams_destination_test.go +++ b/agent/cache-types/intention_upstreams_destination_test.go @@ -24,8 +24,8 @@ func TestIntentionUpstreamsDestination(t *testing.T) { rpc.On("RPC", mock.Anything, "Internal.IntentionUpstreamsDestination", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) require.Equal(t, "foo", req.ServiceName) @@ -34,7 +34,7 @@ func TestIntentionUpstreamsDestination(t *testing.T) { } reply := args.Get(3).(*structs.IndexedServiceList) reply.Services = services - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/intention_upstreams_test.go b/agent/cache-types/intention_upstreams_test.go index 3259969f03a8..bb9cd185c4fa 100644 --- a/agent/cache-types/intention_upstreams_test.go +++ b/agent/cache-types/intention_upstreams_test.go @@ -24,8 +24,8 @@ func TestIntentionUpstreams(t *testing.T) { rpc.On("RPC", mock.Anything, "Internal.IntentionUpstreams", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) require.Equal(t, "foo", req.ServiceName) @@ -34,7 +34,7 @@ func TestIntentionUpstreams(t *testing.T) { } reply := args.Get(3).(*structs.IndexedServiceList) reply.Services = services - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/node_services.go b/agent/cache-types/node_services.go index 44dd5624f565..4e4e78ebed68 100644 --- a/agent/cache-types/node_services.go +++ b/agent/cache-types/node_services.go @@ -36,8 +36,8 @@ func (c *NodeServices) Fetch(opts cache.FetchOptions, req cache.Request) (cache. reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and endup arbitrarily stale anyway. This @@ -52,6 +52,6 @@ func (c *NodeServices) Fetch(opts cache.FetchOptions, req cache.Request) (cache. } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/node_services_test.go b/agent/cache-types/node_services_test.go index 6f16f93d5d61..ea62f6f81a12 100644 --- a/agent/cache-types/node_services_test.go +++ b/agent/cache-types/node_services_test.go @@ -25,8 +25,8 @@ func TestNodeServices(t *testing.T) { rpc.On("RPC", mock.Anything, "Catalog.NodeServices", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.NodeSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.Equal(t, "node-01", req.Node) require.True(t, req.AllowStale) @@ -40,7 +40,7 @@ func TestNodeServices(t *testing.T) { }, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/peered_upstreams.go b/agent/cache-types/peered_upstreams.go index 964b350eb150..096b7085ef8d 100644 --- a/agent/cache-types/peered_upstreams.go +++ b/agent/cache-types/peered_upstreams.go @@ -34,8 +34,8 @@ func (i *PeeredUpstreams) Fetch(opts cache.FetchOptions, req cache.Request) (cac reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -50,6 +50,6 @@ func (i *PeeredUpstreams) Fetch(opts cache.FetchOptions, req cache.Request) (cac } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/peered_upstreams_test.go b/agent/cache-types/peered_upstreams_test.go index 07be6e418808..e8862a703708 100644 --- a/agent/cache-types/peered_upstreams_test.go +++ b/agent/cache-types/peered_upstreams_test.go @@ -27,7 +27,7 @@ func TestPeeredUpstreams(t *testing.T) { Run(func(args mock.Arguments) { req := args.Get(2).(*structs.PartitionSpecificRequest) require.Equal(t, uint64(24), req.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) reply := args.Get(3).(*structs.IndexedPeeredServiceList) diff --git a/agent/cache-types/peerings.go b/agent/cache-types/peerings.go index 53138e5512d8..ab3cf126313e 100644 --- a/agent/cache-types/peerings.go +++ b/agent/cache-types/peerings.go @@ -83,13 +83,13 @@ func (t *Peerings) Fetch(opts cache.FetchOptions, req cache.Request) (cache.Fetc reqReal = &dup // Set the minimum query index to our current index, so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // We allow stale queries here to spread out the RPC load, but peerstream information, including the STATUS, // will not be returned. Right now this is fine for the watch in proxycfg/mesh_gateway.go, // but it could be a problem for a future consumer. - reqReal.QueryOptions.SetAllowStale(true) + reqReal.SetAllowStale(true) ctx, err := external.ContextWithQueryOptions(context.Background(), reqReal.QueryOptions) if err != nil { diff --git a/agent/cache-types/prepared_query.go b/agent/cache-types/prepared_query.go index 8a9ec7720959..07172f888327 100644 --- a/agent/cache-types/prepared_query.go +++ b/agent/cache-types/prepared_query.go @@ -48,7 +48,7 @@ func (c *PreparedQuery) Fetch(_ cache.FetchOptions, req cache.Request) (cache.Fe } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/prepared_query_test.go b/agent/cache-types/prepared_query_test.go index 50850c20fe9b..6eaf41e5d51d 100644 --- a/agent/cache-types/prepared_query_test.go +++ b/agent/cache-types/prepared_query_test.go @@ -29,7 +29,7 @@ func TestPreparedQuery(t *testing.T) { require.True(t, req.AllowStale) reply := args.Get(3).(*structs.PreparedQueryExecuteResponse) - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/resolved_service_config.go b/agent/cache-types/resolved_service_config.go index 76c333840f5d..f29ec98ceaef 100644 --- a/agent/cache-types/resolved_service_config.go +++ b/agent/cache-types/resolved_service_config.go @@ -36,8 +36,8 @@ func (c *ResolvedServiceConfig) Fetch(opts cache.FetchOptions, req cache.Request reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and endup arbitrarily stale anyway. This @@ -52,6 +52,6 @@ func (c *ResolvedServiceConfig) Fetch(opts cache.FetchOptions, req cache.Request } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/resolved_service_config_test.go b/agent/cache-types/resolved_service_config_test.go index a71cdb783436..b2018fcc488c 100644 --- a/agent/cache-types/resolved_service_config_test.go +++ b/agent/cache-types/resolved_service_config_test.go @@ -25,8 +25,8 @@ func TestResolvedServiceConfig(t *testing.T) { rpc.On("RPC", mock.Anything, "ConfigEntry.ResolveServiceConfig", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceConfigRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.Equal(t, "foo", req.Name) require.True(t, req.AllowStale) @@ -45,7 +45,7 @@ func TestResolvedServiceConfig(t *testing.T) { }, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/service_dump.go b/agent/cache-types/service_dump.go index 60c2895aff1f..a7f3820e446a 100644 --- a/agent/cache-types/service_dump.go +++ b/agent/cache-types/service_dump.go @@ -35,8 +35,8 @@ func (c *InternalServiceDump) Fetch(opts cache.FetchOptions, req cache.Request) reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -51,6 +51,6 @@ func (c *InternalServiceDump) Fetch(opts cache.FetchOptions, req cache.Request) } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/service_dump_test.go b/agent/cache-types/service_dump_test.go index 3570fc9720a1..809d160cabc2 100644 --- a/agent/cache-types/service_dump_test.go +++ b/agent/cache-types/service_dump_test.go @@ -24,15 +24,15 @@ func TestInternalServiceDump(t *testing.T) { rpc.On("RPC", mock.Anything, "Internal.ServiceDump", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceDumpRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) reply := args.Get(3).(*structs.IndexedNodesWithGateways) reply.Nodes = []structs.CheckServiceNode{ {Service: &structs.NodeService{Kind: req.ServiceKind, Service: "foo"}}, } - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/service_gateways.go b/agent/cache-types/service_gateways.go index a080fc77451c..cf55f9f7d343 100644 --- a/agent/cache-types/service_gateways.go +++ b/agent/cache-types/service_gateways.go @@ -35,8 +35,8 @@ func (g *ServiceGateways) Fetch(opts cache.FetchOptions, req cache.Request) (cac reqReal = &dup // Set the minimum query index to our current index so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This @@ -51,6 +51,6 @@ func (g *ServiceGateways) Fetch(opts cache.FetchOptions, req cache.Request) (cac } result.Value = &reply - result.Index = reply.QueryMeta.Index + result.Index = reply.Index return result, nil } diff --git a/agent/cache-types/service_gateways_test.go b/agent/cache-types/service_gateways_test.go index 9f615162b6fb..2e4941924e72 100644 --- a/agent/cache-types/service_gateways_test.go +++ b/agent/cache-types/service_gateways_test.go @@ -24,8 +24,8 @@ func TestServiceGateways(t *testing.T) { rpc.On("RPC", mock.Anything, "Internal.ServiceGateways", mock.Anything, mock.Anything).Return(nil). Run(func(args mock.Arguments) { req := args.Get(2).(*structs.ServiceSpecificRequest) - require.Equal(t, uint64(24), req.QueryOptions.MinQueryIndex) - require.Equal(t, 1*time.Second, req.QueryOptions.MaxQueryTime) + require.Equal(t, uint64(24), req.MinQueryIndex) + require.Equal(t, 1*time.Second, req.MaxQueryTime) require.True(t, req.AllowStale) require.Equal(t, "foo", req.ServiceName) @@ -39,7 +39,7 @@ func TestServiceGateways(t *testing.T) { reply := args.Get(3).(*structs.IndexedCheckServiceNodes) reply.Nodes = nodes - reply.QueryMeta.Index = 48 + reply.Index = 48 resp = reply }) diff --git a/agent/cache-types/trust_bundle.go b/agent/cache-types/trust_bundle.go index 0bac27e2b8c2..b42cb36d4fb8 100644 --- a/agent/cache-types/trust_bundle.go +++ b/agent/cache-types/trust_bundle.go @@ -83,14 +83,14 @@ func (t *TrustBundle) Fetch(opts cache.FetchOptions, req cache.Request) (cache.F reqReal = &dup // Set the minimum query index to our current index, so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This // allows cached service-discover to automatically read scale across all // servers too. - reqReal.QueryOptions.SetAllowStale(true) + reqReal.SetAllowStale(true) // Fetch ctx, err := external.ContextWithQueryOptions(context.Background(), reqReal.QueryOptions) diff --git a/agent/cache-types/trust_bundles.go b/agent/cache-types/trust_bundles.go index 7098c01af47a..17ff5d6517c2 100644 --- a/agent/cache-types/trust_bundles.go +++ b/agent/cache-types/trust_bundles.go @@ -87,14 +87,14 @@ func (t *TrustBundles) Fetch(opts cache.FetchOptions, req cache.Request) (cache. reqReal = &dup // Set the minimum query index to our current index, so we block - reqReal.QueryOptions.MinQueryIndex = opts.MinIndex - reqReal.QueryOptions.MaxQueryTime = opts.Timeout + reqReal.MinQueryIndex = opts.MinIndex + reqReal.MaxQueryTime = opts.Timeout // Always allow stale - there's no point in hitting leader if the request is // going to be served from cache and end up arbitrarily stale anyway. This // allows cached service-discover to automatically read scale across all // servers too. - reqReal.QueryOptions.SetAllowStale(true) + reqReal.SetAllowStale(true) // Fetch ctx, err := external.ContextWithQueryOptions(context.Background(), reqReal.QueryOptions) diff --git a/agent/checks/check_test.go b/agent/checks/check_test.go index e66673ad1f27..4bbac1edda3a 100644 --- a/agent/checks/check_test.go +++ b/agent/checks/check_test.go @@ -1129,7 +1129,7 @@ func TestStatusHandlerMaintainWarningStatusWhenCheckIsFlapping(t *testing.T) { func TestCheckTCPCritical(t *testing.T) { t.Parallel() - var tcpServer net.Listener = mockTCPServer(`tcp`) + var tcpServer = mockTCPServer(`tcp`) expectTCPStatus(t, `127.0.0.1:0`, api.HealthCritical) tcpServer.Close() } @@ -1204,7 +1204,6 @@ func mockUDPServer(ctx context.Context, network string, port int) { close(chClose) } wg.Wait() - return } func expectUDPStatus(t *testing.T, udp string, status string) { @@ -1314,7 +1313,7 @@ func TestCheckH2PING(t *testing.T) { for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return }) + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}) server := httptest.NewUnstartedServer(handler) server.EnableHTTP2 = true server.Config.ReadTimeout = tt.connTimeout diff --git a/agent/config/builder.go b/agent/config/builder.go index ccdb2454f481..396d0f9ec508 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -692,9 +692,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) { // autoEncrypt and autoConfig implicitly turns on connect which is why // they need to be above other settings that rely on connect. autoEncryptDNSSAN := []string{} - for _, d := range c.AutoEncrypt.DNSSAN { - autoEncryptDNSSAN = append(autoEncryptDNSSAN, d) - } + autoEncryptDNSSAN = append(autoEncryptDNSSAN, c.AutoEncrypt.DNSSAN...) autoEncryptIPSAN := []net.IP{} for _, i := range c.AutoEncrypt.IPSAN { ip := net.ParseIP(i) @@ -1257,7 +1255,7 @@ func (b *builder) validate(rt RuntimeConfig) error { } if rt.UIConfig.MetricsProxy.BaseURL != "" { u, err := url.Parse(rt.UIConfig.MetricsProxy.BaseURL) - if err != nil || !(u.Scheme == "http" || u.Scheme == "https") { + if err != nil || (u.Scheme != "http" && u.Scheme != "https") { return fmt.Errorf("ui_config.metrics_proxy.base_url must be a valid http"+ " or https URL. received: %q", rt.UIConfig.MetricsProxy.BaseURL) @@ -1273,7 +1271,7 @@ func (b *builder) validate(rt RuntimeConfig) error { return err } u, err := url.Parse(v) - if err != nil || !(u.Scheme == "http" || u.Scheme == "https") { + if err != nil || (u.Scheme != "http" && u.Scheme != "https") { return fmt.Errorf("ui_config.dashboard_url_templates values must be a"+ " valid http or https URL. received: %q", rt.UIConfig.MetricsProxy.BaseURL) @@ -1656,7 +1654,7 @@ func (b *builder) checkVal(v *CheckDefinition) *structs.CheckDefinition { OSService: stringVal(v.OSService), DeregisterCriticalServiceAfter: b.durationVal(fmt.Sprintf("check[%s].deregister_critical_service_after", id), v.DeregisterCriticalServiceAfter), OutputMaxSize: intValWithDefault(v.OutputMaxSize, checks.DefaultBufSize), - EnterpriseMeta: v.EnterpriseMeta.ToStructs(), + EnterpriseMeta: v.ToStructs(), } } @@ -1738,7 +1736,7 @@ func (b *builder) serviceVal(v *ServiceDefinition) *structs.ServiceDefinition { Proxy: b.serviceProxyVal(v.Proxy), Connect: b.serviceConnectVal(v.Connect), Locality: b.serviceLocalityVal(v.Locality), - EnterpriseMeta: v.EnterpriseMeta.ToStructs(), + EnterpriseMeta: v.ToStructs(), } } diff --git a/agent/config/deprecated.go b/agent/config/deprecated.go index 921e3329ffa6..c736c584623b 100644 --- a/agent/config/deprecated.go +++ b/agent/config/deprecated.go @@ -90,114 +90,114 @@ func applyDeprecatedConfig(d *decodeTarget) (Config, []string) { // TODO(boxofrad): The DeprecatedConfig struct only holds fields that were once // on the top-level Config struct (not nested fields e.g. ACL.Tokens) maybe we // should rethink this a bit? - if d.Config.ACL.Tokens.AgentMaster != nil { - if d.Config.ACL.Tokens.AgentRecovery == nil { - d.Config.ACL.Tokens.AgentRecovery = d.Config.ACL.Tokens.AgentMaster + if d.ACL.Tokens.AgentMaster != nil { + if d.ACL.Tokens.AgentRecovery == nil { + d.ACL.Tokens.AgentRecovery = d.ACL.Tokens.AgentMaster } warns = append(warns, deprecationWarning("acl.tokens.agent_master", "acl.tokens.agent_recovery")) } if dep.ACLAgentMasterToken != nil { - if d.Config.ACL.Tokens.AgentRecovery == nil { - d.Config.ACL.Tokens.AgentRecovery = dep.ACLAgentMasterToken + if d.ACL.Tokens.AgentRecovery == nil { + d.ACL.Tokens.AgentRecovery = dep.ACLAgentMasterToken } warns = append(warns, deprecationWarning("acl_agent_master_token", "acl.tokens.agent_recovery")) } if dep.ACLAgentToken != nil { - if d.Config.ACL.Tokens.Agent == nil { - d.Config.ACL.Tokens.Agent = dep.ACLAgentToken + if d.ACL.Tokens.Agent == nil { + d.ACL.Tokens.Agent = dep.ACLAgentToken } warns = append(warns, deprecationWarning("acl_agent_token", "acl.tokens.agent")) } if dep.ACLToken != nil { - if d.Config.ACL.Tokens.Default == nil { - d.Config.ACL.Tokens.Default = dep.ACLToken + if d.ACL.Tokens.Default == nil { + d.ACL.Tokens.Default = dep.ACLToken } warns = append(warns, deprecationWarning("acl_token", "acl.tokens.default")) } - if d.Config.ACL.Tokens.Master != nil { - if d.Config.ACL.Tokens.InitialManagement == nil { - d.Config.ACL.Tokens.InitialManagement = d.Config.ACL.Tokens.Master + if d.ACL.Tokens.Master != nil { + if d.ACL.Tokens.InitialManagement == nil { + d.ACL.Tokens.InitialManagement = d.ACL.Tokens.Master } warns = append(warns, deprecationWarning("acl.tokens.master", "acl.tokens.initial_management")) } if dep.ACLMasterToken != nil { - if d.Config.ACL.Tokens.InitialManagement == nil { - d.Config.ACL.Tokens.InitialManagement = dep.ACLMasterToken + if d.ACL.Tokens.InitialManagement == nil { + d.ACL.Tokens.InitialManagement = dep.ACLMasterToken } warns = append(warns, deprecationWarning("acl_master_token", "acl.tokens.initial_management")) } if dep.ACLReplicationToken != nil { - if d.Config.ACL.Tokens.Replication == nil { - d.Config.ACL.Tokens.Replication = dep.ACLReplicationToken + if d.ACL.Tokens.Replication == nil { + d.ACL.Tokens.Replication = dep.ACLReplicationToken } - d.Config.ACL.TokenReplication = pBool(true) + d.ACL.TokenReplication = pBool(true) warns = append(warns, deprecationWarning("acl_replication_token", "acl.tokens.replication")) } if dep.EnableACLReplication != nil { - if d.Config.ACL.TokenReplication == nil { - d.Config.ACL.TokenReplication = dep.EnableACLReplication + if d.ACL.TokenReplication == nil { + d.ACL.TokenReplication = dep.EnableACLReplication } warns = append(warns, deprecationWarning("enable_acl_replication", "acl.enable_token_replication")) } if dep.ACLDatacenter != nil { - if d.Config.PrimaryDatacenter == nil { - d.Config.PrimaryDatacenter = dep.ACLDatacenter + if d.PrimaryDatacenter == nil { + d.PrimaryDatacenter = dep.ACLDatacenter } // when the acl_datacenter config is used it implicitly enables acls - d.Config.ACL.Enabled = pBool(true) + d.ACL.Enabled = pBool(true) warns = append(warns, deprecationWarning("acl_datacenter", "primary_datacenter")) } if dep.ACLDefaultPolicy != nil { - if d.Config.ACL.DefaultPolicy == nil { - d.Config.ACL.DefaultPolicy = dep.ACLDefaultPolicy + if d.ACL.DefaultPolicy == nil { + d.ACL.DefaultPolicy = dep.ACLDefaultPolicy } warns = append(warns, deprecationWarning("acl_default_policy", "acl.default_policy")) } if dep.ACLDownPolicy != nil { - if d.Config.ACL.DownPolicy == nil { - d.Config.ACL.DownPolicy = dep.ACLDownPolicy + if d.ACL.DownPolicy == nil { + d.ACL.DownPolicy = dep.ACLDownPolicy } warns = append(warns, deprecationWarning("acl_down_policy", "acl.down_policy")) } if dep.ACLTTL != nil { - if d.Config.ACL.TokenTTL == nil { - d.Config.ACL.TokenTTL = dep.ACLTTL + if d.ACL.TokenTTL == nil { + d.ACL.TokenTTL = dep.ACLTTL } warns = append(warns, deprecationWarning("acl_ttl", "acl.token_ttl")) } if dep.ACLEnableKeyListPolicy != nil { - if d.Config.ACL.EnableKeyListPolicy == nil { - d.Config.ACL.EnableKeyListPolicy = dep.ACLEnableKeyListPolicy + if d.ACL.EnableKeyListPolicy == nil { + d.ACL.EnableKeyListPolicy = dep.ACLEnableKeyListPolicy } warns = append(warns, deprecationWarning("acl_enable_key_list_policy", "acl.enable_key_list_policy")) } if len(dep.StartJoinAddrsLAN) > 0 { - d.Config.RetryJoinLAN = append(d.Config.RetryJoinLAN, dep.StartJoinAddrsLAN...) + d.RetryJoinLAN = append(d.RetryJoinLAN, dep.StartJoinAddrsLAN...) warns = append(warns, deprecationWarning("start_join", "retry_join")) } if len(dep.StartJoinAddrsWAN) > 0 { - d.Config.RetryJoinWAN = append(d.Config.RetryJoinWAN, dep.StartJoinAddrsWAN...) + d.RetryJoinWAN = append(d.RetryJoinWAN, dep.StartJoinAddrsWAN...) warns = append(warns, deprecationWarning("start_join_wan", "retry_join_wan")) } if dep.RaftBoltDBConfig != nil { - if d.Config.RaftLogStore.BoltDBConfig.NoFreelistSync == nil { - d.Config.RaftLogStore.BoltDBConfig.NoFreelistSync = &dep.RaftBoltDBConfig.NoFreelistSync + if d.RaftLogStore.BoltDBConfig.NoFreelistSync == nil { + d.RaftLogStore.BoltDBConfig.NoFreelistSync = &dep.RaftBoltDBConfig.NoFreelistSync } warns = append(warns, deprecationWarning("raft_boltdb", "raft_logstore.boltdb")) } diff --git a/agent/config/deprecated_test.go b/agent/config/deprecated_test.go index 8d03e431f7af..a7390df68226 100644 --- a/agent/config/deprecated_test.go +++ b/agent/config/deprecated_test.go @@ -4,7 +4,6 @@ package config import ( - "fmt" "sort" "testing" "time" @@ -69,7 +68,7 @@ raft_boltdb { deprecationWarning("cert_file", "tls.defaults.cert_file"), deprecationWarning("key_file", "tls.defaults.key_file"), deprecationWarning("tls_cipher_suites", "tls.defaults.tls_cipher_suites"), - fmt.Sprintf("'tls_min_version' value 'tls11' is deprecated, please specify 'TLSv1_1' instead"), + "'tls_min_version' value 'tls11' is deprecated, please specify 'TLSv1_1' instead", deprecationWarning("tls_min_version", "tls.defaults.tls_min_version"), deprecationWarning("verify_incoming", "tls.defaults.verify_incoming"), deprecationWarning("verify_incoming_https", "tls.https.verify_incoming"), diff --git a/agent/config/file_watcher_test.go b/agent/config/file_watcher_test.go index f937d1401195..da288da403bc 100644 --- a/agent/config/file_watcher_test.go +++ b/agent/config/file_watcher_test.go @@ -408,7 +408,7 @@ func createTempConfigFile(t *testing.T, filename string) string { func randomStr(length int) string { const charset = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - var seededRand *rand.Rand = rand.New( + var seededRand = rand.New( rand.NewSource(time.Now().UnixNano())) b := make([]byte, length) for i := range b { diff --git a/agent/config/flags.go b/agent/config/flags.go index b56a162287c0..f7e777a7e560 100644 --- a/agent/config/flags.go +++ b/agent/config/flags.go @@ -107,12 +107,12 @@ func applyDeprecatedFlags(d *FlagValuesTarget) (Config, []string) { var warns []string if len(dep.StartJoinAddrsLAN) > 0 { - d.Config.RetryJoinLAN = append(d.Config.RetryJoinLAN, dep.StartJoinAddrsLAN...) + d.RetryJoinLAN = append(d.RetryJoinLAN, dep.StartJoinAddrsLAN...) warns = append(warns, deprecatedFlagWarning("-join", "-retry-join")) } if len(dep.StartJoinAddrsWAN) > 0 { - d.Config.RetryJoinWAN = append(d.Config.RetryJoinWAN, dep.StartJoinAddrsWAN...) + d.RetryJoinWAN = append(d.RetryJoinWAN, dep.StartJoinAddrsWAN...) warns = append(warns, deprecatedFlagWarning("-join-wan", "-retry-join-wan")) } return d.Config, warns diff --git a/agent/config_endpoint.go b/agent/config_endpoint.go index 73d755786b85..c0c3f54cc6e1 100644 --- a/agent/config_endpoint.go +++ b/agent/config_endpoint.go @@ -27,7 +27,7 @@ func (s *HTTPHandlers) Config(resp http.ResponseWriter, req *http.Request) (inte return s.configGet(resp, req) case "DELETE": - return s.configDelete(resp, req) + return s.configDelete(req) default: return nil, MethodNotAllowedError{req.Method, []string{"GET", "DELETE"}} @@ -85,7 +85,7 @@ func (s *HTTPHandlers) configGet(resp http.ResponseWriter, req *http.Request) (i } // configDelete deletes the given config entry. -func (s *HTTPHandlers) configDelete(resp http.ResponseWriter, req *http.Request) (interface{}, error) { +func (s *HTTPHandlers) configDelete(req *http.Request) (interface{}, error) { var args structs.ConfigEntryRequest s.parseDC(req, &args.Datacenter) s.parseToken(req, &args.Token) diff --git a/agent/configentry/merge_service_config.go b/agent/configentry/merge_service_config.go index d36c152105af..7bf402f77a05 100644 --- a/agent/configentry/merge_service_config.go +++ b/agent/configentry/merge_service_config.go @@ -168,7 +168,7 @@ func MergeServiceConfig(defaults *structs.ServiceConfigResponse, service *struct // If the defaults did not fully normalize tenancy stuff, take care of // that now too. psn := us.Upstream // only normalize the copy - psn.ServiceName.EnterpriseMeta.Normalize() + psn.ServiceName.Normalize() // Normalize the partition field specially. if psn.Peer != "" { diff --git a/agent/connect/ca/provider_aws_test.go b/agent/connect/ca/provider_aws_test.go index d46221af1fce..db96d3f71949 100644 --- a/agent/connect/ca/provider_aws_test.go +++ b/agent/connect/ca/provider_aws_test.go @@ -46,7 +46,7 @@ func TestAWSBootstrapAndSignPrimary(t *testing.T) { "PrivateKeyBits": tc.KeyBits, "RootCertTTL": "8761h", } - provider := testAWSProvider(t, testProviderConfigPrimary(t, cfg)) + provider := testAWSProvider(t, testProviderConfigPrimary(cfg)) defer provider.Cleanup(true, nil) rootPEM, err := provider.GenerateCAChain() @@ -72,7 +72,7 @@ func TestAWSBootstrapAndSignPrimary(t *testing.T) { } t.Run("Test default root ttl for aws ca provider", func(t *testing.T) { - provider := testAWSProvider(t, testProviderConfigPrimary(t, nil)) + provider := testAWSProvider(t, testProviderConfigPrimary(nil)) defer provider.Cleanup(true, nil) rootPEM, err := provider.GenerateCAChain() @@ -107,7 +107,7 @@ func TestAWSBootstrapAndSignSecondary(t *testing.T) { // all of these tests run at once. skipIfAWSNotConfigured(t) - p1 := testAWSProvider(t, testProviderConfigPrimary(t, nil)) + p1 := testAWSProvider(t, testProviderConfigPrimary(nil)) defer p1.Cleanup(true, nil) rootPEM, err := p1.GenerateCAChain() require.NoError(t, err) @@ -134,13 +134,13 @@ func TestAWSBootstrapAndSignSecondary(t *testing.T) { t.Log("Restarting Providers with State") // Create new provider instances - cfg1 := testProviderConfigPrimary(t, nil) + cfg1 := testProviderConfigPrimary(nil) cfg1.State = p1State p1 = testAWSProvider(t, cfg1) newRootPEM, err := p1.GenerateCAChain() require.NoError(t, err) - cfg2 := testProviderConfigPrimary(t, nil) + cfg2 := testProviderConfigPrimary(nil) cfg2.State = p2State p2 = testAWSProvider(t, cfg2) // Need call ActiveLeafSigningCert like leader would to trigger loading from PCA @@ -166,14 +166,14 @@ func TestAWSBootstrapAndSignSecondary(t *testing.T) { t.Log("Starting up Providers with ExistingARNs") // Create new provider instances with config - cfg1 := testProviderConfigPrimary(t, map[string]interface{}{ + cfg1 := testProviderConfigPrimary(map[string]interface{}{ "ExistingARN": p1State[AWSStateCAARNKey], }) p1 = testAWSProvider(t, cfg1) newRootPEM, err := p1.GenerateCAChain() require.NoError(t, err) - cfg2 := testProviderConfigPrimary(t, map[string]interface{}{ + cfg2 := testProviderConfigPrimary(map[string]interface{}{ "ExistingARN": p2State[AWSStateCAARNKey], }) cfg1.RawConfig["ExistingARN"] = p2State[AWSStateCAARNKey] @@ -239,7 +239,7 @@ func TestAWSBootstrapAndSignSecondaryConsul(t *testing.T) { }) t.Run("pri=aws,sec=consul", func(t *testing.T) { - p1 := testAWSProvider(t, testProviderConfigPrimary(t, nil)) + p1 := testAWSProvider(t, testProviderConfigPrimary(nil)) defer p1.Cleanup(true, nil) _, err := p1.GenerateCAChain() @@ -260,7 +260,7 @@ func TestAWSBootstrapAndSignSecondaryConsul(t *testing.T) { func TestAWSNoCrossSigning(t *testing.T) { skipIfAWSNotConfigured(t) - p1 := testAWSProvider(t, testProviderConfigPrimary(t, nil)) + p1 := testAWSProvider(t, testProviderConfigPrimary(nil)) defer p1.Cleanup(true, nil) // Don't bother initializing a PCA as that is slow and unnecessary for this // test @@ -318,7 +318,7 @@ func TestAWSProvider_Cleanup(t *testing.T) { t.Run("provider-change", func(t *testing.T) { // create a provider with the default config which will create the CA - p1Conf := testProviderConfigPrimary(t, nil) + p1Conf := testProviderConfigPrimary(nil) p1 := testAWSProvider(t, p1Conf) p1.GenerateCAChain() @@ -339,7 +339,7 @@ func TestAWSProvider_Cleanup(t *testing.T) { state, err := p1.State() require.NoError(t, err) - p2Conf := testProviderConfigPrimary(t, map[string]interface{}{ + p2Conf := testProviderConfigPrimary(map[string]interface{}{ "ExistingARN": state[AWSStateCAARNKey], }) p2 := testAWSProvider(t, p2Conf) @@ -352,7 +352,7 @@ func TestAWSProvider_Cleanup(t *testing.T) { t.Run("arn-change", func(t *testing.T) { // create a provider with the default config which will create the CA - p1Conf := testProviderConfigPrimary(t, nil) + p1Conf := testProviderConfigPrimary(nil) p1 := testAWSProvider(t, p1Conf) p1.GenerateCAChain() @@ -373,13 +373,13 @@ func TestAWSProvider_Cleanup(t *testing.T) { state, err := p1.State() require.NoError(t, err) - p2Conf := testProviderConfigPrimary(t, map[string]interface{}{ + p2Conf := testProviderConfigPrimary(map[string]interface{}{ "ExistingARN": state[AWSStateCAARNKey], }) p2 := testAWSProvider(t, p2Conf) // changing the ARN should cause the other CA to be deleted - p2ConfAltARN := testProviderConfigPrimary(t, map[string]interface{}{ + p2ConfAltARN := testProviderConfigPrimary(map[string]interface{}{ "ExistingARN": "doesnt-need-to-be-real", }) require.NoError(t, p2.Cleanup(false, p2ConfAltARN.RawConfig)) @@ -389,7 +389,7 @@ func TestAWSProvider_Cleanup(t *testing.T) { t.Run("arn-not-changed", func(t *testing.T) { // create a provider with the default config which will create the CA - p1Conf := testProviderConfigPrimary(t, nil) + p1Conf := testProviderConfigPrimary(nil) p1 := testAWSProvider(t, p1Conf) p1.GenerateCAChain() @@ -405,7 +405,7 @@ func TestAWSProvider_Cleanup(t *testing.T) { state, err := p1.State() require.NoError(t, err) - p2Conf := testProviderConfigPrimary(t, map[string]interface{}{ + p2Conf := testProviderConfigPrimary(map[string]interface{}{ "ExistingARN": state[AWSStateCAARNKey], }) p2 := testAWSProvider(t, p2Conf) @@ -423,7 +423,7 @@ func testAWSProvider(t *testing.T, cfg ProviderConfig) *AWSProvider { return p } -func testProviderConfigPrimary(t *testing.T, cfg map[string]interface{}) ProviderConfig { +func testProviderConfigPrimary(cfg map[string]interface{}) ProviderConfig { rawCfg := make(map[string]interface{}) for k, v := range cfg { rawCfg[k] = v @@ -438,7 +438,7 @@ func testProviderConfigPrimary(t *testing.T, cfg map[string]interface{}) Provide } func testProviderConfigSecondary(t *testing.T, cfg map[string]interface{}) ProviderConfig { - c := testProviderConfigPrimary(t, cfg) + c := testProviderConfigPrimary(cfg) c.IsPrimary = false c.Datacenter = "dc2" return c diff --git a/agent/dns.go b/agent/dns.go index b47483e8c268..f73766f7cfec 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -26,8 +26,7 @@ import ( "github.com/hashicorp/consul/agent/config" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/api" - dnsutil "github.com/hashicorp/consul/internal/dnsutil" - libdns "github.com/hashicorp/consul/internal/dnsutil" + "github.com/hashicorp/consul/internal/dnsutil" "github.com/hashicorp/consul/ipaddr" "github.com/hashicorp/consul/lib" "github.com/hashicorp/consul/logging" @@ -467,7 +466,7 @@ func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) { // only look into the services if we didn't find a node if len(m.Answer) == 0 { // lookup the service address - ip := libdns.IPFromARPA(qName) + ip := dnsutil.IPFromARPA(qName) var serviceAddress string if ip != nil { serviceAddress = ip.String() @@ -650,7 +649,7 @@ func (d *DNSServer) getNameserversAndNodeRecord(questionName string, cfg *dnsReq for _, o := range out.Nodes { name, dc := o.Node.Node, o.Node.Datacenter - if libdns.InvalidNameRe.MatchString(name) { + if dnsutil.InvalidNameRe.MatchString(name) { d.logger.Warn("Skipping invalid node for NS records", "node", name) continue } diff --git a/agent/grpc-external/services/dataplane/get_envoy_bootstrap_params_test.go b/agent/grpc-external/services/dataplane/get_envoy_bootstrap_params_test.go index 5178db55363f..4b3971b9ed2a 100644 --- a/agent/grpc-external/services/dataplane/get_envoy_bootstrap_params_test.go +++ b/agent/grpc-external/services/dataplane/get_envoy_bootstrap_params_test.go @@ -46,7 +46,7 @@ const ( testAccessLogs = "{\"name\":\"Consul Listener Filter Log\",\"typedConfig\":{\"@type\":\"type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog\",\"logFormat\":{\"jsonFormat\":{\"custom_field\":\"%START_TIME%\"}}}}" ) -func testRegisterRequestProxy(t *testing.T) *structs.RegisterRequest { +func testRegisterRequestProxy() *structs.RegisterRequest { return &structs.RegisterRequest{ Datacenter: serverDC, Node: nodeName, @@ -79,7 +79,7 @@ func testRegisterIngressGateway(t *testing.T) *structs.RegisterRequest { return registerReq } -func testProxyDefaults(t *testing.T, accesslogs bool) structs.ConfigEntry { +func testProxyDefaults(accesslogs bool) structs.ConfigEntry { pd := &structs.ProxyConfigEntry{ Kind: structs.ProxyDefaults, Name: structs.ProxyConfigGlobal, @@ -95,7 +95,7 @@ func testProxyDefaults(t *testing.T, accesslogs bool) structs.ConfigEntry { return pd } -func testServiceDefaults(t *testing.T) structs.ConfigEntry { +func testServiceDefaults() structs.ConfigEntry { return &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, Name: testServiceName, @@ -198,11 +198,11 @@ func TestGetEnvoyBootstrapParams_Success(t *testing.T) { testCases := []testCase{ { name: "lookup service sidecar proxy by node name", - registerReq: testRegisterRequestProxy(t), + registerReq: testRegisterRequestProxy(), }, { name: "lookup service sidecar proxy by node ID", - registerReq: testRegisterRequestProxy(t), + registerReq: testRegisterRequestProxy(), nodeID: true, }, { @@ -216,23 +216,23 @@ func TestGetEnvoyBootstrapParams_Success(t *testing.T) { }, { name: "merge proxy defaults for sidecar proxy", - registerReq: testRegisterRequestProxy(t), - proxyDefaults: testProxyDefaults(t, false), + registerReq: testRegisterRequestProxy(), + proxyDefaults: testProxyDefaults(false), }, { name: "proxy defaults access logs", - registerReq: testRegisterRequestProxy(t), - proxyDefaults: testProxyDefaults(t, true), + registerReq: testRegisterRequestProxy(), + proxyDefaults: testProxyDefaults(true), }, { name: "merge service defaults for sidecar proxy", - registerReq: testRegisterRequestProxy(t), - serviceDefaults: testServiceDefaults(t), + registerReq: testRegisterRequestProxy(), + serviceDefaults: testServiceDefaults(), }, { name: "merge proxy defaults and service defaults for sidecar proxy", - registerReq: testRegisterRequestProxy(t), - serviceDefaults: testServiceDefaults(t), + registerReq: testRegisterRequestProxy(), + serviceDefaults: testServiceDefaults(), }, } @@ -262,7 +262,7 @@ func TestGetEnvoyBootstrapParams_Error(t *testing.T) { require.NoError(t, err) store := testutils.TestStateStore(t, nil) - registerReq := testRegisterRequestProxy(t) + registerReq := testRegisterRequestProxy() err = store.EnsureRegistration(1, registerReq) require.NoError(t, err) diff --git a/agent/grpc-external/services/peerstream/replication.go b/agent/grpc-external/services/peerstream/replication.go index 692a475235be..9a0d865f719e 100644 --- a/agent/grpc-external/services/peerstream/replication.go +++ b/agent/grpc-external/services/peerstream/replication.go @@ -10,7 +10,6 @@ import ( "google.golang.org/genproto/googleapis/rpc/code" "google.golang.org/protobuf/proto" - newproto "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" "github.com/hashicorp/consul/acl" @@ -127,7 +126,7 @@ func makeServerAddrsResponse( // the protobuf.Any type, the asserted T type, and any errors // during marshalling or type assertion. // `in` MUST be of type T or it returns an error. -func marshalToProtoAny[T newproto.Message](in any) (*anypb.Any, T, error) { +func marshalToProtoAny[T proto.Message](in any) (*anypb.Any, T, error) { typ, ok := in.(T) if !ok { var outType T diff --git a/agent/grpc-external/services/peerstream/stream_test.go b/agent/grpc-external/services/peerstream/stream_test.go index 37e5e99a76f7..a9abc7c8395a 100644 --- a/agent/grpc-external/services/peerstream/stream_test.go +++ b/agent/grpc-external/services/peerstream/stream_test.go @@ -21,7 +21,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" - newproto "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" "github.com/hashicorp/consul/acl" @@ -1852,7 +1851,7 @@ func writeInitialRootsAndCA(t *testing.T, store *state.Store) (string, *structs. return clusterID, rootA } -func makeAnyPB(t *testing.T, pb newproto.Message) *anypb.Any { +func makeAnyPB(t *testing.T, pb proto.Message) *anypb.Any { any, err := anypb.New(pb) require.NoError(t, err) return any diff --git a/agent/grpc-external/services/resource/mutate_and_validate_test.go b/agent/grpc-external/services/resource/mutate_and_validate_test.go index 6644f108d402..7f7ca74bb209 100644 --- a/agent/grpc-external/services/resource/mutate_and_validate_test.go +++ b/agent/grpc-external/services/resource/mutate_and_validate_test.go @@ -64,7 +64,7 @@ func TestMutateAndValidate_OwnerValidation(t *testing.T) { WithRegisterFns(demo.RegisterTypes). Run(t) - for desc, tc := range ownerValidationTestCases(t) { + for desc, tc := range ownerValidationTestCases() { t.Run(desc, func(t *testing.T) { run(t, client, tc) }) @@ -100,7 +100,7 @@ func TestMutateAndValidate_Success(t *testing.T) { WithRegisterFns(demo.RegisterTypes). Run(t) - for desc, tc := range mavOrWriteSuccessTestCases(t) { + for desc, tc := range mavOrWriteSuccessTestCases() { t.Run(desc, func(t *testing.T) { run(t, client, tc) }) @@ -133,7 +133,7 @@ func TestMutateAndValidate_Mutate(t *testing.T) { } func TestMutateAndValidate_TenancyMarkedForDeletion_Fails(t *testing.T) { - for desc, tc := range mavOrWriteTenancyMarkedForDeletionTestCases(t) { + for desc, tc := range mavOrWriteTenancyMarkedForDeletionTestCases() { t.Run(desc, func(t *testing.T) { server := testServer(t) client := testClient(t, server) diff --git a/agent/grpc-external/services/resource/write_mav_common_test.go b/agent/grpc-external/services/resource/write_mav_common_test.go index 6b6a82b44e9f..d8925b67d6bc 100644 --- a/agent/grpc-external/services/resource/write_mav_common_test.go +++ b/agent/grpc-external/services/resource/write_mav_common_test.go @@ -130,7 +130,7 @@ type ownerValidTestCase struct { errorContains string } -func ownerValidationTestCases(t *testing.T) map[string]ownerValidTestCase { +func ownerValidationTestCases() map[string]ownerValidTestCase { return map[string]ownerValidTestCase{ "no owner type": { modFn: func(res *pbresource.Resource) { res.Owner.Type = nil }, @@ -184,7 +184,7 @@ type mavOrWriteSuccessTestCase struct { } // Test case struct shared by MutateAndValidate and Write success test cases -func mavOrWriteSuccessTestCases(t *testing.T) map[string]mavOrWriteSuccessTestCase { +func mavOrWriteSuccessTestCases() map[string]mavOrWriteSuccessTestCase { return map[string]mavOrWriteSuccessTestCase{ "namespaced resource provides nonempty partition and namespace": { modFn: func(artist, _ *pbresource.Resource) *pbresource.Resource { @@ -251,42 +251,12 @@ type mavOrWriteTenancyNotFoundTestCase map[string]struct { errContains string } -// Test case struct shared by MutateAndValidate and Write test cases where tenancy is not found -func mavOrWriteTenancyNotFoundTestCases(t *testing.T) mavOrWriteTenancyNotFoundTestCase { - return mavOrWriteTenancyNotFoundTestCase{ - "namespaced resource provides nonexistant partition": { - modFn: func(artist, _ *pbresource.Resource) *pbresource.Resource { - artist.Id.Tenancy.Partition = "boguspartition" - return artist - }, - errCode: codes.InvalidArgument, - errContains: "partition not found", - }, - "namespaced resource provides nonexistant namespace": { - modFn: func(artist, _ *pbresource.Resource) *pbresource.Resource { - artist.Id.Tenancy.Namespace = "bogusnamespace" - return artist - }, - errCode: codes.InvalidArgument, - errContains: "namespace not found", - }, - "partitioned resource provides nonexistant partition": { - modFn: func(_, recordLabel *pbresource.Resource) *pbresource.Resource { - recordLabel.Id.Tenancy.Partition = "boguspartition" - return recordLabel - }, - errCode: codes.InvalidArgument, - errContains: "partition not found", - }, - } -} - type mavOrWriteTenancyMarkedForDeletionTestCase struct { modFn func(artist, recordLabel *pbresource.Resource, mockTenancyBridge *svc.MockTenancyBridge) *pbresource.Resource errContains string } -func mavOrWriteTenancyMarkedForDeletionTestCases(t *testing.T) map[string]mavOrWriteTenancyMarkedForDeletionTestCase { +func mavOrWriteTenancyMarkedForDeletionTestCases() map[string]mavOrWriteTenancyMarkedForDeletionTestCase { return map[string]mavOrWriteTenancyMarkedForDeletionTestCase{ "namespaced resources partition marked for deletion": { modFn: func(artist, _ *pbresource.Resource, mockTenancyBridge *svc.MockTenancyBridge) *pbresource.Resource { diff --git a/agent/grpc-external/services/resource/write_status.go b/agent/grpc-external/services/resource/write_status.go index fc209cd91252..f092c5f49d1b 100644 --- a/agent/grpc-external/services/resource/write_status.go +++ b/agent/grpc-external/services/resource/write_status.go @@ -144,13 +144,10 @@ func (s *Server) validateWriteStatusRequest(req *pbresource.WriteStatusRequest) switch { case condition.Resource.Type == nil: field = fmt.Sprintf("status.conditions[%d].resource.type", i) - break case condition.Resource.Tenancy == nil: field = fmt.Sprintf("status.conditions[%d].resource.tenancy", i) - break case condition.Resource.Name == "": field = fmt.Sprintf("status.conditions[%d].resource.name", i) - break } } } diff --git a/agent/grpc-external/services/resource/write_test.go b/agent/grpc-external/services/resource/write_test.go index c14aaad0e1eb..4a34d3e6bfaa 100644 --- a/agent/grpc-external/services/resource/write_test.go +++ b/agent/grpc-external/services/resource/write_test.go @@ -51,7 +51,7 @@ func TestWrite_OwnerValidation(t *testing.T) { WithRegisterFns(demo.RegisterTypes). Run(t) - testCases := ownerValidationTestCases(t) + testCases := ownerValidationTestCases() // This is not part of ownerValidationTestCases because it is a special case // that only gets caught deeper into the write path. @@ -158,7 +158,7 @@ func TestWrite_Mutate(t *testing.T) { } func TestWrite_Create_Success(t *testing.T) { - for desc, tc := range mavOrWriteSuccessTestCases(t) { + for desc, tc := range mavOrWriteSuccessTestCases() { t.Run(desc, func(t *testing.T) { client := svctest.NewResourceServiceBuilder(). WithRegisterFns(demo.RegisterTypes). @@ -181,7 +181,7 @@ func TestWrite_Create_Success(t *testing.T) { } func TestWrite_Create_With_TenancyMarkedForDeletion_Fails(t *testing.T) { - for desc, tc := range mavOrWriteTenancyMarkedForDeletionTestCases(t) { + for desc, tc := range mavOrWriteTenancyMarkedForDeletionTestCases() { t.Run(desc, func(t *testing.T) { server := testServer(t) client := testClient(t, server) diff --git a/agent/grpc-internal/services/subscribe/subscribe_test.go b/agent/grpc-internal/services/subscribe/subscribe_test.go index a574da3fa825..b39adbc32fa2 100644 --- a/agent/grpc-internal/services/subscribe/subscribe_test.go +++ b/agent/grpc-internal/services/subscribe/subscribe_test.go @@ -120,7 +120,7 @@ func TestServer_Subscribe_IntegrationWithBackend(t *testing.T) { require.NoError(t, err) t.Cleanup(logError(t, conn.Close)) - chEvents := make(chan eventOrError, 0) + chEvents := make(chan eventOrError) var snapshotEvents []*pbsubscribe.Event testutil.RunStep(t, "setup a client and subscribe to a topic", func(t *testing.T) { @@ -535,7 +535,7 @@ func TestServer_Subscribe_IntegrationWithBackend_ForwardToDC(t *testing.T) { require.NoError(t, err) t.Cleanup(logError(t, connLocal.Close)) - chEvents := make(chan eventOrError, 0) + chEvents := make(chan eventOrError) var snapshotEvents []*pbsubscribe.Event testutil.RunStep(t, "setup a client and subscribe to a topic", func(t *testing.T) { @@ -801,7 +801,7 @@ node "node1" { t.Cleanup(logError(t, conn.Close)) streamClient := pbsubscribe.NewStateChangeSubscriptionClient(conn) - chEvents := make(chan eventOrError, 0) + chEvents := make(chan eventOrError) testutil.RunStep(t, "setup a client, subscribe to a topic, and receive a snapshot", func(t *testing.T) { streamHandle, err := streamClient.Subscribe(ctx, &pbsubscribe.SubscribeRequest{ @@ -888,7 +888,7 @@ node "node1" { }) require.NoError(t, err) - chEvents := make(chan eventOrError, 0) + chEvents := make(chan eventOrError) go recvEvents(chEvents, streamHandle) require.True(t, getEvent(t, chEvents).GetEndOfSnapshot()) @@ -953,7 +953,7 @@ node "node1" { require.NoError(t, err) t.Cleanup(logError(t, conn.Close)) - chEvents := make(chan eventOrError, 0) + chEvents := make(chan eventOrError) testutil.RunStep(t, "setup a client and subscribe to a topic", func(t *testing.T) { streamClient := pbsubscribe.NewStateChangeSubscriptionClient(conn) @@ -993,7 +993,7 @@ node "node1" { }) // Re-subscribe because the previous test step terminated the stream. - chEvents = make(chan eventOrError, 0) + chEvents = make(chan eventOrError) streamClient := pbsubscribe.NewStateChangeSubscriptionClient(conn) streamHandle, err := streamClient.Subscribe(ctx, &pbsubscribe.SubscribeRequest{ Topic: pbsubscribe.Topic_ServiceHealth, diff --git a/agent/hcp/testing.go b/agent/hcp/testing.go index 11f3ac0d7299..c4f7770f1a73 100644 --- a/agent/hcp/testing.go +++ b/agent/hcp/testing.go @@ -70,7 +70,7 @@ func (s *MockHCPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { } matches := basePathRe.FindStringSubmatch(r.URL.Path) - if matches == nil || len(matches) < 5 { + if len(matches) < 5 { w.WriteHeader(404) log.Printf("ERROR 404: %s %s\n", r.Method, r.URL.Path) return diff --git a/agent/http.go b/agent/http.go index 077059991bc8..fe0e90d4741e 100644 --- a/agent/http.go +++ b/agent/http.go @@ -1040,14 +1040,6 @@ func (s *HTTPHandlers) parseConsistency(resp http.ResponseWriter, req *http.Requ return false } -// parseConsistencyReadRequest is used to parse the ?consistent query param. -func parseConsistencyReadRequest(resp http.ResponseWriter, req *http.Request, b *pbcommon.ReadRequest) { - query := req.URL.Query() - if _, ok := query["consistent"]; ok { - b.RequireConsistent = true - } -} - // parseDC is used to parse the datacenter from the query params. // ?datacenter has precedence over ?dc. func (s *HTTPHandlers) parseDC(req *http.Request, dc *string) { @@ -1073,7 +1065,6 @@ func (s *HTTPHandlers) parseTokenInternal(req *http.Request, token *string) { } *token = "" - return } func (s *HTTPHandlers) parseTokenFromHeaders(req *http.Request, token *string) bool { @@ -1119,9 +1110,7 @@ func (s *HTTPHandlers) parseTokenWithDefault(req *http.Request, token *string) { s.parseTokenInternal(req, token) // parseTokenInternal modifies *token if token != nil && *token == "" { *token = s.agent.tokens.UserToken() - return } - return } // parseToken is used to parse the ?token query param or the X-Consul-Token header or diff --git a/agent/leafcert/leafcert_test.go b/agent/leafcert/leafcert_test.go index f23ecfef62f9..3b8926cff3a3 100644 --- a/agent/leafcert/leafcert_test.go +++ b/agent/leafcert/leafcert_test.go @@ -43,7 +43,7 @@ func TestManager_changingRoots(t *testing.T) { } // First fetch should return immediately - getCh := testAsyncGet(t, m, req) + getCh := testAsyncGet(m, req) var idx uint64 select { case <-time.After(100 * time.Millisecond): @@ -59,7 +59,7 @@ func TestManager_changingRoots(t *testing.T) { // Second fetch should block with set index req.MinQueryIndex = idx - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case result := <-getCh: t.Fatalf("should not return: %#v", result) @@ -80,7 +80,7 @@ func TestManager_changingRoots(t *testing.T) { } // Third fetch should block - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case result := <-getCh: t.Fatalf("should not return: %#v", result) @@ -119,7 +119,7 @@ func TestManager_changingRootsJitterBetweenCalls(t *testing.T) { } // First fetch should return immediately - getCh := testAsyncGet(t, m, req) + getCh := testAsyncGet(m, req) var ( idx uint64 issued *structs.IssuedCert @@ -160,7 +160,7 @@ func TestManager_changingRootsJitterBetweenCalls(t *testing.T) { rootsDelivered := false for rootsDelivered { start := time.Now() - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case result := <-getCh: require.NoError(t, result.Err) @@ -236,7 +236,7 @@ func TestManager_changingRootsBetweenBlockingCalls(t *testing.T) { } // First fetch should return immediately - getCh := testAsyncGet(t, m, req) + getCh := testAsyncGet(m, req) var ( idx uint64 issued *structs.IssuedCert @@ -255,7 +255,7 @@ func TestManager_changingRootsBetweenBlockingCalls(t *testing.T) { // Next fetch should block for the full timeout start := time.Now() - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case <-time.After(100 * time.Millisecond): t.Fatal("shouldn't block for too long waiting for fetch") @@ -274,7 +274,7 @@ func TestManager_changingRootsBetweenBlockingCalls(t *testing.T) { // We should get the new cert immediately on next fetch (since test override // root change jitter to be 1 nanosecond so no delay expected). - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case <-time.After(100 * time.Millisecond): t.Fatal("shouldn't block too long waiting for fetch") @@ -324,7 +324,7 @@ func TestManager_CSRRateLimiting(t *testing.T) { // First fetch should return rate limit error directly - client is expected to // backoff itself. - getCh := testAsyncGet(t, m, req) + getCh := testAsyncGet(m, req) select { case <-time.After(200 * time.Millisecond): t.Fatal("shouldn't block longer than one jitter window for success") @@ -334,7 +334,7 @@ func TestManager_CSRRateLimiting(t *testing.T) { } // Second call should return correct cert immediately. - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) var ( idx uint64 issued *structs.IssuedCert @@ -361,7 +361,7 @@ func TestManager_CSRRateLimiting(t *testing.T) { // After root rotation jitter has been waited out, a new CSR will // be attempted but will fail and return the previous cached result with no // error since we will try again soon. - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case <-time.After(200 * time.Millisecond): t.Fatal("shouldn't block too long waiting for fetch") @@ -382,7 +382,7 @@ func TestManager_CSRRateLimiting(t *testing.T) { // Root rotation state is now only captured in the opts.LastResult.State so a // subsequent call should also wait for 100ms and then attempt to generate a // new cert since we failed last time. - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case <-time.After(200 * time.Millisecond): t.Fatal("shouldn't block too long waiting for fetch") @@ -402,7 +402,7 @@ func TestManager_CSRRateLimiting(t *testing.T) { // across both the blocking request that observed the rotation and the // subsequent one. The next request should wait out the rest of the backoff // and then actually fetch a new cert at last! - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case <-time.After(200 * time.Millisecond): t.Fatal("shouldn't block too long waiting for fetch") @@ -455,7 +455,7 @@ func TestManager_watchRootsDedupingMultipleCallers(t *testing.T) { } // First fetch should return immediately - getCh := testAsyncGet(t, m, req) + getCh := testAsyncGet(m, req) var idx uint64 select { case <-time.After(100 * time.Millisecond): @@ -468,7 +468,7 @@ func TestManager_watchRootsDedupingMultipleCallers(t *testing.T) { // Second fetch should block with set index req.MinQueryIndex = idx - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case result := <-getCh: setupDoneCh <- fmt.Errorf("should not return: %#v", result) @@ -591,7 +591,7 @@ func TestManager_expiringLeaf(t *testing.T) { } // First fetch should return immediately - getCh := testAsyncGet(t, m, req) + getCh := testAsyncGet(m, req) var ( idx uint64 issued *structs.IssuedCert @@ -609,7 +609,7 @@ func TestManager_expiringLeaf(t *testing.T) { // Second fetch should return immediately despite there being // no updated CA roots, because we issued an expired cert. - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case <-time.After(100 * time.Millisecond): t.Fatal("shouldn't block waiting for fetch") @@ -624,7 +624,7 @@ func TestManager_expiringLeaf(t *testing.T) { // Third fetch should block since the cert is not expiring and // we also didn't update CA certs. req.MinQueryIndex = idx - getCh = testAsyncGet(t, m, req) + getCh = testAsyncGet(m, req) select { case result := <-getCh: t.Fatalf("should not return: %#v", result) @@ -1027,7 +1027,7 @@ type testGetResult struct { // testAsyncGet returns a channel that returns the result of the testGet call. // // This is useful for testing timing and concurrency with testGet calls. -func testAsyncGet(t *testing.T, m *Manager, req *ConnectCALeafRequest) <-chan testGetResult { +func testAsyncGet(m *Manager, req *ConnectCALeafRequest) <-chan testGetResult { ch := make(chan testGetResult) go func() { index, cert, err := m.testGet(req) diff --git a/agent/metrics_test.go b/agent/metrics_test.go index 07ceaa8f8033..6d04499c53c4 100644 --- a/agent/metrics_test.go +++ b/agent/metrics_test.go @@ -20,7 +20,6 @@ import ( "github.com/hashicorp/consul/agent/rpc/middleware" "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil/retry" - testretry "github.com/hashicorp/consul/sdk/testutil/retry" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/consul/tlsutil" ) @@ -273,7 +272,7 @@ func TestHTTPHandlers_AgentMetrics_LeaderShipMetrics(t *testing.T) { defer s3.Shutdown() // agent hasn't become a leader - retry.RunWith(retry.ThirtySeconds(), t, func(r *testretry.R) { + retry.RunWith(retry.ThirtySeconds(), t, func(r *retry.R) { respRec := httptest.NewRecorder() recordPromMetrics(r, s1, respRec) found := strings.Contains(respRec.Body.String(), metricsPrefix1+"_server_isLeader 0") @@ -290,7 +289,7 @@ func TestHTTPHandlers_AgentMetrics_LeaderShipMetrics(t *testing.T) { testrpc.WaitForLeader(t, s3.RPC, "dc1") // Verify agent's isLeader metrics is 1 - retry.RunWith(retry.ThirtySeconds(), t, func(r *testretry.R) { + retry.RunWith(retry.ThirtySeconds(), t, func(r *retry.R) { respRec1 := httptest.NewRecorder() recordPromMetrics(r, s1, respRec1) found1 := strings.Contains(respRec1.Body.String(), metricsPrefix1+"_server_isLeader 1") @@ -518,7 +517,7 @@ func TestHTTPHandlers_AgentMetrics_WAL_Prometheus(t *testing.T) { defer a.Shutdown() testrpc.WaitForLeader(t, a.RPC, "dc1") - testretry.Run(t, func(r *testretry.R) { + retry.Run(t, func(r *retry.R) { respRec := httptest.NewRecorder() recordPromMetrics(r, a, respRec) @@ -624,7 +623,7 @@ func TestHTTPHandlers_AgentMetrics_LogVerifier_Prometheus(t *testing.T) { defer a.Shutdown() testrpc.WaitForLeader(t, a.RPC, "dc1") - testretry.Run(t, func(r *testretry.R) { + retry.Run(t, func(r *retry.R) { respRec := httptest.NewRecorder() recordPromMetrics(r, a, respRec) diff --git a/agent/notify_test.go b/agent/notify_test.go index f256ee319ce7..0624cdb8a5db 100644 --- a/agent/notify_test.go +++ b/agent/notify_test.go @@ -10,7 +10,7 @@ import ( // Used to be defined in NotifyGroup.WaitCh but was only used in tests and prone // to leaking memory if anything real did use it because there is no way to // clear the chan later. -func testWaitCh(t *testing.T, grp *NotifyGroup) chan struct{} { +func testWaitCh(grp *NotifyGroup) chan struct{} { ch := make(chan struct{}, 1) grp.Wait(ch) return ch @@ -19,8 +19,8 @@ func testWaitCh(t *testing.T, grp *NotifyGroup) chan struct{} { func TestNotifyGroup(t *testing.T) { grp := &NotifyGroup{} - ch1 := testWaitCh(t, grp) - ch2 := testWaitCh(t, grp) + ch1 := testWaitCh(grp) + ch2 := testWaitCh(grp) select { case <-ch1: @@ -47,7 +47,7 @@ func TestNotifyGroup(t *testing.T) { } // Should be unregistered - ch3 := testWaitCh(t, grp) + ch3 := testWaitCh(grp) grp.Notify() select { @@ -70,7 +70,7 @@ func TestNotifyGroup(t *testing.T) { func TestNotifyGroup_Clear(t *testing.T) { grp := &NotifyGroup{} - ch1 := testWaitCh(t, grp) + ch1 := testWaitCh(grp) grp.Clear(ch1) grp.Notify() diff --git a/agent/peering_endpoint.go b/agent/peering_endpoint.go index 2d5cab92be2e..f37a0ebd1b95 100644 --- a/agent/peering_endpoint.go +++ b/agent/peering_endpoint.go @@ -31,7 +31,7 @@ func (s *HTTPHandlers) PeeringEndpoint(resp http.ResponseWriter, req *http.Reque case "GET": return s.peeringRead(resp, req, name) case "DELETE": - return s.peeringDelete(resp, req, name) + return s.peeringDelete(req, name) default: return nil, MethodNotAllowedError{req.Method, []string{"GET", "DELETE"}} } @@ -201,7 +201,7 @@ func (s *HTTPHandlers) PeeringEstablish(resp http.ResponseWriter, req *http.Requ // peeringDelete initiates a deletion for a peering that matches the name and partition. // This assumes that the name and partition parameters are valid. -func (s *HTTPHandlers) peeringDelete(resp http.ResponseWriter, req *http.Request, name string) (interface{}, error) { +func (s *HTTPHandlers) peeringDelete(req *http.Request, name string) (interface{}, error) { var entMeta acl.EnterpriseMeta if err := s.parseEntMetaPartition(req, &entMeta); err != nil { return nil, err diff --git a/agent/prepared_query_endpoint.go b/agent/prepared_query_endpoint.go index 08f7dca06cb1..2c8de775440a 100644 --- a/agent/prepared_query_endpoint.go +++ b/agent/prepared_query_endpoint.go @@ -243,7 +243,7 @@ RETRY_ONCE: } // preparedQueryUpdate updates a prepared query. -func (s *HTTPHandlers) preparedQueryUpdate(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) { +func (s *HTTPHandlers) preparedQueryUpdate(id string, req *http.Request) (interface{}, error) { args := structs.PreparedQueryRequest{ Op: structs.PreparedQueryUpdate, } @@ -270,7 +270,7 @@ func (s *HTTPHandlers) preparedQueryUpdate(id string, resp http.ResponseWriter, } // preparedQueryDelete deletes prepared query. -func (s *HTTPHandlers) preparedQueryDelete(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) { +func (s *HTTPHandlers) preparedQueryDelete(id string, req *http.Request) (interface{}, error) { args := structs.PreparedQueryRequest{ Op: structs.PreparedQueryDelete, Query: &structs.PreparedQuery{ @@ -336,10 +336,10 @@ func (s *HTTPHandlers) PreparedQuerySpecific(resp http.ResponseWriter, req *http return s.preparedQueryGet(id, resp, req) case "PUT": - return s.preparedQueryUpdate(id, resp, req) + return s.preparedQueryUpdate(id, req) case "DELETE": - return s.preparedQueryDelete(id, resp, req) + return s.preparedQueryDelete(id, req) default: return nil, MethodNotAllowedError{req.Method, []string{"GET", "PUT", "DELETE"}} diff --git a/agent/proxycfg/api_gateway.go b/agent/proxycfg/api_gateway.go index fbef84f61603..e7b6d4dcb9a7 100644 --- a/agent/proxycfg/api_gateway.go +++ b/agent/proxycfg/api_gateway.go @@ -265,7 +265,6 @@ func (h *handlerAPIGateway) handleGatewayConfigUpdate(ctx context.Context, u Upd }) snap.APIGateway.BoundGatewayConfigLoaded = true - break case *structs.APIGatewayConfigEntry: snap.APIGateway.GatewayConfig = gwConf @@ -280,7 +279,6 @@ func (h *handlerAPIGateway) handleGatewayConfigUpdate(ctx context.Context, u Upd if err != nil { return err } - break default: return fmt.Errorf("invalid type for config entry: %T", resp.Entry) } diff --git a/agent/session_endpoint.go b/agent/session_endpoint.go index 90c3fa32bae7..31da29100543 100644 --- a/agent/session_endpoint.go +++ b/agent/session_endpoint.go @@ -216,7 +216,5 @@ func fixupEmptySessionChecks(session *structs.Session) { // If the NodeChecks field contains an empty slice, empty out the default check that was provided to Checks if len(session.NodeChecks) == 0 { session.Checks = nil - return } - return } diff --git a/agent/structs/config_entry.go b/agent/structs/config_entry.go index 15cec184f6b8..1d489546865c 100644 --- a/agent/structs/config_entry.go +++ b/agent/structs/config_entry.go @@ -296,7 +296,7 @@ func (e *ServiceConfigEntry) Validate() error { } if e.Destination != nil { - if e.Destination.Addresses == nil || len(e.Destination.Addresses) == 0 { + if len(e.Destination.Addresses) == 0 { validationErr = multierror.Append(validationErr, errors.New("Destination must contain at least one valid address")) } diff --git a/agent/structs/config_entry_jwt_provider_test.go b/agent/structs/config_entry_jwt_provider_test.go index 6a117fe5084f..9076960c668f 100644 --- a/agent/structs/config_entry_jwt_provider_test.go +++ b/agent/structs/config_entry_jwt_provider_test.go @@ -20,7 +20,7 @@ func newTestAuthz(t *testing.T, src string) acl.Authorizer { return authorizer } -var tenSeconds time.Duration = 10 * time.Second +var tenSeconds = 10 * time.Second var hundredSeconds time.Duration = 100 * time.Second var connectTimeout = time.Duration(5) * time.Second diff --git a/agent/xds/clusters.go b/agent/xds/clusters.go index 028013353e58..83e4234e3b2b 100644 --- a/agent/xds/clusters.go +++ b/agent/xds/clusters.go @@ -1761,7 +1761,7 @@ func (s *ResourceGenerator) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, op OutlierDetection: &envoy_cluster_v3.OutlierDetection{}, } - useEDS := !(len(opts.hostnameEndpoints) > 0) + useEDS := len(opts.hostnameEndpoints) <= 0 // TCP keepalive settings can be enabled for terminating gateway upstreams or remote mesh gateways. remoteUpstream := opts.isRemote || snap.Kind == structs.ServiceKindTerminatingGateway diff --git a/agent/xds/listeners.go b/agent/xds/listeners.go index 449f87c8b6e6..e5be5329be43 100644 --- a/agent/xds/listeners.go +++ b/agent/xds/listeners.go @@ -1707,7 +1707,7 @@ func (s *ResourceGenerator) makeTerminatingGatewayListener( ) } - var dest *structs.DestinationConfig = &svcConfig.Destination + var dest = &svcConfig.Destination opts := terminatingGatewayFilterChainOpts{ service: svc, diff --git a/agent/xds/xds_protocol_helpers_test.go b/agent/xds/xds_protocol_helpers_test.go index fb79dbfe9883..723f192a0b89 100644 --- a/agent/xds/xds_protocol_helpers_test.go +++ b/agent/xds/xds_protocol_helpers_test.go @@ -77,7 +77,7 @@ type testManager struct { cancels chan structs.ServiceID } -func newTestManager(t *testing.T) *testManager { +func newTestManager() *testManager { return &testManager{ stateChans: map[structs.ServiceID]chan *proxycfg.ConfigSnapshot{}, drainChans: map[structs.ServiceID]chan struct{}{}, @@ -186,7 +186,7 @@ func newTestServerDeltaScenario( token string, authCheckFrequency time.Duration, ) *testServerScenario { - mgr := newTestManager(t) + mgr := newTestManager() envoy := NewTestEnvoy(t, proxyID, token) sink := metrics.NewInmemSink(1*time.Minute, 1*time.Minute) diff --git a/command/monitor/monitor.go b/command/monitor/monitor.go index e1d0e8597d50..4f7a170564dd 100644 --- a/command/monitor/monitor.go +++ b/command/monitor/monitor.go @@ -82,14 +82,11 @@ func (c *cmd) Run(args []string) int { go func() { defer close(eventDoneCh) OUTER: - for { - select { - case log := <-logCh: - if log == "" { - break OUTER - } - c.UI.Info(log) + for log := range logCh { + if log == "" { + break OUTER } + c.UI.Info(log) } c.lock.Lock() diff --git a/command/peering/read/read.go b/command/peering/read/read.go index 8d15210fcfaa..27793dc27024 100644 --- a/command/peering/read/read.go +++ b/command/peering/read/read.go @@ -114,7 +114,7 @@ func formatPeering(peering *api.Peering) string { buffer.WriteString(fmt.Sprintf("DeletedAt: %s\n", peering.DeletedAt.Format(time.RFC3339))) } buffer.WriteString(fmt.Sprintf("State: %s\n", peering.State)) - if peering.Meta != nil && len(peering.Meta) > 0 { + if len(peering.Meta) > 0 { buffer.WriteString("Meta:\n") for k, v := range peering.Meta { buffer.WriteString(fmt.Sprintf(" %s=%s\n", k, v)) @@ -125,7 +125,7 @@ func formatPeering(peering *api.Peering) string { buffer.WriteString(fmt.Sprintf("Peer ID: %s\n", peering.PeerID)) buffer.WriteString(fmt.Sprintf("Peer Server Name: %s\n", peering.PeerServerName)) buffer.WriteString(fmt.Sprintf("Peer CA Pems: %d\n", len(peering.PeerCAPems))) - if peering.PeerServerAddresses != nil && len(peering.PeerServerAddresses) > 0 { + if len(peering.PeerServerAddresses) > 0 { buffer.WriteString("Peer Server Addresses:\n") for _, v := range peering.PeerServerAddresses { buffer.WriteString(fmt.Sprintf(" %s", v)) diff --git a/command/tls/cert/create/tls_cert_create.go b/command/tls/cert/create/tls_cert_create.go index cfaff836cd0c..a0e18cbb9115 100644 --- a/command/tls/cert/create/tls_cert_create.go +++ b/command/tls/cert/create/tls_cert_create.go @@ -86,9 +86,7 @@ func (c *cmd) Run(args []string) int { return 1 } - if !((c.server && !c.client && !c.cli) || - (!c.server && c.client && !c.cli) || - (!c.server && !c.client && c.cli)) { + if (!c.server || c.client || c.cli) && (c.server || !c.client || c.cli) && (c.server || c.client || !c.cli) { c.UI.Error("Please provide either -server, -client, or -cli") return 1 } diff --git a/command/version/formatter.go b/command/version/formatter.go index 612c305a7985..3939fb30a49d 100644 --- a/command/version/formatter.go +++ b/command/version/formatter.go @@ -40,7 +40,7 @@ func newPrettyFormatter() Formatter { return &prettyFormatter{} } -func (_ *prettyFormatter) Format(info *VersionInfo) (string, error) { +func (*prettyFormatter) Format(info *VersionInfo) (string, error) { var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf("Consul v%s\n", info.HumanVersion)) if info.Revision != "" { @@ -70,7 +70,7 @@ func newJSONFormatter() Formatter { return &jsonFormatter{} } -func (_ *jsonFormatter) Format(info *VersionInfo) (string, error) { +func (*jsonFormatter) Format(info *VersionInfo) (string, error) { b, err := json.MarshalIndent(info, "", " ") if err != nil { return "", fmt.Errorf("Failed to marshal version info: %v", err) diff --git a/internal/go-sso/oidcauth/oidcauthtest/testing.go b/internal/go-sso/oidcauth/oidcauthtest/testing.go index 29b7cf909930..3ba4befe0989 100644 --- a/internal/go-sso/oidcauth/oidcauthtest/testing.go +++ b/internal/go-sso/oidcauth/oidcauthtest/testing.go @@ -285,13 +285,13 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { switch { case req.FormValue("grant_type") != "authorization_code": - _ = writeTokenErrorResponse(w, req, http.StatusBadRequest, "invalid_request", "bad grant_type") + _ = writeTokenErrorResponse(w, http.StatusBadRequest, "invalid_request", "bad grant_type") return case !strutil.StrListContains(s.allowedRedirectURIs, req.FormValue("redirect_uri")): - _ = writeTokenErrorResponse(w, req, http.StatusBadRequest, "invalid_request", "redirect_uri is not allowed") + _ = writeTokenErrorResponse(w, http.StatusBadRequest, "invalid_request", "redirect_uri is not allowed") return case req.FormValue("code") != s.expectedAuthCode: - _ = writeTokenErrorResponse(w, req, http.StatusUnauthorized, "invalid_grant", "unexpected auth code") + _ = writeTokenErrorResponse(w, http.StatusUnauthorized, "invalid_grant", "unexpected auth code") return } @@ -308,7 +308,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { jwtData, err := SignJWT("", stdClaims, s.customClaims) if err != nil { - _ = writeTokenErrorResponse(w, req, http.StatusInternalServerError, "server_error", err.Error()) + _ = writeTokenErrorResponse(w, http.StatusInternalServerError, "server_error", err.Error()) return } @@ -359,7 +359,7 @@ func writeAuthErrorResponse(w http.ResponseWriter, req *http.Request, errorCode, http.Redirect(w, req, redirectURI, http.StatusFound) } -func writeTokenErrorResponse(w http.ResponseWriter, req *http.Request, statusCode int, errorCode, errorMessage string) error { +func writeTokenErrorResponse(w http.ResponseWriter, statusCode int, errorCode, errorMessage string) error { body := struct { Code string `json:"error"` Desc string `json:"error_description,omitempty"` diff --git a/internal/resource/reaper/controller_test.go b/internal/resource/reaper/controller_test.go index 58ed2564fe3f..f443a826a909 100644 --- a/internal/resource/reaper/controller_test.go +++ b/internal/resource/reaper/controller_test.go @@ -16,7 +16,6 @@ import ( "github.com/hashicorp/consul/internal/resource" "github.com/hashicorp/consul/internal/resource/demo" "github.com/hashicorp/consul/internal/resource/resourcetest" - rtest "github.com/hashicorp/consul/internal/resource/resourcetest" "github.com/hashicorp/consul/proto-public/pbresource" "github.com/hashicorp/consul/sdk/testutil" ) @@ -217,7 +216,7 @@ func runReaperTestCaseWithTenancies(testCase func(tenancy *pbresource.Tenancy)) func setupResourceService(t *testing.T) pbresource.ResourceServiceClient { return svctest.NewResourceServiceBuilder(). - WithTenancies(rtest.TestTenancies()...). + WithTenancies(resourcetest.TestTenancies()...). WithRegisterFns(demo.RegisterTypes). Run(t) } diff --git a/tlsutil/config_test.go b/tlsutil/config_test.go index 3721a75ff5b6..f83e083b6bc7 100644 --- a/tlsutil/config_test.go +++ b/tlsutil/config_test.go @@ -1694,11 +1694,6 @@ func certChain(t *testing.T, certs ...string) []*x509.Certificate { return result } -func startRPCTLSServer(t *testing.T, c *Configurator) (net.Conn, <-chan error) { - client, errc, _ := startTLSServer(c.IncomingRPCConfig()) - return client, errc -} - func startALPNRPCTLSServer(t *testing.T, config *Config, alpnProtos []string) (net.Conn, <-chan error) { cfg := makeConfigurator(t, *config).IncomingALPNRPCConfig(alpnProtos) client, errc, _ := startTLSServer(cfg)