Skip to content

Commit d2b2b09

Browse files
authored
Generate both v1beta1 and v1 CRD YAML (#54)
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 7fbcb29 commit d2b2b09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+12237
-22
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ REPO := $(notdir $(shell pwd))
2020
BIN := installer
2121

2222
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
23-
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
23+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false,crdVersions={v1beta1,v1}"
2424
# https://github.com/appscodelabs/gengo-builder
2525
CODE_GENERATOR_IMAGE ?= appscode/gengo:release-1.18
2626
API_GROUPS ?= installer:v1alpha1
@@ -225,7 +225,7 @@ gen-bindata:
225225

226226
.PHONY: gen-values-schema
227227
gen-values-schema:
228-
@yq r api/crds/installer.stash.appscode.com_stashoperators.yaml spec.validation.openAPIV3Schema.properties.spec > /tmp/stash-values.openapiv3_schema.yaml
228+
@yq r api/crds/installer.stash.appscode.com_stashoperators.v1.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec > /tmp/stash-values.openapiv3_schema.yaml
229229
@yq d /tmp/stash-values.openapiv3_schema.yaml description > charts/stash/values.openapiv3_schema.yaml
230230

231231
.PHONY: gen-chart-doc

api/crds/bindata.go

Lines changed: 25 additions & 2 deletions
Large diffs are not rendered by default.

api/crds/installer.stash.appscode.com_stashoperators.v1.yaml

Lines changed: 1269 additions & 0 deletions
Large diffs are not rendered by default.

api/crds/lib.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,39 @@ package crds
1919
import (
2020
"fmt"
2121

22-
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
2322
"k8s.io/apimachinery/pkg/runtime/schema"
23+
"kmodules.xyz/client-go/apiextensions"
2424
"sigs.k8s.io/yaml"
2525
)
2626

27+
func load(filename string, o interface{}) error {
28+
if _, ok := _bindata[filename]; ok {
29+
data, err := Asset(filename)
30+
if err != nil {
31+
return err
32+
}
33+
return yaml.Unmarshal(data, o)
34+
}
35+
return nil
36+
}
37+
2738
func CustomResourceDefinition(gvr schema.GroupVersionResource) (*apiextensions.CustomResourceDefinition, error) {
28-
data, err := Asset(fmt.Sprintf("%s_%s.yaml", gvr.Group, gvr.Resource))
29-
if err != nil {
39+
var out apiextensions.CustomResourceDefinition
40+
41+
v1file := fmt.Sprintf("%s_%s.v1.yaml", gvr.Group, gvr.Resource)
42+
if err := load(v1file, &out.V1); err != nil {
3043
return nil, err
3144
}
32-
var out apiextensions.CustomResourceDefinition
33-
err = yaml.Unmarshal(data, &out)
34-
if err != nil {
45+
46+
v1beta1file := fmt.Sprintf("%s_%s.yaml", gvr.Group, gvr.Resource)
47+
if err := load(v1beta1file, &out.V1beta1); err != nil {
3548
return nil, err
3649
}
50+
51+
if out.V1 == nil && out.V1beta1 == nil {
52+
return nil, fmt.Errorf("missing crd yamls for gvr: %s", gvr)
53+
}
54+
3755
return &out, nil
3856
}
3957

apis/installer/install/pruning_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@ import (
2828

2929
func TestPruneTypes(t *testing.T) {
3030
Install(clientsetscheme.Scheme)
31-
crdfuzz.SchemaFuzzTestForV1beta1CRD(t, clientsetscheme.Scheme, v1alpha1.StashOperator{}.CustomResourceDefinition(), fuzzer.Funcs)
31+
32+
if crd := (v1alpha1.StashOperator{}).CustomResourceDefinition(); crd.V1 != nil {
33+
crdfuzz.SchemaFuzzTestForV1CRD(t, clientsetscheme.Scheme, crd.V1, fuzzer.Funcs)
34+
}
35+
if crd := (v1alpha1.StashOperator{}).CustomResourceDefinition(); crd.V1beta1 != nil {
36+
crdfuzz.SchemaFuzzTestForV1beta1CRD(t, clientsetscheme.Scheme, crd.V1beta1, fuzzer.Funcs)
37+
}
3238
}

apis/installer/v1alpha1/stash_operator_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package v1alpha1
1919
import (
2020
"stash.appscode.dev/installer/api/crds"
2121

22-
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
22+
"kmodules.xyz/client-go/apiextensions"
2323
)
2424

2525
func (_ StashOperator) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {

go.mod

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module stash.appscode.dev/installer
33
go 1.12
44

55
require (
6+
cloud.google.com/go v0.49.0 // indirect
7+
github.com/Azure/go-autorest/autorest v0.9.3-0.20191028180845-3492b2aff503 // indirect
8+
github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503 // indirect
69
github.com/NYTimes/gziphandler v1.1.1 // indirect
710
github.com/appscode/go v0.0.0-20200323182826-54e98e09185a
811
github.com/blang/semver v3.5.1+incompatible // indirect
@@ -12,6 +15,7 @@ require (
1215
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
1316
github.com/google/gofuzz v1.1.0
1417
github.com/googleapis/gnostic v0.3.1 // indirect
18+
github.com/gophercloud/gophercloud v0.6.0 // indirect
1519
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
1620
github.com/grpc-ecosystem/grpc-gateway v1.12.1 // indirect
1721
github.com/hashicorp/golang-lru v0.5.3 // indirect
@@ -27,21 +31,19 @@ require (
2731
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
2832
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f // indirect
2933
google.golang.org/appengine v1.6.5 // indirect
30-
google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9 // indirect
3134
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
3235
k8s.io/api v0.18.3
33-
k8s.io/apiextensions-apiserver v0.18.3
3436
k8s.io/apimachinery v0.18.3
3537
k8s.io/client-go v12.0.0+incompatible
3638
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6
37-
kmodules.xyz/client-go v0.0.0-20200522120609-c6430d66212f
39+
kmodules.xyz/client-go v0.0.0-20200524205059-e986bc44c91b
3840
kmodules.xyz/crd-schema-fuzz v0.0.0-20200521005638-2433a187de95
3941
sigs.k8s.io/yaml v1.2.0
4042
)
4143

4244
replace (
4345
bitbucket.org/ww/goautoneg => gomodules.xyz/goautoneg v0.0.0-20120707110453-a547fc61f48d
44-
git.apache.org/thrift.git => github.com/apache/thrift v0.12.0
46+
git.apache.org/thrift.git => github.com/apache/thrift v0.13.0
4547
github.com/Azure/azure-sdk-for-go => github.com/Azure/azure-sdk-for-go v35.0.0+incompatible
4648
github.com/Azure/go-ansiterm => github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78
4749
github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.0.0+incompatible
@@ -57,6 +59,7 @@ replace (
5759
github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.0.0
5860
go.etcd.io/etcd => go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738
5961
google.golang.org/grpc => google.golang.org/grpc v1.26.0
62+
k8s.io/api => github.com/kmodules/api v0.18.4-0.20200524125823-c8bc107809b9
6063
k8s.io/apimachinery => github.com/kmodules/apimachinery v0.19.0-alpha.0.0.20200520235721-10b58e57a423
6164
k8s.io/apiserver => github.com/kmodules/apiserver v0.18.4-0.20200521000930-14c5f6df9625
6265
k8s.io/client-go => k8s.io/client-go v0.18.3

0 commit comments

Comments
 (0)