From cf0d6d08f4b1a7471daac0462a69fd6f69612ab3 Mon Sep 17 00:00:00 2001 From: Naoki MATSUMOTO Date: Wed, 1 Jul 2026 10:21:16 +0900 Subject: [PATCH] Add 'skipSchemaValidation' field in a test manifest This is used to turn off validation on a specific test manifest. --- README.md | 6 +++++- internal/tester/manifest.go | 13 +++++++------ .../skip-schema-validation.yaml | 13 +++++++++++++ .../skip-schema-validation.yaml | 13 +++++++++++++ internal/tester/tester.go | 2 +- internal/tester/tester_test.go | 9 +++++++++ 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 internal/tester/testdata/vap-custom-resources.test/skip-schema-validation.yaml create mode 100644 internal/tester/testdata/vap-standard-resources.test/skip-schema-validation.yaml diff --git a/README.md b/README.md index 27715da..e5b4c6b 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ resources: schemaLocations: # Optional: For Custom Resources - - +skipSchemaValidation: # Optional: skip resource manifest validation for this test manifest file vapTestSuites: - policy: # ValidatingAdmissionPolicy's name tests: @@ -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 --validate-resource-manifests=false` disables the validation. +`kaptest run --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 diff --git a/internal/tester/manifest.go b/internal/tester/manifest.go index d12852d..98862a4 100644 --- a/internal/tester/manifest.go +++ b/internal/tester/manifest.go @@ -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) { diff --git a/internal/tester/testdata/vap-custom-resources.test/skip-schema-validation.yaml b/internal/tester/testdata/vap-custom-resources.test/skip-schema-validation.yaml new file mode 100644 index 0000000..20fd67b --- /dev/null +++ b/internal/tester/testdata/vap-custom-resources.test/skip-schema-validation.yaml @@ -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 diff --git a/internal/tester/testdata/vap-standard-resources.test/skip-schema-validation.yaml b/internal/tester/testdata/vap-standard-resources.test/skip-schema-validation.yaml new file mode 100644 index 0000000..883d4c0 --- /dev/null +++ b/internal/tester/testdata/vap-standard-resources.test/skip-schema-validation.yaml @@ -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 diff --git a/internal/tester/tester.go b/internal/tester/tester.go index e4896b8..1a932d8 100644 --- a/internal/tester/tester.go +++ b/internal/tester/tester.go @@ -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 { diff --git a/internal/tester/tester_test.go b/internal/tester/tester_test.go index 72d1c55..e47494a 100644 --- a/internal/tester/tester_test.go +++ b/internal/tester/tester_test.go @@ -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{