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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -649,6 +652,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -710,6 +716,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -722,6 +731,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-different-consul-svc-name-sidecar-proxy",
Expand Down Expand Up @@ -791,6 +803,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -803,6 +818,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -873,6 +891,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -885,6 +906,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand All @@ -902,6 +926,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-service-updated",
Service: "service-updated",
Expand All @@ -914,6 +941,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -976,6 +1006,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -988,6 +1021,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-different-consul-svc-name-sidecar-proxy",
Expand All @@ -1005,6 +1041,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -1017,6 +1056,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-different-consul-svc-name-sidecar-proxy",
Expand Down Expand Up @@ -1065,6 +1107,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -1077,6 +1122,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand All @@ -1094,6 +1142,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-service-updated",
Service: "service-updated",
Expand All @@ -1106,6 +1157,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -1142,6 +1196,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -1154,6 +1211,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-different-consul-svc-name-sidecar-proxy",
Expand All @@ -1171,6 +1231,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-different-consul-svc-name",
Service: "different-consul-svc-name",
Expand All @@ -1183,6 +1246,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-different-consul-svc-name-sidecar-proxy",
Expand Down Expand Up @@ -1232,6 +1298,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -1250,6 +1319,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -1318,6 +1390,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod1-service-updated",
Service: "service-updated",
Expand All @@ -1336,6 +1411,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod1-service-updated-sidecar-proxy",
Expand All @@ -1359,6 +1437,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
ID: "pod2-service-updated",
Service: "service-updated",
Expand All @@ -1377,6 +1458,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
{
Node: consulNodeName,
Address: consulNodeAddress,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
Service: &api.AgentService{
Kind: api.ServiceKindConnectProxy,
ID: "pod2-service-updated-sidecar-proxy",
Expand Down Expand Up @@ -1432,8 +1516,9 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
c.ACL.Tokens.InitialManagement = adminToken
}
})

consulClient := testClient.APIClient
// Coincidentally, this allows enough time for the bootstrap token to be generated
testClient.TestServer.WaitForActiveCARoot(t)

_, err := namespaces.EnsureExists(consulClient, ts.ExpConsulNS, "")
require.NoError(t, err)
Expand Down Expand Up @@ -1738,6 +1823,8 @@ func TestReconcileDeleteEndpointWithNamespaces(t *testing.T) {
}
})
consulClient := testClient.APIClient
// Coincidentally, this allows enough time for the bootstrap token to be generated
testClient.TestServer.WaitForActiveCARoot(t)

_, err := namespaces.EnsureExists(consulClient, ts.ExpConsulNS, "")
require.NoError(t, err)
Expand All @@ -1749,6 +1836,9 @@ func TestReconcileDeleteEndpointWithNamespaces(t *testing.T) {
Node: consulNodeName,
Address: consulNodeAddress,
Service: svc,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
}
_, err = consulClient.Catalog().Register(serviceRegistration, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -2030,6 +2120,8 @@ func TestReconcileDeleteGatewayWithNamespaces(t *testing.T) {
}
})
consulClient := testClient.APIClient
// Coincidentally, this allows enough time for the bootstrap token to be generated
testClient.TestServer.WaitForActiveCARoot(t)

_, err := namespaces.EnsureExists(consulClient, ts.ConsulNS, "")
require.NoError(t, err)
Expand All @@ -2041,6 +2133,9 @@ func TestReconcileDeleteGatewayWithNamespaces(t *testing.T) {
Node: consulNodeName,
Address: consulNodeAddress,
Service: svc,
NodeMeta: map[string]string{
metaKeySyntheticNode: "true",
},
}
_, err = consulClient.Catalog().Register(serviceRegistration, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -2103,8 +2198,15 @@ func TestReconcileDeleteGatewayWithNamespaces(t *testing.T) {
require.Empty(t, append(defaultNS, testNS...))

if tt.enableACLs {
_, _, err = consulClient.ACL().TokenRead(token.AccessorID, nil)
require.EqualError(t, err, "Unexpected response code: 403 (ACL not found)")
queryOpts := &api.QueryOptions{}
if tt.initialConsulSvcs[0].Kind == api.ServiceKindMeshGateway {
queryOpts.Namespace = "default" // Mesh Gateways must always be registered in the "default" namespace.
} else {
queryOpts.Namespace = ts.ConsulNS
}

token, _, err = consulClient.ACL().TokenRead(token.AccessorID, queryOpts)
require.Contains(t, err.Error(), "ACL not found", token)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4073,6 +4073,7 @@ func TestReconcileDeleteEndpoint(t *testing.T) {
}
})
consulClient := testClient.APIClient
// TODO: stabilize this test by waiting for the ACL bootstrap

// Register service and proxy in consul
var token *api.ACLToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"time"

logrtest "github.com/go-logr/logr/testr"
"github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1"
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/constants"
"github.com/hashicorp/consul-k8s/control-plane/helper/test"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/stretchr/testify/require"
Expand All @@ -23,6 +20,10 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1"
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/constants"
"github.com/hashicorp/consul-k8s/control-plane/helper/test"
)

// TestReconcile_CreateUpdatePeeringAcceptor creates a peering acceptor.
Expand Down Expand Up @@ -505,6 +506,7 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) {
// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
consulClient := testClient.APIClient
testClient.TestServer.WaitForActiveCARoot(t)

if tt.initialConsulPeerName != "" {
// Add the initial peerings into Consul by calling the Generate token endpoint.
Expand Down Expand Up @@ -628,6 +630,7 @@ func TestReconcile_DeletePeeringAcceptor(t *testing.T) {
// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
consulClient := testClient.APIClient
testClient.TestServer.WaitForActiveCARoot(t)

// Add the initial peerings into Consul by calling the Generate token endpoint.
_, _, err := consulClient.Peerings().GenerateToken(context.Background(), api.PeeringGenerateTokenRequest{PeerName: "acceptor-deleted"}, nil)
Expand Down Expand Up @@ -774,6 +777,7 @@ func TestReconcile_VersionAnnotation(t *testing.T) {
// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
consulClient := testClient.APIClient
testClient.TestServer.WaitForActiveCARoot(t)

_, _, err := consulClient.Peerings().GenerateToken(context.Background(), api.PeeringGenerateTokenRequest{PeerName: "acceptor-created"}, nil)
require.NoError(t, err)
Expand Down
Loading