From e2a8c7267b31305910bb69826e86f1f8cbb56dc8 Mon Sep 17 00:00:00 2001 From: Alessandro Degano Date: Fri, 11 Sep 2020 14:46:28 +0200 Subject: [PATCH] Fly execute: pass worker tags to input. Fix #5672. When issuing `fly execute` and selecting a platform where there are *only* tagged worker the command fails because DetermineInputs does not pass along the tags specified in the command and thus, at the end of the chain, SelectWorkers will return that no worker satisfy the request (because the are no untagged workers). This commit passes the worker tags along the chain so that the input can be set up. Signed-off-by: Alessandro Degano --- atc/api/artifactserver/create.go | 1 + fly/commands/execute.go | 1 + .../internal/executehelpers/inputs.go | 6 +++-- .../internal/executehelpers/uploads.go | 4 ++-- go-concourse/concourse/artifacts.go | 4 ++-- go-concourse/concourse/artifacts_test.go | 4 ++-- .../concourse/concoursefakes/fake_team.go | 23 ++++++++++++------- go-concourse/concourse/team.go | 2 +- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/atc/api/artifactserver/create.go b/atc/api/artifactserver/create.go index 94a7ab5f8..d26f98492 100644 --- a/atc/api/artifactserver/create.go +++ b/atc/api/artifactserver/create.go @@ -23,6 +23,7 @@ func (s *Server) CreateArtifact(team db.Team) http.Handler { workerSpec := worker.WorkerSpec{ TeamID: team.ID(), Platform: r.FormValue("platform"), + Tags: r.Form["tags"], } volumeSpec := worker.VolumeSpec{ diff --git a/fly/commands/execute.go b/fly/commands/execute.go index f8d41f19a..996d4d564 100644 --- a/fly/commands/execute.go +++ b/fly/commands/execute.go @@ -66,6 +66,7 @@ func (command *ExecuteCommand) Execute(args []string) error { command.InputsFrom, command.IncludeIgnored, taskConfig.Platform, + command.Tags, ) if err != nil { return err diff --git a/fly/commands/internal/executehelpers/inputs.go b/fly/commands/internal/executehelpers/inputs.go index 403befae4..e07f0920a 100644 --- a/fly/commands/internal/executehelpers/inputs.go +++ b/fly/commands/internal/executehelpers/inputs.go @@ -31,6 +31,7 @@ func DetermineInputs( inputsFrom flaghelpers.JobFlag, includeIgnored bool, platform string, + tags []string, ) ([]Input, map[string]string, *atc.ImageResource, atc.VersionedResourceTypes, error) { inputMappings := ConvertInputMappings(userInputMappings) @@ -74,7 +75,7 @@ func DetermineInputs( } } - inputsFromLocal, err := GenerateLocalInputs(fact, team, localInputMappings, includeIgnored, platform) + inputsFromLocal, err := GenerateLocalInputs(fact, team, localInputMappings, includeIgnored, platform, tags) if err != nil { return nil, nil, nil, nil, err } @@ -158,6 +159,7 @@ func GenerateLocalInputs( inputMappings []flaghelpers.InputPairFlag, includeIgnored bool, platform string, + tags []string, ) (map[string]Input, error) { inputs := map[string]Input{} @@ -170,7 +172,7 @@ func GenerateLocalInputs( path := mapping.Path prog.Go("uploading "+name, func(bar *mpb.Bar) error { - artifact, err := Upload(bar, team, path, includeIgnored, platform) + artifact, err := Upload(bar, team, path, includeIgnored, platform, tags) if err != nil { return err } diff --git a/fly/commands/internal/executehelpers/uploads.go b/fly/commands/internal/executehelpers/uploads.go index 61091afba..982c34631 100644 --- a/fly/commands/internal/executehelpers/uploads.go +++ b/fly/commands/internal/executehelpers/uploads.go @@ -12,7 +12,7 @@ import ( "github.com/vbauerster/mpb/v4" ) -func Upload(bar *mpb.Bar, team concourse.Team, path string, includeIgnored bool, platform string) (atc.WorkerArtifact, error) { +func Upload(bar *mpb.Bar, team concourse.Team, path string, includeIgnored bool, platform string, tags []string) (atc.WorkerArtifact, error) { files := getFiles(path, includeIgnored) archiveStream, archiveWriter := io.Pipe() @@ -21,7 +21,7 @@ func Upload(bar *mpb.Bar, team concourse.Team, path string, includeIgnored bool, archiveWriter.CloseWithError(tgzfs.Compress(archiveWriter, path, files...)) }() - return team.CreateArtifact(bar.ProxyReader(archiveStream), platform) + return team.CreateArtifact(bar.ProxyReader(archiveStream), platform, tags) } func getFiles(dir string, includeIgnored bool) []string { diff --git a/go-concourse/concourse/artifacts.go b/go-concourse/concourse/artifacts.go index bd8303dd6..6363dbbe0 100644 --- a/go-concourse/concourse/artifacts.go +++ b/go-concourse/concourse/artifacts.go @@ -11,7 +11,7 @@ import ( "github.com/tedsuo/rata" ) -func (team *team) CreateArtifact(src io.Reader, platform string) (atc.WorkerArtifact, error) { +func (team *team) CreateArtifact(src io.Reader, platform string, tags []string) (atc.WorkerArtifact, error) { var artifact atc.WorkerArtifact params := rata.Params{ @@ -22,7 +22,7 @@ func (team *team) CreateArtifact(src io.Reader, platform string) (atc.WorkerArti Header: http.Header{"Content-Type": {"application/octet-stream"}}, RequestName: atc.CreateArtifact, Params: params, - Query: url.Values{"platform": {platform}}, + Query: url.Values{"platform": {platform}, "tags": tags}, Body: src, }, &internal.Response{ Result: &artifact, diff --git a/go-concourse/concourse/artifacts_test.go b/go-concourse/concourse/artifacts_test.go index b8533f76c..80346df3b 100644 --- a/go-concourse/concourse/artifacts_test.go +++ b/go-concourse/concourse/artifacts_test.go @@ -27,7 +27,7 @@ var _ = Describe("ArtifactRepository", func() { }) It("errors", func() { - _, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform") + _, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform", []string{"some-tags"}) Expect(err).To(HaveOccurred()) }) }) @@ -45,7 +45,7 @@ var _ = Describe("ArtifactRepository", func() { }) It("returns json", func() { - artifact, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform") + artifact, err := team.CreateArtifact(bytes.NewBufferString("some-contents"), "some-platform", []string{"some-tags"}) Expect(err).NotTo(HaveOccurred()) Expect(artifact.ID).To(Equal(17)) }) diff --git a/go-concourse/concourse/concoursefakes/fake_team.go b/go-concourse/concourse/concoursefakes/fake_team.go index 71a254529..193d0bc0c 100644 --- a/go-concourse/concourse/concoursefakes/fake_team.go +++ b/go-concourse/concourse/concoursefakes/fake_team.go @@ -148,11 +148,12 @@ type FakeTeam struct { result1 int64 result2 error } - CreateArtifactStub func(io.Reader, string) (atc.WorkerArtifact, error) + CreateArtifactStub func(io.Reader, string, []string) (atc.WorkerArtifact, error) createArtifactMutex sync.RWMutex createArtifactArgsForCall []struct { arg1 io.Reader arg2 string + arg3 []string } createArtifactReturns struct { result1 atc.WorkerArtifact @@ -1334,17 +1335,23 @@ func (fake *FakeTeam) ClearTaskCacheReturnsOnCall(i int, result1 int64, result2 }{result1, result2} } -func (fake *FakeTeam) CreateArtifact(arg1 io.Reader, arg2 string) (atc.WorkerArtifact, error) { +func (fake *FakeTeam) CreateArtifact(arg1 io.Reader, arg2 string, arg3 []string) (atc.WorkerArtifact, error) { + var arg3Copy []string + if arg3 != nil { + arg3Copy = make([]string, len(arg3)) + copy(arg3Copy, arg3) + } fake.createArtifactMutex.Lock() ret, specificReturn := fake.createArtifactReturnsOnCall[len(fake.createArtifactArgsForCall)] fake.createArtifactArgsForCall = append(fake.createArtifactArgsForCall, struct { arg1 io.Reader arg2 string - }{arg1, arg2}) - fake.recordInvocation("CreateArtifact", []interface{}{arg1, arg2}) + arg3 []string + }{arg1, arg2, arg3Copy}) + fake.recordInvocation("CreateArtifact", []interface{}{arg1, arg2, arg3Copy}) fake.createArtifactMutex.Unlock() if fake.CreateArtifactStub != nil { - return fake.CreateArtifactStub(arg1, arg2) + return fake.CreateArtifactStub(arg1, arg2, arg3) } if specificReturn { return ret.result1, ret.result2 @@ -1359,17 +1366,17 @@ func (fake *FakeTeam) CreateArtifactCallCount() int { return len(fake.createArtifactArgsForCall) } -func (fake *FakeTeam) CreateArtifactCalls(stub func(io.Reader, string) (atc.WorkerArtifact, error)) { +func (fake *FakeTeam) CreateArtifactCalls(stub func(io.Reader, string, []string) (atc.WorkerArtifact, error)) { fake.createArtifactMutex.Lock() defer fake.createArtifactMutex.Unlock() fake.CreateArtifactStub = stub } -func (fake *FakeTeam) CreateArtifactArgsForCall(i int) (io.Reader, string) { +func (fake *FakeTeam) CreateArtifactArgsForCall(i int) (io.Reader, string, []string) { fake.createArtifactMutex.RLock() defer fake.createArtifactMutex.RUnlock() argsForCall := fake.createArtifactArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } func (fake *FakeTeam) CreateArtifactReturns(result1 atc.WorkerArtifact, result2 error) { diff --git a/go-concourse/concourse/team.go b/go-concourse/concourse/team.go index 819c4fa17..568dbfc22 100644 --- a/go-concourse/concourse/team.go +++ b/go-concourse/concourse/team.go @@ -71,7 +71,7 @@ type Team interface { Builds(page Page) ([]atc.Build, Pagination, error) OrderingPipelines(pipelineNames []string) error - CreateArtifact(io.Reader, string) (atc.WorkerArtifact, error) + CreateArtifact(io.Reader, string, []string) (atc.WorkerArtifact, error) GetArtifact(int) (io.ReadCloser, error) }