github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/e2e/connect/connect.go (about)

     1  package connect
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/nomad/e2e/e2eutil"
     7  	"github.com/hashicorp/nomad/e2e/framework"
     8  	"github.com/hashicorp/nomad/helper/uuid"
     9  )
    10  
    11  const (
    12  	// envConsulToken is the consul http token environment variable
    13  	envConsulToken = "CONSUL_HTTP_TOKEN"
    14  
    15  	// demoConnectJob is the example connect enabled job useful for testing
    16  	demoConnectJob = "connect/input/demo.nomad"
    17  
    18  	// demoConnectCustomProxyExposed is a connect job with custom sidecar_task
    19  	// that also uses the expose check feature.
    20  	demoConnectCustomProxyExposed = "connect/input/expose-custom.nomad"
    21  
    22  	// demoConnectNativeJob is the example connect native enabled job useful for testing
    23  	demoConnectNativeJob = "connect/input/native-demo.nomad"
    24  
    25  	// demoConnectIngressGateway is the example ingress gateway job useful for testing
    26  	demoConnectIngressGateway = "connect/input/ingress-gateway.nomad"
    27  
    28  	// demoConnectMultiIngressGateway is the example multi ingress gateway job useful for testing
    29  	demoConnectMultiIngressGateway = "connect/input/multi-ingress.nomad"
    30  
    31  	// demoConnectTerminatingGateway is the example terminating gateway job useful for testing
    32  	demoConnectTerminatingGateway = "connect/input/terminating-gateway.nomad"
    33  )
    34  
    35  type ConnectE2ETest struct {
    36  	framework.TC
    37  	jobIds []string
    38  }
    39  
    40  func init() {
    41  	// Connect tests without Consul ACLs enabled.
    42  	framework.AddSuites(&framework.TestSuite{
    43  		Component:   "Connect",
    44  		CanRunLocal: true,
    45  		Consul:      true,
    46  		Cases: []framework.TestCase{
    47  			new(ConnectE2ETest),
    48  			new(ConnectClientStateE2ETest),
    49  		},
    50  	})
    51  
    52  	framework.AddSuites(&framework.TestSuite{
    53  		Component:   "ConnectACLs",
    54  		CanRunLocal: false,
    55  		Consul:      true,
    56  		Parallel:    false,
    57  		Cases: []framework.TestCase{
    58  			new(ConnectACLsE2ETest),
    59  		},
    60  	})
    61  }
    62  
    63  func (tc *ConnectE2ETest) BeforeAll(f *framework.F) {
    64  	e2eutil.WaitForLeader(f.T(), tc.Nomad())
    65  	e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 2)
    66  }
    67  
    68  func (tc *ConnectE2ETest) AfterEach(f *framework.F) {
    69  	if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" {
    70  		return
    71  	}
    72  
    73  	for _, id := range tc.jobIds {
    74  		tc.Nomad().Jobs().Deregister(id, true, nil)
    75  	}
    76  	tc.jobIds = []string{}
    77  	tc.Nomad().System().GarbageCollect()
    78  }
    79  
    80  func connectJobID() string {
    81  	return "connect" + uuid.Generate()[0:8]
    82  }
    83  
    84  // TestConnectDemo tests the demo job file used in Connect Integration examples.
    85  func (tc *ConnectE2ETest) TestConnectDemo(f *framework.F) {
    86  	t := f.T()
    87  
    88  	jobID := connectJobID()
    89  	tc.jobIds = append(tc.jobIds, jobID)
    90  
    91  	allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectJob, jobID, "")
    92  	allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
    93  	e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
    94  }
    95  
    96  // TestConnectCustomSidecarExposed tests that a connect sidecar with custom task
    97  // definition can also make use of the expose service check feature.
    98  func (tc *ConnectE2ETest) TestConnectCustomSidecarExposed(f *framework.F) {
    99  	t := f.T()
   100  
   101  	jobID := connectJobID()
   102  	tc.jobIds = append(tc.jobIds, jobID)
   103  
   104  	allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectCustomProxyExposed, jobID, "")
   105  	allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
   106  	e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
   107  }
   108  
   109  // TestConnectNativeDemo tests the demo job file used in Connect Native Integration examples.
   110  func (tc *ConnectE2ETest) TestConnectNativeDemo(f *framework.F) {
   111  	t := f.T()
   112  
   113  	jobID := connectJobID()
   114  	tc.jobIds = append(tc.jobIds, jobID)
   115  
   116  	allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectNativeJob, jobID, "")
   117  	allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
   118  	e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
   119  }
   120  
   121  func (tc *ConnectE2ETest) TestConnectIngressGatewayDemo(f *framework.F) {
   122  	t := f.T()
   123  
   124  	jobID := connectJobID()
   125  	tc.jobIds = append(tc.jobIds, jobID)
   126  
   127  	allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectIngressGateway, jobID, "")
   128  	allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
   129  	e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
   130  }
   131  
   132  func (tc *ConnectE2ETest) TestConnectMultiIngressGatewayDemo(f *framework.F) {
   133  	t := f.T()
   134  
   135  	jobID := connectJobID()
   136  	tc.jobIds = append(tc.jobIds, jobID)
   137  
   138  	allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectMultiIngressGateway, jobID, "")
   139  
   140  	allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
   141  	e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
   142  }
   143  
   144  func (tc *ConnectE2ETest) TestConnectTerminatingGatewayDemo(f *framework.F) {
   145  
   146  	t := f.T()
   147  
   148  	jobID := connectJobID()
   149  	tc.jobIds = append(tc.jobIds, jobID)
   150  
   151  	allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectTerminatingGateway, jobID, "")
   152  
   153  	allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
   154  	e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
   155  }