Exemplo n.º 1
0
func (pair configPair) Equal() bool {
	conf := pair.Config
	cont := pair.Container

	if (conf.Memory / 1024 / 1024) != int64(cont.Memory) {
		return false
	}
	if conf.CPUShares != int64(cont.Cpu) {
		return false
	}
	if conf.Image != cont.Image {
		return false
	}
	if cont.EntryPoint == nil && !utils.StrSliceEqual(conf.Entrypoint, []string{}) {
		return false
	}
	if cont.EntryPoint != nil && !utils.StrSliceEqual(conf.Entrypoint, *cont.EntryPoint) {
		return false
	}
	if !utils.StrSliceEqual(cont.Command, conf.Cmd) {
		return false
	}
	// TODO, Volumes, VolumesFrom, ExposedPorts

	return true
}
Exemplo n.º 2
0
// ContainerOverridesEqual determines if two container overrides are equal
func ContainerOverridesEqual(lhs, rhs api.ContainerOverrides) bool {
	if lhs.Command == nil || rhs.Command == nil {
		if lhs.Command != rhs.Command {
			return false
		}
	} else {
		if !utils.StrSliceEqual(*lhs.Command, *rhs.Command) {
			return false
		}
	}

	return true
}
Exemplo n.º 3
0
// ContainersEqual determines if this container is equal to another container.
// This is not exact equality, but logical equality.
// TODO: use reflection along with `equal:"unordered"` annotations on slices to
// replace this verbose code (low priority, but would be fun)
func ContainersEqual(lhs, rhs *api.Container) bool {
	if lhs == rhs {
		return true
	}
	if lhs.Name != rhs.Name || lhs.Image != rhs.Image {
		return false
	}

	if !utils.StrSliceEqual(lhs.Command, rhs.Command) {
		return false
	}
	if lhs.Cpu != rhs.Cpu || lhs.Memory != rhs.Memory {
		return false
	}
	// Order doesn't matter
	if !utils.SlicesDeepEqual(lhs.Links, rhs.Links) {
		return false
	}
	if !utils.SlicesDeepEqual(lhs.VolumesFrom, rhs.VolumesFrom) {
		return false
	}
	if !utils.SlicesDeepEqual(lhs.MountPoints, rhs.MountPoints) {
		return false
	}
	if !utils.SlicesDeepEqual(lhs.Ports, rhs.Ports) {
		return false
	}
	if !utils.SlicesDeepEqual(lhs.KnownPortBindings, rhs.KnownPortBindings) {
		return false
	}
	if lhs.Essential != rhs.Essential {
		return false
	}
	if lhs.EntryPoint == nil || rhs.EntryPoint == nil {
		if lhs.EntryPoint != rhs.EntryPoint {
			return false
		}
		// both nil
	} else {
		if !utils.StrSliceEqual(*lhs.EntryPoint, *rhs.EntryPoint) {
			return false
		}
	}
	if !reflect.DeepEqual(lhs.Environment, rhs.Environment) {
		return false
	}
	if !ContainerOverridesEqual(lhs.Overrides, rhs.Overrides) {
		return false
	}
	if lhs.DesiredStatus != rhs.DesiredStatus || lhs.KnownStatus != rhs.KnownStatus {
		return false
	}
	if lhs.AppliedStatus != rhs.AppliedStatus {
		return false
	}
	if lhs.KnownExitCode == nil || rhs.KnownExitCode == nil {
		if lhs.KnownExitCode != nil || rhs.KnownExitCode != nil {
			return false
		}
	} else {
		if *lhs.KnownExitCode != *rhs.KnownExitCode {
			return false
		}
	}

	return true
}