Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use go-bindata to embed YAML files with CRDs. #1211

Merged
merged 7 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ deploy-clean:
.PHONY: generate
# Generate code
generate:
ifeq (, $(shell which go-bindata))
go get github.com/go-bindata/go-bindata/go-bindata
endif
go-bindata -pkg crd -o pkg/kudoctl/kudoinit/crd/bindata.go -ignore README.md config/crds
./hack/update_codegen.sh

.PHONY: generate-clean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ spec:
description: ConnectionString defines a templated string that can be
used to connect to an instance of the Operator.
type: string
crdVersion:
type: string
operator:
type: object
parameters:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/docker/go-units v0.4.0 // indirect
github.com/dustinkirkland/golang-petname v0.0.0-20170921220637-d3c2ba80e75e
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/google/btree v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg=
Expand Down
38 changes: 4 additions & 34 deletions pkg/kudoctl/cmd/init_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,27 @@ func TestMain(m *testing.M) {
}

const (
operatorFileName = "kudo_v1beta1_operator.yaml"
operatorVersionFileName = "kudo_v1beta1_operatorversion.yaml"
instanceFileName = "kudo_v1beta1_instance.yaml"
operatorFileName = "kudo.dev_operators.yaml"
operatorVersionFileName = "kudo.dev_operatorversions.yaml"
instanceFileName = "kudo.dev_instances.yaml"
manifestsDir = "../../../config/crds/"
)

func TestCrds_Config(t *testing.T) {
crds := crd.NewInitializer()

if *updateGolden {
err := writeManifest(operatorFileName, crds.Operator)
if err != nil {
t.Errorf("Operator file override failed: %v", err)
}
err = writeManifest(operatorVersionFileName, crds.OperatorVersion)
if err != nil {
t.Errorf("OperatorVersion file override failed: %v", err)
}
err = writeManifest(instanceFileName, crds.Instance)
if err != nil {
t.Errorf("Instance file override failed: %v", err)
}
}

assertManifestFileMatch(t, operatorFileName, crds.Operator)
assertManifestFileMatch(t, operatorVersionFileName, crds.OperatorVersion)
assertManifestFileMatch(t, instanceFileName, crds.Instance)
}

func writeManifest(fileName string, expectedObject runtime.Object) error {
expectedContent, err := runtimeObjectAsBytes(expectedObject)
if err != nil {
return err
}

fmt.Printf("Updating file %s", fileName)
path := filepath.Join(manifestsDir, fileName)
if err := ioutil.WriteFile(path, expectedContent, 0644); err != nil {
return fmt.Errorf("failed to update config file: %s", err)
}
return nil
}

func assertManifestFileMatch(t *testing.T, fileName string, expectedObject runtime.Object) {
expectedContent, err := runtimeObjectAsBytes(expectedObject)
assert.Nil(t, err)
path := filepath.Join(manifestsDir, fileName)
of, err := ioutil.ReadFile(path)
assert.Nil(t, err)

assert.Equal(t, string(expectedContent), string(of), "manifest file does not match the existing one")
assert.Equal(t, string(expectedContent), string(of), fmt.Sprintf("embedded file %s does not match the source, run 'make generate'", fileName))
}

func runtimeObjectAsBytes(o runtime.Object) ([]byte, error) {
Expand Down
2 changes: 0 additions & 2 deletions pkg/kudoctl/cmd/testdata/deploy-kudo-ns.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ spec:
description: ConnectionString defines a templated string that can be
used to connect to an instance of the Operator.
type: string
crdVersion:
type: string
operator:
type: object
parameters:
Expand Down
2 changes: 0 additions & 2 deletions pkg/kudoctl/cmd/testdata/deploy-kudo-sa.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ spec:
description: ConnectionString defines a templated string that can be
used to connect to an instance of the Operator.
type: string
crdVersion:
type: string
operator:
type: object
parameters:
Expand Down
2 changes: 0 additions & 2 deletions pkg/kudoctl/cmd/testdata/deploy-kudo-webhook.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ spec:
description: ConnectionString defines a templated string that can be
used to connect to an instance of the Operator.
type: string
crdVersion:
type: string
operator:
type: object
parameters:
Expand Down
2 changes: 0 additions & 2 deletions pkg/kudoctl/cmd/testdata/deploy-kudo.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ spec:
description: ConnectionString defines a templated string that can be
used to connect to an instance of the Operator.
type: string
crdVersion:
type: string
operator:
type: object
parameters:
Expand Down
4 changes: 4 additions & 0 deletions pkg/kudoctl/kudoinit/crd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Embedded CRDs

The CRDs provided by this package are embedded into the binary through the file `bindata.go`,
generated by `go-bindata` invoked from the `make generate` target.
Loading