-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node pools: validate pool exists on job registration (#17386)
Add a new job admission hook for node pools that enforces the pool exists on registration. Also provide the skeleton function we need for Enterprise enforcement functions we'll implement later.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package nomad | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
||
// jobNodePoolValidatingHook is an admission hook that ensures the job has valid | ||
// node pool configuration. | ||
type jobNodePoolValidatingHook struct { | ||
srv *Server | ||
} | ||
|
||
func (j jobNodePoolValidatingHook) Name() string { | ||
return "node-pool-validation" | ||
} | ||
|
||
func (j jobNodePoolValidatingHook) Validate(job *structs.Job) ([]error, error) { | ||
poolName := job.NodePool | ||
|
||
pool, err := j.srv.State().NodePoolByName(nil, poolName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if pool == nil { | ||
return nil, fmt.Errorf("job %q is in nonexistent node pool %q", job.ID, poolName) | ||
} | ||
|
||
return j.enterpriseValidation(job, pool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//go:build !ent | ||
// +build !ent | ||
|
||
package nomad | ||
|
||
import "github.com/hashicorp/nomad/nomad/structs" | ||
|
||
// enterpriseValidation implements any admission hooks for node pools for Nomad | ||
// Enterprise. | ||
func (j jobNodePoolValidatingHook) enterpriseValidation(_ *structs.Job, _ *structs.NodePool) ([]error, error) { | ||
return nil, nil | ||
} | ||
|
||
// jobNodePoolMutatingHook mutates the job on Nomad Enterprise only. | ||
type jobNodePoolMutatingHook struct { | ||
srv *Server | ||
} | ||
|
||
func (c jobNodePoolMutatingHook) Name() string { | ||
return "node-pool-mutation" | ||
} | ||
|
||
func (c jobNodePoolMutatingHook) Mutate(job *structs.Job) (*structs.Job, []error, error) { | ||
return job, nil, nil | ||
} |