From 20a2b98c2abdb6d8a173bc7ff946a2bf3f8fa3ef Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Thu, 3 Oct 2019 19:19:14 -0700 Subject: [PATCH] Migrate angryjet to crossplane-tools Signed-off-by: Nic Cope --- .github/ISSUE_TEMPLATE/bug_report.md | 40 +++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 24 ++++++++ .github/PULL_REQUEST_TEMPLATE.md | 28 +++++++++ .github/stale.yml | 38 ++++++++++++ .gitignore | 5 ++ .gitmodules | 3 + Gopkg.lock | 8 +-- Makefile | 71 +++++++++++++++++++++++ README.md | 39 ++++++++----- build | 1 + cmd/angryjet/main.go | 26 +++++++-- internal/comments/comments.go | 16 +++++ internal/fields/fields.go | 16 +++++ internal/generate/generate.go | 21 ++++++- internal/match/match.go | 20 ++++++- internal/methods/methods.go | 21 ++++++- internal/methods/methods_test.go | 19 +++++- 17 files changed, 367 insertions(+), 29 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/stale.yml create mode 100644 .gitmodules create mode 100644 Makefile create mode 160000 build diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..8be8fbb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,40 @@ +--- +name: Bug Report +about: Help us diagnose and fix bugs in Crossplane +labels: bug +--- + + +### What happened? + + + +### How can we reproduce it? + + +### What environment did it happen in? +Crossplane Tools version: + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..c385d79 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature Request +about: Help us make Crossplane more useful +labels: enhancement +--- + + +### What problem are you facing? + + +### How could Crossplane help solve your problem? + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..06d6473 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,28 @@ + + +### Description of your changes + + +### Checklist + +I have: +- [ ] Run `make reviewable` to ensure this PR is ready for review. +- [ ] Ensured this PR contains a neat, self documenting set of commits. diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..f6c6e0a --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,38 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +# Number of days of inactivity before an Issue or Pull Request becomes stale +daysUntilStale: 90 + +# Number of days of inactivity before a stale Issue or Pull Request is closed. +# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. +daysUntilClose: 7 + +# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable +exemptLabels: + - security + +# Set to true to ignore issues in a project (defaults to false) +exemptProjects: false + +# Set to true to ignore issues in a milestone (defaults to false) +exemptMilestones: false + +# Label to use when marking as stale +staleLabel: wontfix + +# Comment to post when marking as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + +# Comment to post when closing a stale Issue or Pull Request. +closeComment: > + This issue has been automatically closed due to inactivity. Please re-open + if this still requires investigation. + +# Limit the number of actions per hour, from 1-30. Default is 30 +limitPerRun: 30 + +# Limit to only `issues` or `pulls` +only: issues diff --git a/.gitignore b/.gitignore index 140bc80..575c53b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,8 @@ *.out vendor/ + +# Upbound build directories +.cache +.work +_output diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8032804 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "build"] + path = build + url = git@github.com:upbound/build diff --git a/Gopkg.lock b/Gopkg.lock index cee583d..2fd05a2 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -14,11 +14,11 @@ [[projects]] branch = "master" - digest = "1:4be0754e8ae810a4cc3b41f0dda393d9d0e22f3589c9a81120e00c925deb4f9c" + digest = "1:f780e2e814981de9dbdc2ca49d6c91d4aa4e2a1639ebc4106fafb0dc54fa5bd8" name = "github.com/alecthomas/units" packages = ["."] pruneopts = "UT" - revision = "680d30ca31172657fa50e996eb82d790d1d8b96e" + revision = "f65c72e2690dc4b403c8bd637baf4611cd4c069b" [[projects]] digest = "1:60abec4c812fc39cf7e66571da9e1758c586c258af815c4062b20d136542ff19" @@ -52,7 +52,7 @@ [[projects]] branch = "master" - digest = "1:7ebbc54f43ca941fe96ab2c115712a1ae0e25f3f6f4064fadc4c0f22a341a018" + digest = "1:18be5c94d0795019fd5455847b68ed49c2e34b1cd2ad4122578ffef0b29e8643" name = "golang.org/x/tools" packages = [ "go/ast/astutil", @@ -66,7 +66,7 @@ "internal/semver", ] pruneopts = "UT" - revision = "5eefd052ad727afc5e2e7b034c752b9d3d902b3b" + revision = "9cd7e18f8ef73a428ee6125634aae52a8d0c94d4" [[projects]] digest = "1:c06d9e11d955af78ac3bbb26bd02e01d2f61f689e1a3bce2ef6fb683ef8a7f2d" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a82034e --- /dev/null +++ b/Makefile @@ -0,0 +1,71 @@ +PROJECT_NAME := crossplane-tools +PROJECT_REPO := github.com/crossplaneio/$(PROJECT_NAME) + +PLATFORMS ?= linux_amd64 darwin_amd64 +# -include will silently skip missing files, which allows us +# to load those files with a target in the Makefile. If only +# "include" was used, the make command would fail and refuse +# to run a target until the include commands succeeded. +-include build/makelib/common.mk + +S3_BUCKET ?= crossplane.releases +-include build/makelib/output.mk + +# Set a sane default so that the nprocs calculation below is less noisy on the initial +# loading of this file +NPROCS ?= 1 + +# each of our test suites starts a kube-apiserver and running many test suites in +# parallel can lead to high CPU utilization. by default we reduce the parallelism +# to half the number of CPU cores. +GO_TEST_PARALLEL := $(shell echo $$(( $(NPROCS) / 2 ))) + +GO_STATIC_PACKAGES = $(GO_PROJECT)/cmd/angryjet +GO_LDFLAGS += -X $(GO_PROJECT)/pkg/version.Version=$(VERSION) +GO_SUBDIRS += cmd internal +-include build/makelib/golang.mk + +# We want submodules to be set up the first time `make` is run. +# We manage the build/ folder and its Makefiles as a submodule. +# The first time `make` is run, the includes of build/*.mk files will +# all fail, and this target will be run. The next time, the default as defined +# by the includes will be run instead. +fallthrough: submodules + @echo Initial setup complete. Running make again . . . + @make + +go.test.unit: $(KUBEBUILDER) + +# Generate a coverage report for cobertura applying exclusions on +# - generated file +cobertura: + @cat $(GO_TEST_OUTPUT)/coverage.txt | \ + grep -v zz_generated.deepcopy | \ + $(GOCOVER_COBERTURA) > $(GO_TEST_OUTPUT)/cobertura-coverage.xml + +# Ensure a PR is ready for review. +reviewable: vendor lint test + +# Update the submodules, such as the common build scripts. +submodules: + @git submodule sync + @git submodule update --init --recursive + +.PHONY: cobertura reviewable submodules fallthrough + +# Special Targets + +define CROSSPLANE_TOOLS_MAKE_HELP +Crossplane Tools Targets: + reviewable Ensure a PR is ready for review. + submodules Update the submodules, such as the common build scripts. + +endef +export CROSSPLANE_TOOLS_MAKE_HELP + +crossplane-tools.help: + @echo "$$CROSSPLANE_TOOLS_MAKE_HELP" + +help-special: crossplane-tools.help + +.PHONY: crossplane-tools.help help-special diff --git a/README.md b/README.md index be35255..aad921d 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,32 @@ -# angryjet [![Godoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/negz/angryjet) +# crossplane-tools [![Godoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/crossplaneio/crossplane-tools) -An experimental code generator for [Crossplane] controllers. +Experimental code generators for [Crossplane] controllers. -Currently `angryjet` will detect Go structs that appear to be capable of -satisfying crossplane-runtime's [`resource.Managed`] interface and automatically -generate the method set required to satisfy that interface. A struct is -considered capable of satisfying `resource.Managed` if its `Spec` field is a -struct that embeds a [`ResourceSpec`] and its `Status` field is a struct that -embeds a [`ResourceStatus`]. The method set is written to -`zz_generated.managed.go` by default. Methods are not written if they are -already defined. Use the `// +crossplane:generate:methods=false` comment marker -to explicitly disable generation of any methods for a type. +`angryjet` is the only extant tool within crossplane-tools. It will detect Go +structs that appear to be capable of satisfying crossplane-runtime's interfaces +(such as [`resource.Managed`]) and automatically generate the method set +required to satisfy that interface. A struct is considered capable of satisfying +crossplane-runtime's interfaces based on the heuristics described in the +[Crossplane Services Developer Guide], for example a managed resource must: + +* Embed a [`ResourceStatus`] struct in their `Status` struct. +* Embed a [`ResourceSpec`] struct in their `Spec` struct. +* Embed a `Parameters` struct in their `Spec` struct. + +Methods are not written if they are already defined outside of the file that +would be generated. Use the `//+crossplane:generate:methods=false` comment +marker to explicitly disable generation of any methods for a type. Use `go +generate` to generate your Crossplane API types by adding a generate marker to +the top level of your `api/` directory, for example: + +```go +// Generate crossplane-runtime methodsets (resource.Claim, etc) +//go:generate go run ../vendor/github.com/crossplaneio/crossplane-tools/cmd/angryjet/main.go generate-methodsets ./... +``` ```console -$ go run cmd/angryjet/main.go generate-methodsets --help -usage: main generate-methodsets [] [] +$ angryjet generate-methodsets --help +usage: angryjet generate-methodsets [] [] Generate a Crossplane method sets. @@ -42,3 +54,4 @@ Args: [`resource.Managed`]: https://godoc.org/github.com/crossplaneio/crossplane-runtime/pkg/resource#Managed [`ResourceSpec`]: https://godoc.org/github.com/crossplaneio/crossplane-runtime/apis/core/v1alpha1#ResourceSpec [`ResourceStatus`]: https://godoc.org/github.com/crossplaneio/crossplane-runtime/apis/core/v1alpha1#ResourceStatus +[Crossplane Services Developer Guide]: https://crossplane.io/docs/v0.3/services-developer-guide.html#defining-resource-kinds \ No newline at end of file diff --git a/build b/build new file mode 160000 index 0000000..ff9fe7d --- /dev/null +++ b/build @@ -0,0 +1 @@ +Subproject commit ff9fe7dd3d553dad7b43a3afc960b2372eb5126f diff --git a/cmd/angryjet/main.go b/cmd/angryjet/main.go index 5210f2f..6614318 100644 --- a/cmd/angryjet/main.go +++ b/cmd/angryjet/main.go @@ -1,3 +1,18 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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 main import ( @@ -5,14 +20,15 @@ import ( "os" "path/filepath" - "github.com/negz/angryjet/internal/comments" - "github.com/negz/angryjet/internal/fields" - "github.com/negz/angryjet/internal/generate" - "github.com/negz/angryjet/internal/match" - "github.com/negz/angryjet/internal/methods" "github.com/pkg/errors" "golang.org/x/tools/go/packages" "gopkg.in/alecthomas/kingpin.v2" + + "github.com/crossplaneio/crossplane-tools/internal/comments" + "github.com/crossplaneio/crossplane-tools/internal/fields" + "github.com/crossplaneio/crossplane-tools/internal/generate" + "github.com/crossplaneio/crossplane-tools/internal/match" + "github.com/crossplaneio/crossplane-tools/internal/methods" ) const ( diff --git a/internal/comments/comments.go b/internal/comments/comments.go index b9fd975..5ec8046 100644 --- a/internal/comments/comments.go +++ b/internal/comments/comments.go @@ -1,3 +1,19 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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 comments extracts and parses comments from a package. package comments diff --git a/internal/fields/fields.go b/internal/fields/fields.go index ce16424..51e9cb2 100644 --- a/internal/fields/fields.go +++ b/internal/fields/fields.go @@ -1,3 +1,19 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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 fields defines and matches common struct fields. package fields diff --git a/internal/generate/generate.go b/internal/generate/generate.go index fd79204..d2310b3 100644 --- a/internal/generate/generate.go +++ b/internal/generate/generate.go @@ -1,3 +1,19 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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 generate generates method sets for Go types. package generate @@ -10,14 +26,15 @@ import ( "sort" "github.com/dave/jennifer/jen" - "github.com/negz/angryjet/internal/match" "github.com/pkg/errors" "golang.org/x/tools/go/packages" + + "github.com/crossplaneio/crossplane-tools/internal/match" ) // HeaderGenerated is added to all files generated by angryjet. // See https://github.com/golang/go/issues/13560#issuecomment-288457920. -const HeaderGenerated = "Code generated by https://github.com/negz/angryjet. DO NOT EDIT." +const HeaderGenerated = "Code generated by angryjet. DO NOT EDIT." type options struct { Matches match.Object diff --git a/internal/match/match.go b/internal/match/match.go index 851e29b..6309cae 100644 --- a/internal/match/match.go +++ b/internal/match/match.go @@ -1,11 +1,27 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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 match identifies Go types as common Crossplane resources. package match import ( "go/types" - "github.com/negz/angryjet/internal/comments" - "github.com/negz/angryjet/internal/fields" + "github.com/crossplaneio/crossplane-tools/internal/comments" + "github.com/crossplaneio/crossplane-tools/internal/fields" ) // An Object matcher is a function that returns true if the supplied object diff --git a/internal/methods/methods.go b/internal/methods/methods.go index 5a380da..f16ffd5 100644 --- a/internal/methods/methods.go +++ b/internal/methods/methods.go @@ -1,3 +1,19 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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 methods contains methods that may be generated for a Go type. package methods @@ -6,8 +22,9 @@ import ( "strings" "github.com/dave/jennifer/jen" - "github.com/negz/angryjet/internal/fields" - "github.com/negz/angryjet/internal/generate" + + "github.com/crossplaneio/crossplane-tools/internal/fields" + "github.com/crossplaneio/crossplane-tools/internal/generate" ) // NewSetConditions returns a NewMethod that writes a SetConditions method for diff --git a/internal/methods/methods_test.go b/internal/methods/methods_test.go index 751db11..8face08 100644 --- a/internal/methods/methods_test.go +++ b/internal/methods/methods_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2019 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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 methods import ( @@ -7,7 +23,8 @@ import ( "github.com/dave/jennifer/jen" "github.com/google/go-cmp/cmp" - "github.com/negz/angryjet/internal/fields" + + "github.com/crossplaneio/crossplane-tools/internal/fields" ) type MockObject struct {