Skip to content

Commit

Permalink
move objects under server
Browse files Browse the repository at this point in the history
  • Loading branch information
porridge committed Jan 23, 2024
1 parent 55b147f commit c314e70
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions integration_test/testdata/helmtest/suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
18 changes: 7 additions & 11 deletions pkg/framework/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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() {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions pkg/framework/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit c314e70

Please sign in to comment.