mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
e2e: add some e2e tests for pledge task driver (#17909)
* e2e: setup nomad for pledge driver * e2e: add some e2e tests for pledge task driver
This commit is contained in:
6
e2e/pledge/doc.go
Normal file
6
e2e/pledge/doc.go
Normal file
@@ -0,0 +1,6 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
// Package pledge tests the community pledge task driver.
|
||||
// https://github.com/shoenig/nomad-pledge-driver
|
||||
package pledge
|
||||
62
e2e/pledge/input/bridge.hcl
Normal file
62
e2e/pledge/input/bridge.hcl
Normal file
@@ -0,0 +1,62 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
job "bridge" {
|
||||
|
||||
constraint {
|
||||
attribute = "${attr.kernel.name}"
|
||||
value = "linux"
|
||||
}
|
||||
|
||||
group "group" {
|
||||
network {
|
||||
mode = "bridge"
|
||||
port "http" { to = 8181 }
|
||||
}
|
||||
|
||||
service {
|
||||
provider = "nomad"
|
||||
name = "pybridge"
|
||||
port = "http"
|
||||
tags = ["public=${attr.unique.platform.aws.public-ipv4}"]
|
||||
check {
|
||||
name = "up"
|
||||
type = "http"
|
||||
path = "/index.html"
|
||||
interval = "6s"
|
||||
timeout = "1s"
|
||||
}
|
||||
}
|
||||
|
||||
task "python" {
|
||||
driver = "pledge"
|
||||
config {
|
||||
command = "python3"
|
||||
args = ["-m", "http.server", "8181", "--directory", "${NOMAD_TASK_DIR}"]
|
||||
promises = "stdio rpath inet"
|
||||
unveil = ["r:/etc/mime.types", "r:${NOMAD_TASK_DIR}"]
|
||||
}
|
||||
|
||||
template {
|
||||
destination = "local/index.html"
|
||||
data = <<EOH
|
||||
<!doctype html>
|
||||
<html>
|
||||
<title>bridge mode</title>
|
||||
<body><p>Hello, pal!</p></body>
|
||||
</html>
|
||||
EOH
|
||||
}
|
||||
}
|
||||
|
||||
restart {
|
||||
attempts = 0
|
||||
mode = "fail"
|
||||
}
|
||||
|
||||
update {
|
||||
min_healthy_time = "4s"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
e2e/pledge/input/curl.hcl
Normal file
41
e2e/pledge/input/curl.hcl
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
variable "address" {
|
||||
type = string
|
||||
description = "The address to cURL"
|
||||
}
|
||||
|
||||
job "curl" {
|
||||
type = "batch"
|
||||
|
||||
constraint {
|
||||
attribute = "${attr.kernel.name}"
|
||||
value = "linux"
|
||||
}
|
||||
|
||||
group "group" {
|
||||
network {
|
||||
mode = "host"
|
||||
}
|
||||
|
||||
reschedule {
|
||||
attempts = 0
|
||||
unlimited = false
|
||||
}
|
||||
|
||||
restart {
|
||||
attempts = 0
|
||||
mode = "fail"
|
||||
}
|
||||
|
||||
task "curl" {
|
||||
driver = "pledge"
|
||||
config {
|
||||
command = "curl"
|
||||
args = ["${var.address}"]
|
||||
promises = "stdio rpath inet dns sendfd"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
39
e2e/pledge/input/sleep.hcl
Normal file
39
e2e/pledge/input/sleep.hcl
Normal file
@@ -0,0 +1,39 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
job "sleep" {
|
||||
constraint {
|
||||
attribute = "${attr.kernel.name}"
|
||||
value = "linux"
|
||||
}
|
||||
|
||||
group "group" {
|
||||
update {
|
||||
min_healthy_time = "4s"
|
||||
}
|
||||
|
||||
reschedule {
|
||||
attempts = 0
|
||||
unlimited = false
|
||||
}
|
||||
|
||||
restart {
|
||||
attempts = 0
|
||||
mode = "fail"
|
||||
}
|
||||
|
||||
task "task" {
|
||||
driver = "pledge"
|
||||
|
||||
config {
|
||||
command = "sleep"
|
||||
args = ["infinity"]
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 10
|
||||
memory = 32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
e2e/pledge/input/unveil.hcl
Normal file
34
e2e/pledge/input/unveil.hcl
Normal file
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
job "unveil" {
|
||||
type = "batch"
|
||||
|
||||
constraint {
|
||||
attribute = "${attr.kernel.name}"
|
||||
value = "linux"
|
||||
}
|
||||
|
||||
group "group" {
|
||||
|
||||
reschedule {
|
||||
attempts = 0
|
||||
unlimited = false
|
||||
}
|
||||
|
||||
restart {
|
||||
attempts = 0
|
||||
mode = "fail"
|
||||
}
|
||||
|
||||
task "cat" {
|
||||
driver = "pledge"
|
||||
config {
|
||||
command = "cat"
|
||||
args = ["/etc/passwd"]
|
||||
promises = "stdio rpath"
|
||||
unveil = ["r:/etc/passwd"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
64
e2e/pledge/pledge_test.go
Normal file
64
e2e/pledge/pledge_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package pledge
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/e2e/e2eutil"
|
||||
"github.com/hashicorp/nomad/e2e/v3/cluster3"
|
||||
"github.com/hashicorp/nomad/e2e/v3/jobs3"
|
||||
"github.com/shoenig/test/must"
|
||||
)
|
||||
|
||||
func TestPledge(t *testing.T) {
|
||||
cluster3.Establish(t,
|
||||
cluster3.Leader(),
|
||||
cluster3.LinuxClients(1),
|
||||
cluster3.Timeout(10*time.Second),
|
||||
)
|
||||
|
||||
t.Run("testSleep", testSleep)
|
||||
t.Run("testBridgeNetwork", testBridgeNetwork)
|
||||
t.Run("testUnveil", testUnveil)
|
||||
}
|
||||
|
||||
func testSleep(t *testing.T) {
|
||||
_, cleanup := jobs3.Submit(t, "./input/sleep.hcl")
|
||||
t.Cleanup(cleanup)
|
||||
}
|
||||
|
||||
func testBridgeNetwork(t *testing.T) {
|
||||
_, cleanup := jobs3.Submit(t, "./input/bridge.hcl")
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
ip, port := findService(t, "pybridge")
|
||||
address := fmt.Sprintf("http://%s:%d", ip, port)
|
||||
|
||||
curlJob, curlCleanup := jobs3.Submit(t, "./input/curl.hcl",
|
||||
jobs3.Var("address", address),
|
||||
jobs3.WaitComplete("curl"),
|
||||
)
|
||||
t.Cleanup(curlCleanup)
|
||||
|
||||
logs := curlJob.TaskLogs("group", "curl")
|
||||
must.StrContains(t, logs.Stdout, "<title>bridge mode</title>")
|
||||
}
|
||||
|
||||
func testUnveil(t *testing.T) {
|
||||
job, cleanup := jobs3.Submit(t, "./input/unveil.hcl")
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
logs := job.TaskLogs("group", "cat")
|
||||
must.StrContains(t, logs.Stdout, "root:x:0:0")
|
||||
}
|
||||
|
||||
// findService returns the service address and port
|
||||
func findService(t *testing.T, name string) (string, int) {
|
||||
services, _, err := e2eutil.NomadClient(t).Services().Get(name, nil)
|
||||
must.NoError(t, err)
|
||||
return services[0].Address, services[0].Port
|
||||
}
|
||||
@@ -41,3 +41,9 @@ plugin "docker" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin "nomad-pledge-driver" {
|
||||
config {
|
||||
pledge_executable = "/usr/local/bin/pledge"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ Build an AMI for the target configuration
|
||||
|
||||
Examples
|
||||
build ubuntu-jammy-amd64
|
||||
build windows-2016-amd64
|
||||
|
||||
EOF
|
||||
|
||||
|
||||
@@ -96,6 +96,15 @@ sudo apt-get -y install podman catatonit
|
||||
echo "Installing Podman Driver"
|
||||
sudo hc-install install --path ${NOMAD_PLUGIN_DIR} --version 0.4.2 nomad-driver-podman
|
||||
|
||||
# Pledge
|
||||
echo "Installing Pledge Driver"
|
||||
curl -fsSL -o /tmp/pledge-driver.tar.gz https://github.com/shoenig/nomad-pledge-driver/releases/download/v0.2.3/nomad-pledge-driver_0.2.3_linux_amd64.tar.gz
|
||||
curl -fsSL -o /tmp/pledge https://github.com/shoenig/nomad-pledge-driver/releases/download/pledge-1.8.com/pledge-1.8.com
|
||||
tar -C /tmp -xf /tmp/pledge-driver.tar.gz
|
||||
sudo mv /tmp/nomad-pledge-driver ${NOMAD_PLUGIN_DIR}
|
||||
sudo mv /tmp/pledge /usr/local/bin
|
||||
sudo chmod +x /usr/local/bin/pledge
|
||||
|
||||
# ECS
|
||||
if [ -a "/tmp/linux/nomad-driver-ecs" ]; then
|
||||
echo "Installing nomad-driver-ecs"
|
||||
|
||||
Reference in New Issue
Block a user