Skip to content

Commit

Permalink
fix error handling and check kind when reading expansion template
Browse files Browse the repository at this point in the history
Signed-off-by: David-Jaeyoon-Lee <[email protected]>
  • Loading branch information
David-Jaeyoon-Lee committed Oct 30, 2024
1 parent 716b53c commit b15146f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/gator/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var (
// ErrNotAConstraint indicates the user-indicated file does not contain a
// Constraint.
ErrNotAConstraint = errors.New("not a Constraint")
// ErrNotAnExpansion indicates the user-indicated file does not contain a
// ErrNotAnExpansion indicates the user-indicated file does not contain an
// ExpansionTemplate.
ErrNotAnExpansion = errors.New("not an Expansion Template")
// ErrAddingTemplate indicates a problem instantiating a Suite's ConstraintTemplate.
Expand Down
2 changes: 1 addition & 1 deletion pkg/gator/reader/read_constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func ReadExpansion(f fs.FS, path string) (*unstructured.Unstructured, error) {
}

gvk := u.GroupVersionKind()
if gvk.Group != "expansion.gatekeeper.sh" {
if gvk.Group != "expansion.gatekeeper.sh" || gvk.Kind != "ExpansionTemplate" {
return nil, gator.ErrNotAnExpansion
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/gator/verify/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (r *Runner) runReview(ctx context.Context, newClient func() (gator.Client,
}

review, err := c.Review(ctx, au, reviews.EnforcementPoint(util.GatorEnforcementPoint))
if err != nil {
return nil, fmt.Errorf("reviewing %v %s/%s: %w",
toReview.GroupVersionKind(), toReview.GetNamespace(), toReview.GetName(), err)
}

if e != nil {
resultants, err := e.Expand(toReview)
Expand Down

0 comments on commit b15146f

Please sign in to comment.