Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion depot/containerstore/containerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,12 @@ func (cs *containerStore) Destroy(logger lager.Logger, guid string) error {
err = node.Destroy(logger)
if err != nil {
logger.Error("failed-to-destroy-container", err)
return err
}

cs.containers.Remove(guid)

return err
return nil
}

func (cs *containerStore) Get(logger lager.Logger, guid string) (executor.Container, error) {
Expand Down
55 changes: 49 additions & 6 deletions depot/containerstore/containerstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2549,23 +2549,26 @@ var _ = Describe("Container Store", func() {
Eventually(getMetrics).Should(HaveKey(containerstore.GardenContainerDestructionFailedDuration))
})

It("does remove the container from the container store", func() {
It("does not remove the container from the container store", func() {
err := containerStore.Destroy(logger, containerGuid)
Expect(err).To(Equal(destroyErr))

Expect(gardenClient.DestroyCallCount()).To(Equal(1))
Expect(gardenClient.DestroyArgsForCall(0)).To(Equal(containerGuid))

_, err = containerStore.Get(logger, containerGuid)
Expect(err).To(Equal(executor.ErrContainerNotFound))
container, err := containerStore.Get(logger, containerGuid)
Expect(err).ToNot(HaveOccurred())
Expect(container.Guid).To(Equal(containerGuid))
})

It("frees the containers resources", func() {
It("does not free up the containers resources", func() {
err := containerStore.Destroy(logger, containerGuid)
Expect(err).To(Equal(destroyErr))

remainingResources := containerStore.RemainingResources(logger)
Expect(remainingResources).To(Equal(totalCapacity))
resources := containerStore.RemainingResources(logger)
expectedResources := totalCapacity.Copy()
expectedResources.Subtract(&resource)
Expect(resources).To(Equal(expectedResources))
})
})
})
Expand Down Expand Up @@ -2745,6 +2748,46 @@ var _ = Describe("Container Store", func() {
})
})
})

Context("when there are no process associated with the container", func() {
Context("when container is in completed state", func() {
JustBeforeEach(func() {
destroyErr := errors.New("failed-to-destroy-container")
gardenClient.DestroyReturns(destroyErr)
eventEmitter.EmitStub = func(e executor.Event) {
// processing completed container
defer GinkgoRecover()
if e.EventType() == executor.EventTypeContainerComplete {
// sleeping to avoid atomic destroying state
time.Sleep(time.Second)
err := containerStore.Destroy(logger, containerGuid)
Expect(err).To(HaveOccurred())
}
}
})

It("does not emit the completed event", func() {
// completed event will trigger Destroy for failed completed container and that will cause an infinite loop
Eventually(eventEmitter.EmitCallCount).Should(Equal(1))
event1 := eventEmitter.EmitArgsForCall(0)
Expect(event1.EventType()).To(Equal(executor.EventTypeContainerReserved))

err := containerStore.Destroy(logger, containerGuid)
Expect(err).To(HaveOccurred())

container, err := containerStore.Get(logger, containerGuid)
Expect(err).NotTo(HaveOccurred())

Eventually(eventEmitter.EmitCallCount).Should(Equal(2))
event2 := eventEmitter.EmitArgsForCall(1)
Expect(event2).To(Equal(executor.ContainerCompleteEvent{
RawContainer: container,
}))

Consistently(eventEmitter.EmitCallCount).Should(Equal(2))
})
})
})
})

Describe("Get", func() {
Expand Down
4 changes: 3 additions & 1 deletion depot/containerstore/storenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ func (n *storeNode) stop(logger lager.Logger) {
n.process.Signal(os.Interrupt)
logger.Debug("signalled-process")
} else {
n.complete(logger, true, "stopped-before-running", false)
if n.info.State != executor.StateCompleted {
n.complete(logger, true, "stopped-before-running", false)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type executorContainers struct {
func (containers *executorContainers) Containers() ([]garden.Container, error) {
return containers.gardenClient.Containers(garden.Properties{
executor.ContainerOwnerProperty: containers.owner,
executor.ContainerStateProperty: "all",
})
}

Expand Down
3 changes: 3 additions & 0 deletions initializer/initializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ var _ = Describe("Initializer", func() {
fakeGarden.RouteToHandler("GET", "/containers",
func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
gardenState := r.URL.Query()["garden.state"]
Expect(gardenState).To(HaveLen(1))
Expect(gardenState[0]).To(Equal("all"))
healthcheckTagQueryParam := gardenhealth.HealthcheckTag
if r.FormValue(healthcheckTagQueryParam) == gardenhealth.HealthcheckTagValue {
ghttp.RespondWithJSONEncoded(http.StatusOK, struct{}{})(w, r)
Expand Down
5 changes: 4 additions & 1 deletion resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"code.cloudfoundry.org/routing-info/internalroutes"
)

const ContainerOwnerProperty = "executor:owner"
const (
ContainerOwnerProperty = "executor:owner"
ContainerStateProperty = "garden.state"
)

type State string

Expand Down