From c314e70e3a33a3eea2da64b3ca52e0a9a81f7f79 Mon Sep 17 00:00:00 2001 From: Marcin Owsiany Date: Tue, 23 Jan 2024 14:41:57 +0100 Subject: [PATCH] move objects under server --- README.md | 14 +++++++------- integration_test/testdata/helmtest/suite.yaml | 13 +++++++------ pkg/framework/runner.go | 18 +++++++----------- pkg/framework/spec.go | 11 ++++++----- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 370ebbb..15bf912 100644 --- a/README.md +++ b/README.md @@ -33,16 +33,16 @@ server: - openshift-4.1.0 - com.coreos availableSchemas: [] # openAPI schema to validate against, i.e. to validate if rendered objects could be applied + objects: # objects visible to Helm's k8s client, for example via the `lookup` function + # example object specification: + - apiVersion: string + kind: string + metadata: + name: string + namespace: string # optional for cluster-scoped objects noInherit: bool # indicates that server-side settings should *not* be inherited from the enclosing scope capabilities: # represents the .Capabilities in Helm kubeVersion: string # the kubernetes version which is discoverable via `.Capabilities.KubeVersion` -objects: # objects visible to Helm's k8s client, for example via the `lookup` function - # example object specification: - - apiVersion: string - kind: string - metadata: - name: string - namespace: string # optional for cluster-scoped objects values: # values as consumed by Helm via the `-f` CLI flag. key: value set: # alternative format for Helm values, as consumed via the `--set` CLI flag. diff --git a/integration_test/testdata/helmtest/suite.yaml b/integration_test/testdata/helmtest/suite.yaml index 331e4e9..fb3d063 100644 --- a/integration_test/testdata/helmtest/suite.yaml +++ b/integration_test/testdata/helmtest/suite.yaml @@ -4,12 +4,13 @@ server: tests: - name: "Expect secret to be rendered on upgrades" - objects: - - apiVersion: test.stackrox.io - kind: FakeResource - metadata: - name: example-fr - namespace: loadbalancer + server: + objects: + - apiVersion: test.stackrox.io + kind: FakeResource + metadata: + name: example-fr + namespace: loadbalancer release: isUpgrade: true expect: | diff --git a/pkg/framework/runner.go b/pkg/framework/runner.go index c1f2133..653f8b3 100644 --- a/pkg/framework/runner.go +++ b/pkg/framework/runner.go @@ -195,7 +195,7 @@ func (r *runner) instantiateWorld(renderVals chartutil.Values, resources openapi return world } -func (r *runner) loadSchemas() (visible, available schemas.Schemas) { +func (r *runner) loadServerSettings() (visible, available schemas.Schemas, objects []runtime.Object) { var visibleSchemaNames, availableSchemaNames []string r.test.forEachScopeTopDown(func(t *Test) { server := t.Server @@ -216,6 +216,10 @@ func (r *runner) loadSchemas() (visible, available schemas.Schemas) { // Every visible schema is also available (but not vice versa) availableSchemaNames = append(availableSchemaNames, schemaName) } + for _, o := range server.Objects { + obj := &unstructured.Unstructured{Object: o} + objects = append(objects, obj.DeepCopyObject()) + } }) availableSchemaNames = sliceutils.StringUnique(availableSchemaNames) @@ -237,7 +241,7 @@ func (r *runner) loadSchemas() (visible, available schemas.Schemas) { visible = append(visible, schema) } - return visible, available + return visible, available, objects } func (r *runner) Run() { @@ -259,7 +263,7 @@ func (r *runner) Run() { rel.apply(&releaseOpts) }) - visibleSchemas, availableSchemas := r.loadSchemas() + visibleSchemas, availableSchemas, availableObjects := r.loadServerSettings() caps := r.tgt.Capabilities if caps == nil { @@ -281,14 +285,6 @@ func (r *runner) Run() { caps = &newCaps }) - var availableObjects []runtime.Object - r.test.forEachScopeTopDown(func(t *Test) { - for _, o := range t.Objects { - obj := &unstructured.Unstructured{Object: o} - availableObjects = append(availableObjects, obj.DeepCopyObject()) - } - }) - renderVals, err := chartutil.ToRenderValues(r.tgt.Chart, values, releaseOpts, caps) r.Require().NoError(err, "failed to obtain render values") world := r.instantiateWorld(renderVals, availableSchemas, availableObjects) diff --git a/pkg/framework/spec.go b/pkg/framework/spec.go index 801ada3..4fd1c16 100644 --- a/pkg/framework/spec.go +++ b/pkg/framework/spec.go @@ -20,11 +20,10 @@ type Test struct { Values RawDict `json:"values,omitempty" yaml:"values,omitempty"` Set RawDict `json:"set,omitempty" yaml:"set,omitempty"` - Defs string `json:"defs,omitempty" yaml:"defs,omitempty"` - Release *ReleaseSpec `json:"release,omitempty" yaml:"release,omitempty"` - Server *ServerSpec `json:"server,omitempty" yaml:"server,omitempty"` - Capabilities *CapabilitiesSpec `json:"capabilities,omitempty" yaml:"capabilities,omitempty"` - Objects []map[string]interface{} `json:"objects,omitempty" yaml:"objects,omitempty"` + Defs string `json:"defs,omitempty" yaml:"defs,omitempty"` + Release *ReleaseSpec `json:"release,omitempty" yaml:"release,omitempty"` + Server *ServerSpec `json:"server,omitempty" yaml:"server,omitempty"` + Capabilities *CapabilitiesSpec `json:"capabilities,omitempty" yaml:"capabilities,omitempty"` Expect string `json:"expect,omitempty" yaml:"expect,omitempty"` ExpectError *bool `json:"expectError,omitempty" yaml:"expectError,omitempty"` @@ -59,6 +58,8 @@ type ServerSpec struct { // VisibleSchemas are the names of schemas that are available on the server AND discoverable via // `.Capabilities.APIVersions`. VisibleSchemas []string `json:"visibleSchemas,omitempty" yaml:"visibleSchemas,omitempty"` + // Objects are definitions of objects visible to Helm's k8s client, for example via the `lookup` function. + Objects []map[string]interface{} `json:"objects,omitempty" yaml:"objects,omitempty"` // NoInherit indicates that server-side settings should *not* be inherited from the enclosing scope. NoInherit bool `json:"noInherit,omitempty" yaml:"noInherit,omitempty"`