github.com/hernad/nomad@v1.6.112/e2e/e2eutil/input/disconnect-node.nomad (about)

     1  # Copyright (c) HashiCorp, Inc.
     2  # SPDX-License-Identifier: MPL-2.0
     3  
     4  variable "nodeID" {
     5    type = string
     6  }
     7  
     8  variable "time" {
     9    type    = string
    10    default = "0"
    11  }
    12  
    13  job "disconnect-node" {
    14    type        = "batch"
    15    datacenters = ["dc1", "dc2"]
    16  
    17    group "group" {
    18  
    19      reschedule {
    20        attempts  = 0
    21        unlimited = false
    22      }
    23  
    24      # need to prevent the task from being restarted on reconnect, if
    25      # we're stopped long enough for the node to be marked down
    26      max_client_disconnect = "1h"
    27  
    28      constraint {
    29        attribute = "${attr.kernel.name}"
    30        value     = "linux"
    31      }
    32      constraint {
    33        attribute = "${node.unique.id}"
    34        value     = "${var.nodeID}"
    35      }
    36  
    37      task "task" {
    38        driver = "raw_exec"
    39        user   = "root"
    40        config {
    41          command = "/bin/sh"
    42          args = ["-c",
    43            # before disconnecting, we need to sleep long enough for the
    44            # task to register itself, otherwise we end up trying to
    45            # re-run the task immediately on reconnect
    46          "sleep 5; iptables -I OUTPUT -p tcp --dport 4647 -j DROP; sleep ${var.time}; iptables -D OUTPUT -p tcp --dport 4647 -j DROP"]
    47        }
    48      }
    49  
    50    }
    51  }