worker: require workers to pass their architecture
Jobs are scheduled with type "osbuild:{arch}", to ensure that workers
only get jobs with the right architecture assigned.
This commit is contained in:
parent
44c2144994
commit
9008a1defc
10 changed files with 59 additions and 19 deletions
|
|
@ -17,6 +17,7 @@ type Error struct {
|
|||
|
||||
// RequestJobJSONBody defines parameters for RequestJob.
|
||||
type RequestJobJSONBody struct {
|
||||
Arch string `json:"arch"`
|
||||
Types []string `json:"types"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,8 +90,11 @@ paths:
|
|||
type: string
|
||||
enum:
|
||||
- osbuild
|
||||
arch:
|
||||
type: string
|
||||
required:
|
||||
- types
|
||||
- arch
|
||||
description: ''
|
||||
description: Requests a job. This operation blocks until a job is available.
|
||||
parameters: []
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ func (c *Client) RequestJob() (Job, error) {
|
|||
var buf bytes.Buffer
|
||||
err = json.NewEncoder(&buf).Encode(api.RequestJobJSONRequestBody{
|
||||
Types: []string{"osbuild"},
|
||||
Arch: common.CurrentArch(),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
|
|
@ -88,13 +88,13 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
|||
s.server.Handler.ServeHTTP(writer, request)
|
||||
}
|
||||
|
||||
func (s *Server) Enqueue(manifest distro.Manifest, targets []*target.Target) (uuid.UUID, error) {
|
||||
func (s *Server) Enqueue(arch string, manifest distro.Manifest, targets []*target.Target) (uuid.UUID, error) {
|
||||
job := OSBuildJob{
|
||||
Manifest: manifest,
|
||||
Targets: targets,
|
||||
}
|
||||
|
||||
return s.jobs.Enqueue("osbuild", job, nil)
|
||||
return s.jobs.Enqueue("osbuild:"+arch, job, nil)
|
||||
}
|
||||
|
||||
func (s *Server) JobStatus(id uuid.UUID) (*JobStatus, error) {
|
||||
|
|
@ -172,11 +172,14 @@ func (s *Server) DeleteArtifacts(id uuid.UUID) error {
|
|||
return os.RemoveAll(path.Join(s.artifactsDir, id.String()))
|
||||
}
|
||||
|
||||
func (s *Server) RequestOSBuildJob(ctx context.Context) (uuid.UUID, uuid.UUID, *OSBuildJob, error) {
|
||||
func (s *Server) RequestOSBuildJob(ctx context.Context, arch string) (uuid.UUID, uuid.UUID, *OSBuildJob, error) {
|
||||
token := uuid.New()
|
||||
|
||||
// wait on "osbuild" jobs for backwards compatiblity
|
||||
jobTypes := []string{"osbuild", "osbuild:" + arch}
|
||||
|
||||
var args OSBuildJob
|
||||
jobId, err := s.jobs.Dequeue(ctx, []string{"osbuild"}, &args)
|
||||
jobId, err := s.jobs.Dequeue(ctx, jobTypes, &args)
|
||||
if err != nil {
|
||||
return uuid.Nil, uuid.Nil, nil, err
|
||||
}
|
||||
|
|
@ -262,7 +265,7 @@ func (h *apiHandlers) RequestJob(ctx echo.Context) error {
|
|||
return echo.NewHTTPError(http.StatusBadRequest, "invalid job types")
|
||||
}
|
||||
|
||||
token, jobId, jobArgs, err := h.server.RequestOSBuildJob(ctx.Request().Context())
|
||||
token, jobId, jobArgs, err := h.server.RequestOSBuildJob(ctx.Request().Context(), body.Arch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ func TestCreate(t *testing.T) {
|
|||
}
|
||||
server := worker.NewServer(nil, testjobqueue.New(), "")
|
||||
|
||||
_, err = server.Enqueue(manifest, nil)
|
||||
_, err = server.Enqueue(arch.Name(), manifest, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
test.TestRoute(t, server, false, "POST", "/jobs", `{"types":["osbuild"]}`, http.StatusCreated,
|
||||
test.TestRoute(t, server, false, "POST", "/jobs", `{"types":["osbuild"],"arch":"x86_64"}`, http.StatusCreated,
|
||||
`{"type":"osbuild","args":{"manifest":{"pipeline":{},"sources":{}}}}`, "id", "location", "artifact_location")
|
||||
}
|
||||
|
||||
|
|
@ -87,10 +87,10 @@ func TestCancel(t *testing.T) {
|
|||
}
|
||||
server := worker.NewServer(nil, testjobqueue.New(), "")
|
||||
|
||||
jobId, err := server.Enqueue(manifest, nil)
|
||||
jobId, err := server.Enqueue(arch.Name(), manifest, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
token, j, _, err := server.RequestOSBuildJob(context.Background())
|
||||
token, j, _, err := server.RequestOSBuildJob(context.Background(), arch.Name())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, jobId, j)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue