Skip to content

Commit

Permalink
Merge branch 'main' into NET-1723/update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodingenthusiast authored Feb 24, 2023
2 parents d16ab0d + ab0d43e commit 24ec69c
Show file tree
Hide file tree
Showing 48 changed files with 4,424 additions and 1,349 deletions.
35 changes: 35 additions & 0 deletions .release/ci.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,41 @@ event "prepare" {
}
}

## These are promotion and post-publish events
## they should be added to the end of the file after the verify event stanza.

event "trigger-staging" {
// This event is dispatched by the bob trigger-promotion command
// and is required - do not delete.
}

event "promote-staging" {
depends = ["trigger-staging"]
action "promote-staging" {
organization = "hashicorp"
repository = "crt-workflows-common"
workflow = "promote-staging"
config = "release-metadata.hcl"
}

notification {
on = "always"
}
}

event "promote-staging-docker" {
depends = ["promote-staging"]
action "promote-staging-docker" {
organization = "hashicorp"
repository = "crt-workflows-common"
workflow = "promote-staging-docker"
}

notification {
on = "always"
}
}

event "trigger-production" {
// This event is dispatched by the bob trigger-promotion command
// and is required - do not delete.
Expand Down
4 changes: 2 additions & 2 deletions agent/grpc-external/services/peerstream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,8 @@ func TestStreamResources_Server_DisconnectsOnHeartbeatTimeout(t *testing.T) {
})

testutil.RunStep(t, "stream is disconnected due to heartbeat timeout", func(t *testing.T) {
disconnectTime := ptr(it.FutureNow(1))
retry.Run(t, func(r *retry.R) {
disconnectTime := ptr(it.StaticNow())
status, ok := srv.StreamStatus(testPeerID)
require.True(r, ok)
require.False(r, status.Connected)
Expand Down Expand Up @@ -1423,7 +1423,7 @@ func makeClient(t *testing.T, srv *testServer, peerID string) *MockClient {
},
}))

// Receive a services and roots subscription request pair from server
// Receive ExportedService, ExportedServiceList, and PeeringTrustBundle subscription requests from server
receivedSub1, err := client.Recv()
require.NoError(t, err)
receivedSub2, err := client.Recv()
Expand Down
10 changes: 10 additions & 0 deletions agent/grpc-external/services/peerstream/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ func (t *incrementalTime) Now() time.Time {
return t.base.Add(dur)
}

// StaticNow returns the current internal clock without advancing it.
func (t *incrementalTime) StaticNow() time.Time {
t.mu.Lock()
defer t.mu.Unlock()

dur := time.Duration(t.next) * time.Second

return t.base.Add(dur)
}

// FutureNow will return a given future value of the Now() function.
// The numerical argument indicates which future Now value you wanted. The
// value must be > 0.
Expand Down
47 changes: 28 additions & 19 deletions agent/xds/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/armon/go-metrics"
envoy_discovery_v3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
"github.com/hashicorp/consul/api"
"github.com/stretchr/testify/require"
rpcstatus "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/codes"
Expand All @@ -21,8 +20,10 @@ import (
"github.com/hashicorp/consul/agent/grpc-external/limiter"
"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/envoyextensions/xdscommon"
"github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/consul/version"
)

Expand Down Expand Up @@ -1057,19 +1058,23 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// aclResolve may be called in a goroutine even after a
// testcase tt returns. Capture the variable as tc so the
// values don't swap in the next iteration.
tc := tt
aclResolve := func(id string) (acl.Authorizer, error) {
if !tt.defaultDeny {
if !tc.defaultDeny {
// Allow all
return acl.RootAuthorizer("allow"), nil
}
if tt.acl == "" {
if tc.acl == "" {
// No token and defaultDeny is denied
return acl.RootAuthorizer("deny"), nil
}
// Ensure the correct token was passed
require.Equal(t, tt.token, id)
require.Equal(t, tc.token, id)
// Parse the ACL and enforce it
policy, err := acl.NewPolicyFromSource(tt.acl, nil, nil)
policy, err := acl.NewPolicyFromSource(tc.acl, nil, nil)
require.NoError(t, err)
return acl.NewPolicyAuthorizerWithDefaults(acl.RootAuthorizer("deny"), []*acl.Policy{policy}, nil)
}
Expand All @@ -1095,13 +1100,15 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) {

// If there is no token, check that we increment the gauge
if tt.token == "" {
data := scenario.sink.Data()
require.Len(t, data, 1)

item := data[0]
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"]
require.True(t, ok)
require.Equal(t, float32(1), val.Value)
retry.Run(t, func(r *retry.R) {
data := scenario.sink.Data()
require.Len(r, data, 1)

item := data[0]
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"]
require.True(r, ok)
require.Equal(r, float32(1), val.Value)
})
}

if !tt.wantDenied {
Expand Down Expand Up @@ -1138,13 +1145,15 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) {

// If there is no token, check that we decrement the gauge
if tt.token == "" {
data := scenario.sink.Data()
require.Len(t, data, 1)

item := data[0]
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"]
require.True(t, ok)
require.Equal(t, float32(0), val.Value)
retry.Run(t, func(r *retry.R) {
data := scenario.sink.Data()
require.Len(r, data, 1)

item := data[0]
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"]
require.True(r, ok)
require.Equal(r, float32(0), val.Value)
})
}
})
}
Expand Down
4 changes: 1 addition & 3 deletions agent/xds/xds_protocol_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ func newTestServerDeltaScenario(
) *testServerScenario {
mgr := newTestManager(t)
envoy := NewTestEnvoy(t, proxyID, token)
t.Cleanup(func() {
envoy.Close()
})

sink := metrics.NewInmemSink(1*time.Minute, 1*time.Minute)
cfg := metrics.DefaultConfig("consul.xds.test")
Expand All @@ -177,6 +174,7 @@ func newTestServerDeltaScenario(
metrics.NewGlobal(cfg, sink)

t.Cleanup(func() {
envoy.Close()
sink := &metrics.BlackholeSink{}
metrics.NewGlobal(cfg, sink)
})
Expand Down
3 changes: 3 additions & 0 deletions api/operator_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type License struct {
// no longer be used in any capacity
TerminationTime time.Time `json:"termination_time"`

// Whether the license will ignore termination
IgnoreTermination bool `json:"ignore_termination"`

// The product the license is valid for
Product string `json:"product"`

Expand Down
3 changes: 2 additions & 1 deletion command/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ func (c *cmd) prepare() (version string, err error) {
// If none are specified we will collect information from
// all by default
if len(c.capture) == 0 {
c.capture = defaultTargets
c.capture = make([]string, len(defaultTargets))
copy(c.capture, defaultTargets)
}

// If EnableDebug is not true, skip collecting pprof
Expand Down
6 changes: 4 additions & 2 deletions test/integration/consul-container/libs/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewN(t TestingT, conf Config, count int) (*Cluster, error) {
func New(t TestingT, configs []Config) (*Cluster, error) {
id, err := shortid.Generate()
if err != nil {
return nil, fmt.Errorf("could not cluster id: %w", err)
return nil, fmt.Errorf("could not generate cluster id: %w", err)
}

name := fmt.Sprintf("consul-int-cluster-%s", id)
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *Cluster) AddN(conf Config, count int, join bool) error {
return c.Add(configs, join)
}

// Add starts an agent with the given configuration and joins it with the existing cluster
// Add starts agents with the given configurations and joins them to the existing cluster
func (c *Cluster) Add(configs []Config, serfJoin bool) (xe error) {
if c.Index == 0 && !serfJoin {
return fmt.Errorf("the first call to Cluster.Add must have serfJoin=true")
Expand Down Expand Up @@ -160,9 +160,11 @@ func (c *Cluster) Add(configs []Config, serfJoin bool) (xe error) {
func (c *Cluster) Join(agents []Agent) error {
return c.join(agents, false)
}

func (c *Cluster) JoinExternally(agents []Agent) error {
return c.join(agents, true)
}

func (c *Cluster) join(agents []Agent, skipSerfJoin bool) error {
if len(agents) == 0 {
return nil // no change
Expand Down
4 changes: 3 additions & 1 deletion test/integration/consul-container/libs/cluster/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func startContainer(ctx context.Context, req testcontainers.ContainerRequest) (t
})
}

const pauseImage = "k8s.gcr.io/pause:3.3"
const pauseImage = "registry.k8s.io/pause:3.3"

type containerOpts struct {
configFile string
Expand Down Expand Up @@ -518,10 +518,12 @@ func newContainerRequest(config Config, opts containerOpts) (podRequest, consulR
"8079/tcp", // Envoy App Listener - grpc port used by static-server
"8078/tcp", // Envoy App Listener - grpc port used by static-server-v1
"8077/tcp", // Envoy App Listener - grpc port used by static-server-v2
"8076/tcp", // Envoy App Listener - grpc port used by static-server-v3

"8080/tcp", // Envoy App Listener - http port used by static-server
"8081/tcp", // Envoy App Listener - http port used by static-server-v1
"8082/tcp", // Envoy App Listener - http port used by static-server-v2
"8083/tcp", // Envoy App Listener - http port used by static-server-v3
"9998/tcp", // Envoy App Listener
"9999/tcp", // Envoy App Listener
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
libassert "github.com/hashicorp/consul/test/integration/consul-container/libs/assert"
libcluster "github.com/hashicorp/consul/test/integration/consul-container/libs/cluster"
libservice "github.com/hashicorp/consul/test/integration/consul-container/libs/service"
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
"github.com/hashicorp/consul/test/integration/consul-container/test"
)

// TestBasicConnectService Summary
Expand All @@ -23,7 +23,14 @@ import (
// - Make sure a call to the client sidecar local bind port returns a response from the upstream, static-server
func TestBasicConnectService(t *testing.T) {
t.Parallel()
cluster := createCluster(t)

buildOptions := &libcluster.BuildOptions{
InjectAutoEncryption: true,
InjectGossipEncryption: true,
// TODO(rb): fix the test to not need the service/envoy stack to use :8500
AllowHTTPAnyway: true,
}
cluster := test.CreateCluster(t, "", nil, buildOptions, true)

clientService := createServices(t, cluster)
_, port := clientService.GetAddr()
Expand All @@ -37,38 +44,6 @@ func TestBasicConnectService(t *testing.T) {
libassert.AssertFortioName(t, fmt.Sprintf("http://localhost:%d", port), "static-server")
}

func createCluster(t *testing.T) *libcluster.Cluster {
opts := libcluster.BuildOptions{
InjectAutoEncryption: true,
InjectGossipEncryption: true,
// TODO: fix the test to not need the service/envoy stack to use :8500
AllowHTTPAnyway: true,
}
ctx := libcluster.NewBuildContext(t, opts)

conf := libcluster.NewConfigBuilder(ctx).
ToAgentConfig(t)
t.Logf("Cluster config:\n%s", conf.JSON)

configs := []libcluster.Config{*conf}

cluster, err := libcluster.New(t, configs)
require.NoError(t, err)

node := cluster.Agents[0]
client := node.GetClient()

libcluster.WaitForLeader(t, cluster, client)
libcluster.WaitForMembers(t, client, 1)

// Default Proxy Settings
ok, err := utils.ApplyDefaultProxySettings(client)
require.NoError(t, err)
require.True(t, ok)

return cluster
}

func createServices(t *testing.T, cluster *libcluster.Cluster) libservice.Service {
node := cluster.Agents[0]
client := node.GetClient()
Expand Down
68 changes: 68 additions & 0 deletions test/integration/consul-container/test/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package test

import (
"testing"

libcluster "github.com/hashicorp/consul/test/integration/consul-container/libs/cluster"
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
)

type TestLogConsumer struct {
Msgs []string
}

func (g *TestLogConsumer) Accept(l testcontainers.Log) {
g.Msgs = append(g.Msgs, string(l.Content))
}

// Creates a cluster with options for basic customization. All args except t
// are optional and will use sensible defaults when not provided.
func CreateCluster(
t *testing.T,
cmd string,
logConsumer *TestLogConsumer,
buildOptions *libcluster.BuildOptions,
applyDefaultProxySettings bool) *libcluster.Cluster {

// optional
if buildOptions == nil {
buildOptions = &libcluster.BuildOptions{
InjectAutoEncryption: true,
InjectGossipEncryption: true,
}
}
ctx := libcluster.NewBuildContext(t, *buildOptions)

conf := libcluster.NewConfigBuilder(ctx).ToAgentConfig(t)

// optional
if logConsumer != nil {
conf.LogConsumer = logConsumer
}

t.Logf("Cluster config:\n%s", conf.JSON)

// optional custom cmd
if cmd != "" {
conf.Cmd = append(conf.Cmd, cmd)
}

cluster, err := libcluster.New(t, []libcluster.Config{*conf})
require.NoError(t, err)

client, err := cluster.GetClient(nil, true)

require.NoError(t, err)
libcluster.WaitForLeader(t, cluster, client)
libcluster.WaitForMembers(t, client, 1)

if applyDefaultProxySettings {
ok, err := utils.ApplyDefaultProxySettings(client)
require.NoError(t, err)
require.True(t, ok)
}

return cluster
}
Loading

0 comments on commit 24ec69c

Please sign in to comment.