2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-09-03 22:46:03 +00:00
|
|
|
package connect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/e2e/e2eutil"
|
|
|
|
"github.com/hashicorp/nomad/e2e/framework"
|
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
)
|
|
|
|
|
2021-01-19 15:46:44 +00:00
|
|
|
const (
|
|
|
|
// envConsulToken is the consul http token environment variable
|
|
|
|
envConsulToken = "CONSUL_HTTP_TOKEN"
|
|
|
|
|
|
|
|
// demoConnectJob is the example connect enabled job useful for testing
|
|
|
|
demoConnectJob = "connect/input/demo.nomad"
|
|
|
|
|
2021-02-09 15:44:48 +00:00
|
|
|
// demoConnectCustomProxyExposed is a connect job with custom sidecar_task
|
|
|
|
// that also uses the expose check feature.
|
|
|
|
demoConnectCustomProxyExposed = "connect/input/expose-custom.nomad"
|
|
|
|
|
2021-01-19 15:46:44 +00:00
|
|
|
// demoConnectNativeJob is the example connect native enabled job useful for testing
|
|
|
|
demoConnectNativeJob = "connect/input/native-demo.nomad"
|
|
|
|
|
|
|
|
// demoConnectIngressGateway is the example ingress gateway job useful for testing
|
|
|
|
demoConnectIngressGateway = "connect/input/ingress-gateway.nomad"
|
|
|
|
|
|
|
|
// demoConnectMultiIngressGateway is the example multi ingress gateway job useful for testing
|
|
|
|
demoConnectMultiIngressGateway = "connect/input/multi-ingress.nomad"
|
2020-12-15 20:38:33 +00:00
|
|
|
|
|
|
|
// demoConnectTerminatingGateway is the example terminating gateway job useful for testing
|
|
|
|
demoConnectTerminatingGateway = "connect/input/terminating-gateway.nomad"
|
2021-01-19 15:46:44 +00:00
|
|
|
)
|
|
|
|
|
2019-09-03 22:46:03 +00:00
|
|
|
type ConnectE2ETest struct {
|
|
|
|
framework.TC
|
|
|
|
jobIds []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-02-09 15:44:48 +00:00
|
|
|
// Connect tests without Consul ACLs enabled.
|
2020-02-04 02:46:33 +00:00
|
|
|
framework.AddSuites(&framework.TestSuite{
|
|
|
|
Component: "Connect",
|
|
|
|
CanRunLocal: true,
|
|
|
|
Consul: true,
|
|
|
|
Cases: []framework.TestCase{
|
|
|
|
new(ConnectE2ETest),
|
|
|
|
new(ConnectClientStateE2ETest),
|
|
|
|
},
|
|
|
|
})
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2022-03-18 13:27:28 +00:00
|
|
|
framework.AddSuites(&framework.TestSuite{
|
|
|
|
Component: "ConnectACLs",
|
|
|
|
CanRunLocal: false,
|
|
|
|
Consul: true,
|
|
|
|
Parallel: false,
|
|
|
|
Cases: []framework.TestCase{
|
|
|
|
new(ConnectACLsE2ETest),
|
|
|
|
},
|
|
|
|
})
|
2019-09-03 22:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectE2ETest) BeforeAll(f *framework.F) {
|
|
|
|
e2eutil.WaitForLeader(f.T(), tc.Nomad())
|
|
|
|
e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectE2ETest) AfterEach(f *framework.F) {
|
|
|
|
if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range tc.jobIds {
|
|
|
|
tc.Nomad().Jobs().Deregister(id, true, nil)
|
|
|
|
}
|
|
|
|
tc.jobIds = []string{}
|
|
|
|
tc.Nomad().System().GarbageCollect()
|
|
|
|
}
|
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
func connectJobID() string {
|
2020-07-10 15:24:13 +00:00
|
|
|
return "connect" + uuid.Generate()[0:8]
|
2020-06-19 18:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestConnectDemo tests the demo job file used in Connect Integration examples.
|
2019-09-03 22:46:03 +00:00
|
|
|
func (tc *ConnectE2ETest) TestConnectDemo(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIds = append(tc.jobIds, jobID)
|
2019-09-03 22:46:03 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectJob, jobID, "")
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
|
|
|
}
|
2019-09-03 22:46:03 +00:00
|
|
|
|
2021-02-09 15:44:48 +00:00
|
|
|
// TestConnectCustomSidecarExposed tests that a connect sidecar with custom task
|
|
|
|
// definition can also make use of the expose service check feature.
|
|
|
|
func (tc *ConnectE2ETest) TestConnectCustomSidecarExposed(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIds = append(tc.jobIds, jobID)
|
|
|
|
|
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectCustomProxyExposed, jobID, "")
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
|
|
|
}
|
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
// TestConnectNativeDemo tests the demo job file used in Connect Native Integration examples.
|
|
|
|
func (tc *ConnectE2ETest) TestConnectNativeDemo(f *framework.F) {
|
|
|
|
t := f.T()
|
2019-09-03 22:46:03 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIds = append(tc.jobIds, jobID)
|
2019-09-03 22:46:03 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectNativeJob, jobID, "")
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
2019-09-03 22:46:03 +00:00
|
|
|
}
|
2020-11-25 20:30:22 +00:00
|
|
|
|
|
|
|
func (tc *ConnectE2ETest) TestConnectIngressGatewayDemo(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIds = append(tc.jobIds, jobID)
|
|
|
|
|
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectIngressGateway, jobID, "")
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
|
|
|
}
|
2021-01-19 15:46:44 +00:00
|
|
|
|
|
|
|
func (tc *ConnectE2ETest) TestConnectMultiIngressGatewayDemo(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIds = append(tc.jobIds, jobID)
|
|
|
|
|
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectMultiIngressGateway, jobID, "")
|
2020-12-15 20:38:33 +00:00
|
|
|
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectE2ETest) TestConnectTerminatingGatewayDemo(f *framework.F) {
|
|
|
|
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIds = append(tc.jobIds, jobID)
|
|
|
|
|
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectTerminatingGateway, jobID, "")
|
|
|
|
|
2021-01-19 15:46:44 +00:00
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
|
|
|
}
|