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:
James Shubin
2020-01-03 00:53:20 -05:00
parent 8174b88ec3
commit 456550c1d4
2 changed files with 33 additions and 22 deletions

View File

@@ -50,8 +50,8 @@ const (
// initCtxTimeout is the length of time, in seconds, before requests are
// cancelled in Init.
initCtxTimeout = 20
// checkApplyCtxTimeout is the length of time, in seconds, before requests
// are cancelled in CheckApply.
// checkApplyCtxTimeout is the length of time, in seconds, before
// requests are cancelled in CheckApply.
checkApplyCtxTimeout = 120
)
@@ -74,11 +74,12 @@ type DockerContainerRes struct {
Env []string `yaml:"env"`
// Ports is a map of port bindings. E.g. {"tcp" => {80 => 8080},}.
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"`
// Force, if true, will destroy and redeploy the container if the image is
// incorrect.
// Force, if true, this will destroy and redeploy the container if the
// image is incorrect.
Force bool `yaml:"force"`
client *client.Client // docker api client
@@ -374,30 +375,34 @@ func (obj *DockerContainerRes) Cmp(r engine.Res) error {
if !ok {
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 {
return errwrap.Wrapf(err, "cmd differs")
return errwrap.Wrapf(err, "the Cmd field differs")
}
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) {
return fmt.Errorf("ports length differs")
return fmt.Errorf("the Ports length differs")
}
for k, v := range obj.Ports {
for p, q := range v {
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 {
return fmt.Errorf("apiversions differ")
return fmt.Errorf("the APIVersion differs")
}
if obj.Force != res.Force {
return fmt.Errorf("forces differ")
return fmt.Errorf("The Force field differs")
}
return nil
}
@@ -405,6 +410,7 @@ func (obj *DockerContainerRes) Cmp(r engine.Res) error {
// DockerContainerUID is the UID struct for DockerContainerRes.
type DockerContainerUID struct {
engine.BaseUID
name string
}

View File

@@ -37,11 +37,11 @@ import (
)
const (
// dockerImageInitCtxTimeout is the length of time, in seconds, before requests are
// cancelled in Init.
// dockerImageInitCtxTimeout is the length of time, in seconds, before
// requests are cancelled in Init.
dockerImageInitCtxTimeout = 20
// dockerImageCheckApplyCtxTimeout is the length of time, in seconds, before requests
// are cancelled in CheckApply.
// dockerImageCheckApplyCtxTimeout is the length of time, in seconds,
// before requests are cancelled in CheckApply.
dockerImageCheckApplyCtxTimeout = 120
)
@@ -50,14 +50,15 @@ func init() {
}
// 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 {
traits.Base // add the base methods without re-implementation
traits.Edgeable
// State of the image must be exists or absent.
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"`
image string // full image:tag format
@@ -69,6 +70,8 @@ type DockerImageRes struct {
// Default returns some sensible defaults for this resource.
func (obj *DockerImageRes) Default() engine.Res {
return &DockerImageRes{
// TODO: eventually if image supports other properties, this can
// be left out and we could have the state be "unmanaged".
State: "exists",
}
}
@@ -221,11 +224,12 @@ func (obj *DockerImageRes) Cmp(r engine.Res) error {
if !ok {
return fmt.Errorf("error casting r to *DockerImageRes")
}
if obj.Name() != res.Name() {
return fmt.Errorf("names differ")
if obj.State != res.State {
return fmt.Errorf("the State differs")
}
if obj.APIVersion != res.APIVersion {
return fmt.Errorf("apiversions differ")
return fmt.Errorf("the APIVersion differs")
}
return nil
}
@@ -233,6 +237,7 @@ func (obj *DockerImageRes) Cmp(r engine.Res) error {
// DockerImageUID is the UID struct for DockerImageRes.
type DockerImageUID struct {
engine.BaseUID
image string
}