Ejemplo n.º 1
0
func (worker *gardenWorker) CreateContainer(
	logger lager.Logger,
	cancel <-chan os.Signal,
	delegate ImageFetchingDelegate,
	id Identifier,
	metadata Metadata,
	spec ContainerSpec,
	customTypes atc.ResourceTypes,
) (Container, error) {
	gardenContainerSpecFactory := NewGardenContainerSpecFactory(logger, worker.baggageclaimClient, worker.imageFetcher)

	gardenSpec, err := gardenContainerSpecFactory.BuildContainerSpec(spec, worker.resourceTypes, cancel, delegate, id, metadata, worker, customTypes)
	defer gardenContainerSpecFactory.ReleaseVolumes()
	if err != nil {
		return nil, err
	}

	gardenContainer, err := worker.gardenClient.Create(gardenSpec)
	if err != nil {
		return nil, err
	}

	metadata.WorkerName = worker.name
	metadata.Handle = gardenContainer.Handle()
	metadata.User = gardenSpec.Properties["user"]
	_, err = worker.db.CreateContainer(
		db.Container{
			ContainerIdentifier: db.ContainerIdentifier(id),
			ContainerMetadata:   db.ContainerMetadata(metadata),
		},
		containerTTL,
	)
	if err != nil {
		return nil, err
	}

	return newGardenWorkerContainer(
		logger,
		gardenContainer,
		worker.gardenClient,
		worker.baggageclaimClient,
		worker.db,
		worker.clock,
		worker.volumeFactory,
	)
}
Ejemplo n.º 2
0
func (provider *dbProvider) FindContainerForIdentifier(id Identifier) (db.Container, bool, error) {
	return provider.db.FindContainerByIdentifier(db.ContainerIdentifier(id))
}
Ejemplo n.º 3
0
					It("succeeds", func() {
						Expect(createErr).NotTo(HaveOccurred())
					})

					It("creates the container with the Garden client", func() {
						Expect(fakeGardenClient.CreateCallCount()).To(Equal(1))
						Expect(fakeGardenClient.CreateArgsForCall(0)).To(Equal(garden.ContainerSpec{
							RootFSPath: "some-resource-image",
							Privileged: true,
							Properties: garden.Properties{},
						}))
					})

					It("creates the container info in the database", func() {
						expectedIdentifier := db.ContainerIdentifier(id)
						expectedIdentifier.WorkerName = "my-garden-worker"

						container := db.Container{
							Handle:              "some-handle",
							ContainerIdentifier: expectedIdentifier,
						}

						Expect(fakeGardenWorkerDB.CreateContainerCallCount()).To(Equal(1))
						actualContainer, ttl := fakeGardenWorkerDB.CreateContainerArgsForCall(0)
						Expect(actualContainer).To(Equal(container))
						Expect(ttl).To(Equal(5 * time.Minute))
					})

					Context("when creating the container info in the db fails", func() {
						disaster := errors.New("bad")