Merge pull request #4793 from hashicorp/b-no-cty

Do not use cty in drivers
This commit is contained in:
Alex Dadgar
2018-10-16 20:04:41 -07:00
committed by GitHub
4 changed files with 41 additions and 44 deletions

View File

@@ -134,12 +134,12 @@ type Config struct {
// ShutdownPeriodicAfter is a toggle that can be used during tests to
// "stop" a previously-functioning driver, allowing for testing of periodic
// drivers and fingerprinters
ShutdownPeriodicAfter bool `cty:"shutdown_periodic_after"`
ShutdownPeriodicAfter bool `codec:"shutdown_periodic_after"`
// ShutdownPeriodicDuration is a option that can be used during tests
// to "stop" a previously functioning driver after the specified duration
// for testing of periodic drivers and fingerprinters.
ShutdownPeriodicDuration time.Duration `cty:"shutdown_periodic_duration"`
ShutdownPeriodicDuration time.Duration `codec:"shutdown_periodic_duration"`
}
// TaskConfig is the driver configuration of a task within a job
@@ -147,56 +147,56 @@ type TaskConfig struct {
// StartErr specifies the error that should be returned when starting the
// mock driver.
StartErr string `cty:"start_error"`
StartErr string `codec:"start_error"`
// StartErrRecoverable marks the error returned is recoverable
StartErrRecoverable bool `cty:"start_error_recoverable"`
StartErrRecoverable bool `codec:"start_error_recoverable"`
// StartBlockFor specifies a duration in which to block before returning
StartBlockFor time.Duration `cty:"start_block_for"`
StartBlockFor time.Duration `codec:"start_block_for"`
// KillAfter is the duration after which the mock driver indicates the task
// has exited after getting the initial SIGINT signal
KillAfter time.Duration `cty:"kill_after"`
KillAfter time.Duration `codec:"kill_after"`
// RunFor is the duration for which the fake task runs for. After this
// period the MockDriver responds to the task running indicating that the
// task has terminated
RunFor time.Duration `cty:"run_for"`
RunFor time.Duration `codec:"run_for"`
// ExitCode is the exit code with which the MockDriver indicates the task
// has exited
ExitCode int `cty:"exit_code"`
ExitCode int `codec:"exit_code"`
// ExitSignal is the signal with which the MockDriver indicates the task has
// been killed
ExitSignal int `cty:"exit_signal"`
ExitSignal int `codec:"exit_signal"`
// ExitErrMsg is the error message that the task returns while exiting
ExitErrMsg string `cty:"exit_err_msg"`
ExitErrMsg string `codec:"exit_err_msg"`
// SignalErr is the error message that the task returns if signalled
SignalErr string `cty:"signal_error"`
SignalErr string `codec:"signal_error"`
// DriverIP will be returned as the DriverNetwork.IP from Start()
DriverIP string `cty:"driver_ip"`
DriverIP string `codec:"driver_ip"`
// DriverAdvertise will be returned as DriverNetwork.AutoAdvertise from
// Start().
DriverAdvertise bool `cty:"driver_advertise"`
DriverAdvertise bool `codec:"driver_advertise"`
// DriverPortMap will parse a label:number pair and return it in
// DriverNetwork.PortMap from Start().
DriverPortMap string `cty:"driver_port_map"`
DriverPortMap string `codec:"driver_port_map"`
// StdoutString is the string that should be sent to stdout
StdoutString string `cty:"stdout_string"`
StdoutString string `codec:"stdout_string"`
// StdoutRepeat is the number of times the output should be sent.
StdoutRepeat int `cty:"stdout_repeat"`
StdoutRepeat int `codec:"stdout_repeat"`
// StdoutRepeatDur is the duration between repeated outputs.
StdoutRepeatDur time.Duration `cty:"stdout_repeat_duration"`
StdoutRepeatDur time.Duration `codec:"stdout_repeat_duration"`
}
type MockTaskState struct {

View File

@@ -125,16 +125,16 @@ type RawExecDriver struct {
type Config struct {
// NoCgroups tracks whether we should use a cgroup to manage the process
// tree
NoCgroups bool `codec:"no_cgroups" cty:"no_cgroups"`
NoCgroups bool `codec:"no_cgroups"`
// Enabled is set to true to enable the raw_exec driver
Enabled bool `codec:"enabled" cty:"enabled"`
Enabled bool `codec:"enabled"`
}
// TaskConfig is the driver configuration of a task within a job
type TaskConfig struct {
Command string `codec:"command" cty:"command"`
Args []string `codec:"args" cty:"args"`
Command string `codec:"command"`
Args []string `codec:"args"`
}
// RawExecTaskState is the state which is encoded in the handle returned in

View File

@@ -4,22 +4,28 @@ package rkt
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
"time"
appcschema "github.com/appc/spec/schema"
"github.com/hashicorp/consul-template/signals"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-version"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/driver/env"
"github.com/hashicorp/nomad/client/driver/executor"
dstructs "github.com/hashicorp/nomad/client/driver/structs"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
@@ -29,14 +35,6 @@ import (
"github.com/hashicorp/nomad/plugins/shared/hclspec"
rktv1 "github.com/rkt/rkt/api/v1"
"golang.org/x/net/context"
"encoding/json"
"io/ioutil"
"math/rand"
"strconv"
"github.com/hashicorp/consul-template/signals"
"github.com/hashicorp/nomad/client/driver/executor"
)
const (
@@ -85,7 +83,7 @@ var (
"dns_servers": hclspec.NewAttr("dns_servers", "list(string)", false),
"dns_search_domains": hclspec.NewAttr("dns_search_domains", "list(string)", false),
"net": hclspec.NewAttr("net", "list(string)", false),
"port_map": hclspec.NewAttr("port_map", "map(string)", false),
"port_map": hclspec.NewBlockAttrs("port_map", "string", false),
"volumes": hclspec.NewAttr("volumes", "list(string)", false),
"insecure_options": hclspec.NewAttr("insecure_options", "list(string)", false),
"no_overlay": hclspec.NewAttr("no_overlay", "bool", false),
@@ -115,20 +113,20 @@ type Config struct {
// TaskConfig is the driver configuration of a taskConfig within a job
type TaskConfig struct {
ImageName string `codec:"image" cty:"image"`
Command string `codec:"command" cty:"command"`
Args []string `codec:"args" cty:"args"`
TrustPrefix string `codec:"trust_prefix" cty:"trust_prefix"`
DNSServers []string `codec:"dns_servers" cty:"dns_servers"` // DNS Server for containers
DNSSearchDomains []string `codec:"dns_search_domains" cty:"dns_search_domains"` // DNS Search domains for containers
Net []string `codec:"net" cty:"net"` // Networks for the containers
PortMap map[string]string `codec:"port_map" cty:"port_map"` // A map of host port and the port name defined in the image manifest file
Volumes []string `codec:"volumes" cty:"volumes"` // Host-Volumes to mount in, syntax: /path/to/host/directory:/destination/path/in/container[:readOnly]
InsecureOptions []string `codec:"insecure_options" cty:"insecure_options"` // list of args for --insecure-options
ImageName string `codec:"image"`
Command string `codec:"command"`
Args []string `codec:"args"`
TrustPrefix string `codec:"trust_prefix"`
DNSServers []string `codec:"dns_servers"` // DNS Server for containers
DNSSearchDomains []string `codec:"dns_search_domains"` // DNS Search domains for containers
Net []string `codec:"net"` // Networks for the containers
PortMap map[string]string `codec:"port_map"` // A map of host port and the port name defined in the image manifest file
Volumes []string `codec:"volumes"` // Host-Volumes to mount in, syntax: /path/to/host/directory:/destination/path/in/container[:readOnly]
InsecureOptions []string `codec:"insecure_options"` // list of args for --insecure-options
NoOverlay bool `codec:"no_overlay" cty:"no_overlay"` // disable overlayfs for rkt run
Debug bool `codec:"debug" cty:"debug"` // Enable debug option for rkt command
Group string `codec:"group" cty:"group"` // Group override for the container
NoOverlay bool `codec:"no_overlay"` // disable overlayfs for rkt run
Debug bool `codec:"debug"` // Enable debug option for rkt command
Group string `codec:"group"` // Group override for the container
}
// RktTaskState is the state which is encoded in the handle returned in

View File

@@ -54,7 +54,6 @@ func (p *PluginBase) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker,
var MsgpackHandle = func() *codec.MsgpackHandle {
h := &codec.MsgpackHandle{}
h.RawToString = true
h.TypeInfos = codec.NewTypeInfos([]string{"cty", "codec"})
h.MapType = reflect.TypeOf(map[string]interface{}(nil))
return h
}()