Skip to content

Commit

Permalink
fix bad merge, name check everything
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
  • Loading branch information
acpana committed Oct 30, 2023
1 parent e5b49e1 commit e0271d5
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions pkg/webhook/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,17 @@ func (h *validationHandler) validateGatekeeperResources(ctx context.Context, req
return true, nil
}

gvk := req.AdmissionRequest.Kind

// for resources that don't have a name validation
validateWithName := func(ctx context.Context, req *admission.Request, specificValidator func(ctx context.Context, req *admission.Request) (bool, error)) (bool, error) {
if len(req.Name) > 63 {
return false, fmt.Errorf("resource cannot have metadata.name larger than 63 char; length: %d", len(req.Name))
}
return specificValidator(ctx, req)
if len(req.Name) > 63 {
return false, fmt.Errorf("resource cannot have metadata.name larger than 63 char; length: %d", len(req.Name))
}

gvk := req.AdmissionRequest.Kind
switch {
case gvk.Group == "templates.gatekeeper.sh" && gvk.Kind == "ConstraintTemplate":
return validateWithName(ctx, req, h.validateTemplate)
return h.validateTemplate(ctx, req)
case gvk.Group == "expansion.gatekeeper.sh" && gvk.Kind == "ExpansionTemplate":
return h.validateExpansionTemplate(req)
case gvk.Group == "constraints.gatekeeper.sh":
// constraint name is restricted to 63 at schema creation time
return h.validateConstraint(req)
case gvk.Group == "config.gatekeeper.sh" && gvk.Kind == "Config":
if err := h.validateConfigResource(req); err != nil {
Expand Down Expand Up @@ -536,7 +531,7 @@ func (h *validationHandler) validateModifySet(req *admission.Request) (bool, err
return false, nil
}

func (h *validationHandler) validateProvider(_ context.Context, req *admission.Request) (bool, error) {
func (h *validationHandler) validateProvider(req *admission.Request) (bool, error) {
obj, _, err := deserializer.Decode(req.AdmissionRequest.Object.Raw, nil, nil)
if err != nil {
return false, err
Expand Down

0 comments on commit e0271d5

Please sign in to comment.