Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ resources:
schemaLocations: # Optional: For Custom Resources
- <url/to/crd/schema.json>
- <path/to/crd/schema.json>
skipSchemaValidation: <true|false> # Optional: skip resource manifest validation for this test manifest file
vapTestSuites:
- policy: <name> # ValidatingAdmissionPolicy's name
tests:
Expand Down Expand Up @@ -180,7 +181,10 @@ For custom resources, users need to define `schemaLocations` in a test policy to
The schema specification follows kubeconform's one and users can utlize schemas for it.
The example is described in [internal/tester/testdata/vap-custom-resources.test/kaptest.yaml](./internal/tester/testdata/vap-custom-resources.test/kaptest.yaml).

`kaptest run <test_manifest.yaml> --validate-resource-manifests=false` disables the validation.
`kaptest run <test_manifest.yaml> --validate-resource-manifests=false` disables the validation for all test manifest files.

To disable the validation for a specific test manifest file, set `skipSchemaValidation: true` in the file instead.
The example is described in [internal/tester/testdata/vap-custom-resources.test/skip-schema-validation.yaml](./internal/tester/testdata/vap-custom-resources.test/skip-schema-validation.yaml).

### Operation Type

Expand Down
13 changes: 7 additions & 6 deletions internal/tester/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ var supportedTestManifestVersions = []string{currentTestManifestVersion}

// TestManifests is a struct to represent the whole test manifest file.
type TestManifests struct {
Version string `yaml:"version,omitempty"`
Policies []string `yaml:"policies,omitempty"`
Resources []string `yaml:"resources,omitempty"`
SchemaLocations []string `yaml:"schemaLocations,omitempty"` // used for resource manifest validation
VapTestSuites []TestsForSingleVapPolicy `yaml:"vapTestSuites,omitempty"`
MapTestSuites []TestsForSingleMapPolicy `yaml:"mapTestSuites,omitempty"`
Version string `yaml:"version,omitempty"`
Policies []string `yaml:"policies,omitempty"`
Resources []string `yaml:"resources,omitempty"`
SchemaLocations []string `yaml:"schemaLocations,omitempty"` // used for resource manifest validation
SkipSchemaValidation bool `yaml:"skipSchemaValidation,omitempty"`
VapTestSuites []TestsForSingleVapPolicy `yaml:"vapTestSuites,omitempty"`
MapTestSuites []TestsForSingleMapPolicy `yaml:"mapTestSuites,omitempty"`
}

func (t TestManifests) IsValid() (bool, string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: v1alpha1
policies:
- ../vap-custom-resources.yaml
resources:
- resources.yaml
skipSchemaValidation: true
vapTestSuites:
- policy: httpproxy-auth
tests:
- object:
kind: HTTPProxy
name: ok
expect: admit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: v1alpha1
policies:
- ../vap-standard-resources.yaml
resources:
- invalid-resources.yaml
skipSchemaValidation: true
vapTestSuites:
- policy: deployment-replicas
tests:
- object:
kind: Deployment
name: ok
expect: admit
2 changes: 1 addition & 1 deletion internal/tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func runEach(cfg TesterCmdConfig, manifestPath string) testResultSummary {
defer os.Chdir(pwd) //nolint:errcheck

var manifestValidator validator.Validator = nil
if cfg.ValidateResourceManifest {
if cfg.ValidateResourceManifest && !manifests.SkipSchemaValidation {
// Below line causes gofumpt's false positive
err = os.MkdirAll(cfg.SchemaCache, 0755) //nolint:gofumpt
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions internal/tester/tester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ func TestRun(t *testing.T) {
wantErr: nil,
validateManifests: false,
},
{
name: "ok: invalid resource manifest or no schemas, but skipSchemaValidation is set",
args: []string{
"./testdata/vap-standard-resources.test/skip-schema-validation.yaml",
"./testdata/vap-custom-resources.test/skip-schema-validation.yaml",
},
wantErr: nil,
validateManifests: true,
},
{
name: "err: unexpected message output",
args: []string{
Expand Down
Loading