engine: resources: docker: Make a few fixups
Here are a few fixups to the docker resources. All miscellaneous stuff, nothing major.
This commit is contained in:
@@ -50,8 +50,8 @@ const (
|
|||||||
// initCtxTimeout is the length of time, in seconds, before requests are
|
// initCtxTimeout is the length of time, in seconds, before requests are
|
||||||
// cancelled in Init.
|
// cancelled in Init.
|
||||||
initCtxTimeout = 20
|
initCtxTimeout = 20
|
||||||
// checkApplyCtxTimeout is the length of time, in seconds, before requests
|
// checkApplyCtxTimeout is the length of time, in seconds, before
|
||||||
// are cancelled in CheckApply.
|
// requests are cancelled in CheckApply.
|
||||||
checkApplyCtxTimeout = 120
|
checkApplyCtxTimeout = 120
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -74,11 +74,12 @@ type DockerContainerRes struct {
|
|||||||
Env []string `yaml:"env"`
|
Env []string `yaml:"env"`
|
||||||
// Ports is a map of port bindings. E.g. {"tcp" => {80 => 8080},}.
|
// Ports is a map of port bindings. E.g. {"tcp" => {80 => 8080},}.
|
||||||
Ports map[string]map[int64]int64 `yaml:"ports"`
|
Ports map[string]map[int64]int64 `yaml:"ports"`
|
||||||
// APIVersion allows you to override the host's default client API version.
|
// APIVersion allows you to override the host's default client API
|
||||||
|
// version.
|
||||||
APIVersion string `yaml:"apiversion"`
|
APIVersion string `yaml:"apiversion"`
|
||||||
|
|
||||||
// Force, if true, will destroy and redeploy the container if the image is
|
// Force, if true, this will destroy and redeploy the container if the
|
||||||
// incorrect.
|
// image is incorrect.
|
||||||
Force bool `yaml:"force"`
|
Force bool `yaml:"force"`
|
||||||
|
|
||||||
client *client.Client // docker api client
|
client *client.Client // docker api client
|
||||||
@@ -374,30 +375,34 @@ func (obj *DockerContainerRes) Cmp(r engine.Res) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("error casting r to *DockerContainerRes")
|
return fmt.Errorf("error casting r to *DockerContainerRes")
|
||||||
}
|
}
|
||||||
if obj.Name() != res.Name() {
|
|
||||||
return fmt.Errorf("names differ")
|
if obj.State != res.State {
|
||||||
|
return fmt.Errorf("the State differs")
|
||||||
|
}
|
||||||
|
if obj.Image != res.Image {
|
||||||
|
return fmt.Errorf("the Image differs")
|
||||||
}
|
}
|
||||||
if err := util.SortedStrSliceCompare(obj.Cmd, res.Cmd); err != nil {
|
if err := util.SortedStrSliceCompare(obj.Cmd, res.Cmd); err != nil {
|
||||||
return errwrap.Wrapf(err, "cmd differs")
|
return errwrap.Wrapf(err, "the Cmd field differs")
|
||||||
}
|
}
|
||||||
if err := util.SortedStrSliceCompare(obj.Env, res.Env); err != nil {
|
if err := util.SortedStrSliceCompare(obj.Env, res.Env); err != nil {
|
||||||
return errwrap.Wrapf(err, "env differs")
|
return errwrap.Wrapf(err, "tne Env field differs")
|
||||||
}
|
}
|
||||||
if len(obj.Ports) != len(res.Ports) {
|
if len(obj.Ports) != len(res.Ports) {
|
||||||
return fmt.Errorf("ports length differs")
|
return fmt.Errorf("the Ports length differs")
|
||||||
}
|
}
|
||||||
for k, v := range obj.Ports {
|
for k, v := range obj.Ports {
|
||||||
for p, q := range v {
|
for p, q := range v {
|
||||||
if w, ok := res.Ports[k][p]; !ok || q != w {
|
if w, ok := res.Ports[k][p]; !ok || q != w {
|
||||||
return fmt.Errorf("ports differ")
|
return fmt.Errorf("the Ports field differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if obj.APIVersion != res.APIVersion {
|
if obj.APIVersion != res.APIVersion {
|
||||||
return fmt.Errorf("apiversions differ")
|
return fmt.Errorf("the APIVersion differs")
|
||||||
}
|
}
|
||||||
if obj.Force != res.Force {
|
if obj.Force != res.Force {
|
||||||
return fmt.Errorf("forces differ")
|
return fmt.Errorf("The Force field differs")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -405,6 +410,7 @@ func (obj *DockerContainerRes) Cmp(r engine.Res) error {
|
|||||||
// DockerContainerUID is the UID struct for DockerContainerRes.
|
// DockerContainerUID is the UID struct for DockerContainerRes.
|
||||||
type DockerContainerUID struct {
|
type DockerContainerUID struct {
|
||||||
engine.BaseUID
|
engine.BaseUID
|
||||||
|
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// dockerImageInitCtxTimeout is the length of time, in seconds, before requests are
|
// dockerImageInitCtxTimeout is the length of time, in seconds, before
|
||||||
// cancelled in Init.
|
// requests are cancelled in Init.
|
||||||
dockerImageInitCtxTimeout = 20
|
dockerImageInitCtxTimeout = 20
|
||||||
// dockerImageCheckApplyCtxTimeout is the length of time, in seconds, before requests
|
// dockerImageCheckApplyCtxTimeout is the length of time, in seconds,
|
||||||
// are cancelled in CheckApply.
|
// before requests are cancelled in CheckApply.
|
||||||
dockerImageCheckApplyCtxTimeout = 120
|
dockerImageCheckApplyCtxTimeout = 120
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,14 +50,15 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DockerImageRes is a docker image resource. The resource's name must be a
|
// DockerImageRes is a docker image resource. The resource's name must be a
|
||||||
// be a docker image in any supported format (url, image, or image:tag).
|
// docker image in any supported format (url, image, or image:tag).
|
||||||
type DockerImageRes struct {
|
type DockerImageRes struct {
|
||||||
traits.Base // add the base methods without re-implementation
|
traits.Base // add the base methods without re-implementation
|
||||||
traits.Edgeable
|
traits.Edgeable
|
||||||
|
|
||||||
// State of the image must be exists or absent.
|
// State of the image must be exists or absent.
|
||||||
State string `yaml:"state"`
|
State string `yaml:"state"`
|
||||||
// APIVersion allows you to override the host's default client API version.
|
// APIVersion allows you to override the host's default client API
|
||||||
|
// version.
|
||||||
APIVersion string `yaml:"apiversion"`
|
APIVersion string `yaml:"apiversion"`
|
||||||
|
|
||||||
image string // full image:tag format
|
image string // full image:tag format
|
||||||
@@ -69,6 +70,8 @@ type DockerImageRes struct {
|
|||||||
// Default returns some sensible defaults for this resource.
|
// Default returns some sensible defaults for this resource.
|
||||||
func (obj *DockerImageRes) Default() engine.Res {
|
func (obj *DockerImageRes) Default() engine.Res {
|
||||||
return &DockerImageRes{
|
return &DockerImageRes{
|
||||||
|
// TODO: eventually if image supports other properties, this can
|
||||||
|
// be left out and we could have the state be "unmanaged".
|
||||||
State: "exists",
|
State: "exists",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,11 +224,12 @@ func (obj *DockerImageRes) Cmp(r engine.Res) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("error casting r to *DockerImageRes")
|
return fmt.Errorf("error casting r to *DockerImageRes")
|
||||||
}
|
}
|
||||||
if obj.Name() != res.Name() {
|
if obj.State != res.State {
|
||||||
return fmt.Errorf("names differ")
|
return fmt.Errorf("the State differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.APIVersion != res.APIVersion {
|
if obj.APIVersion != res.APIVersion {
|
||||||
return fmt.Errorf("apiversions differ")
|
return fmt.Errorf("the APIVersion differs")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -233,6 +237,7 @@ func (obj *DockerImageRes) Cmp(r engine.Res) error {
|
|||||||
// DockerImageUID is the UID struct for DockerImageRes.
|
// DockerImageUID is the UID struct for DockerImageRes.
|
||||||
type DockerImageUID struct {
|
type DockerImageUID struct {
|
||||||
engine.BaseUID
|
engine.BaseUID
|
||||||
|
|
||||||
image string
|
image string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user