Skip to content

Commit

Permalink
Generate both v1beta1 and v1 CRD YAML (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha authored May 25, 2020
1 parent 320f3ba commit b7394ba
Show file tree
Hide file tree
Showing 94 changed files with 12,007 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ REPO := $(notdir $(shell pwd))
BIN := installer

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

.PHONY: gen-values-schema
gen-values-schema:
@yq r api/crds/installer.kubepack.com_kubepackoperators.yaml spec.validation.openAPIV3Schema.properties.spec > /tmp/kubepack-operator-values.openapiv3_schema.yaml
@yq r api/crds/installer.kubepack.com_kubepackoperators.v1.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec > /tmp/kubepack-operator-values.openapiv3_schema.yaml
@yq d /tmp/kubepack-operator-values.openapiv3_schema.yaml description > charts/kubepack-operator/values.openapiv3_schema.yaml

.PHONY: gen-chart-doc
Expand Down
27 changes: 25 additions & 2 deletions api/crds/bindata.go

Large diffs are not rendered by default.

1,095 changes: 1,095 additions & 0 deletions api/crds/installer.kubepack.com_kubepackoperators.v1.yaml

Large diffs are not rendered by default.

30 changes: 24 additions & 6 deletions api/crds/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,39 @@ package crds
import (
"fmt"

apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/runtime/schema"
"kmodules.xyz/client-go/apiextensions"
"sigs.k8s.io/yaml"
)

func load(filename string, o interface{}) error {
if _, ok := _bindata[filename]; ok {
data, err := Asset(filename)
if err != nil {
return err
}
return yaml.Unmarshal(data, o)
}
return nil
}

func CustomResourceDefinition(gvr schema.GroupVersionResource) (*apiextensions.CustomResourceDefinition, error) {
data, err := Asset(fmt.Sprintf("%s_%s.yaml", gvr.Group, gvr.Resource))
if err != nil {
var out apiextensions.CustomResourceDefinition

v1file := fmt.Sprintf("%s_%s.v1.yaml", gvr.Group, gvr.Resource)
if err := load(v1file, &out.V1); err != nil {
return nil, err
}
var out apiextensions.CustomResourceDefinition
err = yaml.Unmarshal(data, &out)
if err != nil {

v1beta1file := fmt.Sprintf("%s_%s.yaml", gvr.Group, gvr.Resource)
if err := load(v1beta1file, &out.V1beta1); err != nil {
return nil, err
}

if out.V1 == nil && out.V1beta1 == nil {
return nil, fmt.Errorf("missing crd yamls for gvr: %s", gvr)
}

return &out, nil
}

Expand Down
11 changes: 10 additions & 1 deletion apis/installer/install/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ import (

func TestPruneTypes(t *testing.T) {
Install(clientsetscheme.Scheme)
crdfuzz.SchemaFuzzTestForV1beta1CRD(t, clientsetscheme.Scheme, v1alpha1.KubepackOperator{}.CustomResourceDefinition(), fuzzer.Funcs)

// CRD v1
if crd := (v1alpha1.KubepackOperator{}).CustomResourceDefinition(); crd.V1 != nil {
crdfuzz.SchemaFuzzTestForV1CRD(t, clientsetscheme.Scheme, crd.V1, fuzzer.Funcs)
}

// CRD v1beta1
if crd := (v1alpha1.KubepackOperator{}).CustomResourceDefinition(); crd.V1beta1 != nil {
crdfuzz.SchemaFuzzTestForV1beta1CRD(t, clientsetscheme.Scheme, crd.V1beta1, fuzzer.Funcs)
}
}
2 changes: 1 addition & 1 deletion apis/installer/v1alpha1/kubepack_operator_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha1
import (
"kubepack.dev/installer/api/crds"

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

func (_ KubepackOperator) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module kubepack.dev/installer
go 1.12

require (
cloud.google.com/go v0.49.0 // indirect
github.com/Azure/go-autorest/autorest v0.9.3-0.20191028180845-3492b2aff503 // indirect
github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/appscode/go v0.0.0-20200323182826-54e98e09185a
github.com/blang/semver v3.5.1+incompatible // indirect
Expand All @@ -12,6 +15,7 @@ require (
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
github.com/google/gofuzz v1.1.0
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/gophercloud/gophercloud v0.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.12.1 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
Expand All @@ -27,21 +31,19 @@ require (
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
k8s.io/api v0.18.3
k8s.io/apiextensions-apiserver v0.18.3
k8s.io/apimachinery v0.18.3
k8s.io/client-go v0.18.3
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6
kmodules.xyz/client-go v0.0.0-20200522120609-c6430d66212f
kmodules.xyz/client-go v0.0.0-20200525112657-3b8ebfcb5e19
kmodules.xyz/crd-schema-fuzz v0.0.0-20200521005638-2433a187de95
sigs.k8s.io/yaml v1.2.0
)

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

0 comments on commit b7394ba

Please sign in to comment.