Skip to content

Commit

Permalink
first stab
Browse files Browse the repository at this point in the history
  • Loading branch information
porridge committed Dec 8, 2023
1 parent d986e76 commit d3d2e4f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ require (
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.13.2
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9
k8s.io/kubectl v0.28.4
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
sigs.k8s.io/yaml v1.4.0
)

replace helm.sh/helm/v3 v3.13.2 => github.com/porridge/helm/v3 v3.0.0-20231207123003-732d70f87a46

require (
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
4d63.com/gochecknoglobals v0.2.1 // indirect
Expand Down Expand Up @@ -60,7 +63,7 @@ require (
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/esimonov/ifshort v1.0.4 // indirect
github.com/ettle/strcase v0.1.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
Expand Down Expand Up @@ -239,7 +242,6 @@ require (
k8s.io/api v0.28.4 // indirect
k8s.io/apiextensions-apiserver v0.28.2 // indirect
k8s.io/cli-runtime v0.28.4 // indirect
k8s.io/client-go v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
mvdan.cc/gofumpt v0.5.0 // indirect
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ github.com/esimonov/ifshort v1.0.4 h1:6SID4yGWfRae/M7hkVDVVyppy8q/v9OuxNdmjLQStB
github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcHcfgNWTk0=
github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw=
github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY=
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI=
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwCFad8crR9dcMQWvV9Hvulu6hwUh4tWPJnM=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
Expand Down Expand Up @@ -492,6 +492,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polyfloyd/go-errorlint v1.4.5 h1:70YWmMy4FgRHehGNOUask3HtSFSOLKgmDn7ryNe7LqI=
github.com/polyfloyd/go-errorlint v1.4.5/go.mod h1:sIZEbFoDOCnTYYZoVkjc4hTnM459tuWA9H/EkdXwsKk=
github.com/porridge/helm/v3 v3.0.0-20231207123003-732d70f87a46 h1:ncyQ27h+iw2mazvykXHYDVFxyW/4sttTdbVT3domcjc=
github.com/porridge/helm/v3 v3.0.0-20231207123003-732d70f87a46/go.mod h1:GIHDwZggaTGbedevTlrQ6DB++LBN6yuQdeGj0HNaDx0=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down Expand Up @@ -1083,8 +1085,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
helm.sh/helm/v3 v3.13.2 h1:IcO9NgmmpetJODLZhR3f3q+6zzyXVKlRizKFwbi7K8w=
helm.sh/helm/v3 v3.13.2/go.mod h1:GIHDwZggaTGbedevTlrQ6DB++LBN6yuQdeGj0HNaDx0=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
18 changes: 14 additions & 4 deletions pkg/framework/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/dynamic/fake"
"k8s.io/kubectl/pkg/util/openapi"
"k8s.io/kubectl/pkg/validation"
k8sYaml "sigs.k8s.io/yaml"
Expand Down Expand Up @@ -112,7 +113,7 @@ func (r *runner) readAndValidateYAML(fileName, fileContents string, resources op
return objs
}

func (r *runner) instantiateWorld(renderVals chartutil.Values, resources openapi.Resources) map[string]interface{} {
func (r *runner) instantiateWorld(renderVals chartutil.Values, resources openapi.Resources, objects []runtime.Object) map[string]interface{} {
world := make(map[string]interface{})

renderValsBytes, err := json.Marshal(renderVals)
Expand All @@ -123,9 +124,11 @@ func (r *runner) instantiateWorld(renderVals chartutil.Values, resources openapi
if err := json.Unmarshal(renderValsBytes, &helmRenderVals); err != nil {
panic(errors.Wrap(err, "unmarshaling Helm render values"))
}

client := fake.NewSimpleDynamicClient(runtime.NewScheme(), objects...)
world["helm"] = helmRenderVals

renderedTemplates, err := (&engine.Engine{}).Render(r.tgt.Chart, renderVals)
renderedTemplates, err := engine.RenderWithDynamicClient(r.tgt.Chart, renderVals, client)

if *r.test.ExpectError {
r.Require().Error(err, "expected rendering to fail")
Expand Down Expand Up @@ -263,10 +266,17 @@ 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)
world := r.instantiateWorld(renderVals, availableSchemas, availableObjects)
r.evaluatePredicates(world)
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/framework/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ 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"`
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"`

Expect string `json:"expect,omitempty" yaml:"expect,omitempty"`
ExpectError *bool `json:"expectError,omitempty" yaml:"expectError,omitempty"`
Expand Down

0 comments on commit d3d2e4f

Please sign in to comment.