Skip to content

Commit

Permalink
Use kmodules.xyz/schema-checker to validate values schema (#134)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Dec 25, 2020
1 parent 7b2f051 commit 9182697
Show file tree
Hide file tree
Showing 60 changed files with 16,918 additions and 362 deletions.
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,15 @@ gen-bindata:
go-bindata -ignore=\\.go -ignore=\\.DS_Store -mode=0644 -modtime=1573722179 -o bindata.go -pkg crds ./...

.PHONY: gen-values-schema
gen-values-schema:
@yq r crds/installer.stash.appscode.com_stashenterprises.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec > /tmp/stash-enterprise-values.openapiv3_schema.yaml
@yq d /tmp/stash-enterprise-values.openapiv3_schema.yaml description > charts/stash-enterprise/values.openapiv3_schema.yaml
@yq r crds/installer.stash.appscode.com_stashoperators.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec > /tmp/stash-values.openapiv3_schema.yaml
@yq d /tmp/stash-values.openapiv3_schema.yaml description > charts/stash/values.openapiv3_schema.yaml
gen-values-schema: $(BUILD_DIRS)
@for dir in charts/*/; do \
dir=$${dir%*/}; \
dir=$${dir##*/}; \
crd=$$(echo $$dir | tr -d '-'); \
yq r crds/installer.stash.appscode.com_$${crd}s.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec > bin/values.openapiv3_schema.yaml; \
yq d bin/values.openapiv3_schema.yaml description > charts/$${dir}/values.openapiv3_schema.yaml; \
rm -rf bin/values.openapiv3_schema.yaml; \
done

.PHONY: gen-chart-doc
gen-chart-doc: $(shell find $$(pwd)/charts -maxdepth 1 -mindepth 1 -type d -printf 'gen-chart-doc-%f ')
Expand Down
2 changes: 1 addition & 1 deletion apis/installer/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// Funcs returns the fuzzer functions for this api group.
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
func(s *v1alpha1.StashOperator, c fuzz.Continue) {
func(s *v1alpha1.Stash, c fuzz.Continue) {
c.FuzzNoCustom(s) // fuzz self without calling this function again
},
}
Expand Down
4 changes: 2 additions & 2 deletions apis/installer/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&StashEnterprise{},
&StashEnterpriseList{},
&StashOperator{},
&StashOperatorList{},
&Stash{},
&StashList{},
)

scheme.AddKnownTypes(SchemeGroupVersion,
Expand Down
92 changes: 0 additions & 92 deletions apis/installer/v1alpha1/stash_enterprise_types_test.go

This file was deleted.

92 changes: 0 additions & 92 deletions apis/installer/v1alpha1/stash_operator_types_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ import (
)

const (
ResourceKindStashOperator = "StashOperator"
ResourceStashOperator = "stashoperator"
ResourceStashOperators = "stashoperators"
ResourceKindStash = "Stash"
ResourceStash = "stash"
ResourceStashs = "stashs"
)

// StashOperator defines the schama for Stash Operator Installer.
// Stash defines the schama for Stash Operator Installer.

// +genclient
// +genclient:skipVerbs=updateStatus
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=stashoperators,singular=stashoperator,categories={stash,appscode}
type StashOperator struct {
// +kubebuilder:resource:path=stashs,singular=stash,categories={stash,appscode}
type Stash struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec StashOperatorSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Spec StashSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}

// StashOperatorSpec is the schema for Stash operator values file
type StashOperatorSpec struct {
// StashSpec is the schema for Stash operator values file
type StashSpec struct {
//+optional
NameOverride string `json:"nameOverride" protobuf:"bytes,1,opt,name=nameOverride"`
//+optional
Expand Down Expand Up @@ -91,10 +91,10 @@ type StashOperatorSpec struct {

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// StashOperatorList is a list of StashOperators
type StashOperatorList struct {
// StashList is a list of Stashs
type StashList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Items is a list of StashOperator CRD objects
Items []StashOperator `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
// Items is a list of Stash CRD objects
Items []Stash `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
}
33 changes: 33 additions & 0 deletions apis/installer/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the AppsCode Community License 1.0.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1_test

import (
"testing"

"stash.appscode.dev/installer/apis/installer/v1alpha1"

schemachecker "kmodules.xyz/schema-checker"
)

func TestDefaultValues(t *testing.T) {
checker := schemachecker.New("../../..", []interface{}{
v1alpha1.StashSpec{},
v1alpha1.StashEnterpriseSpec{},
})
checker.TestAll(t)
}
Loading

0 comments on commit 9182697

Please sign in to comment.