kubewarden-controller icon indicating copy to clipboard operation
kubewarden-controller copied to clipboard

Refactor policy validation on create and update, including tests

Open viccuad opened this issue 7 months ago • 0 comments

We need to refactor and cleanup webhooks validation, as we realized that we could increase readability and test coverage

Acceptance criteria

  • The file api/policies/v1/policy_validation_matchconditions.go was copy-pasted from k8s.io/kubernetes (see license, copyright, comment at its beginning). We tried to import as-is, but it makes more sense to own it instead. For that:
    • Enable linter in the file (check golangci-lint.yml).
    • Consider moving its functions into api/policies/v1/policy_validation.go and perform any cleanup necessary.
  • Factories should be refactored with the builder pattern.
  • Add integration tests for the webhooks methods: ValidateCreate, ValidateDelete, and ValidateUpdate.
    ATM We test each validator in isolation (see policy_validation_test.go), however, we do not test that the validators are correctly integrated into the webhooks. We could for instance add just a couple of test cases: one with a valid resource and one with a resource that all fields in an invalid state, so that we are sure we are passing through the right validators.

viccuad avatar Jul 23 '24 15:07 viccuad