Migrate angryjet to crossplane-tools
Signed-off-by: Nic Cope <negz@rk0n.org>
This commit is contained in:
parent
6bf82cb09a
commit
20a2b98c2a
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
name: Bug Report
|
||||
about: Help us diagnose and fix bugs in Crossplane
|
||||
labels: bug
|
||||
---
|
||||
<!--
|
||||
Thank you for helping to improve Crossplane!
|
||||
|
||||
Please be sure to search for open issues before raising a new one. We use issues
|
||||
for bug reports and feature requests. Please find us at https://slack.crossplane.io
|
||||
for questions, support, and discussion.
|
||||
-->
|
||||
|
||||
### What happened?
|
||||
<!--
|
||||
Please let us know what behaviour you expected and how Crossplane diverged from
|
||||
that behaviour.
|
||||
-->
|
||||
|
||||
|
||||
### How can we reproduce it?
|
||||
<!--
|
||||
Help us to reproduce your bug as succinctly and precisely as possible. Artifacts
|
||||
such as example manifests or a script that triggers the issue are highly
|
||||
appreciated!
|
||||
-->
|
||||
|
||||
### What environment did it happen in?
|
||||
Crossplane Tools version:
|
||||
|
||||
<!--
|
||||
Include at least the version or commit of Crossplane you were running. Consider
|
||||
also including your:
|
||||
|
||||
* Cloud provider or hardware configuration
|
||||
* Kubernetes version (use `kubectl version`)
|
||||
* Kubernetes distribution (e.g. Tectonic, GKE, OpenShift)
|
||||
* OS (e.g. from /etc/os-release)
|
||||
* Kernel (e.g. `uname -a`)
|
||||
-->
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
name: Feature Request
|
||||
about: Help us make Crossplane more useful
|
||||
labels: enhancement
|
||||
---
|
||||
<!--
|
||||
Thank you for helping to improve Crossplane!
|
||||
|
||||
Please be sure to search for open issues before raising a new one. We use issues
|
||||
for bug reports and feature requests. Please find us at https://slack.crossplane.io
|
||||
for questions, support, and discussion.
|
||||
-->
|
||||
|
||||
### What problem are you facing?
|
||||
<!--
|
||||
Please tell us a little about your use case - it's okay if it's hypothetical!
|
||||
Leading with this context helps frame the feature request so we can ensure we
|
||||
implement it sensibly.
|
||||
--->
|
||||
|
||||
### How could Crossplane help solve your problem?
|
||||
<!--
|
||||
Let us know how you think Crossplane could help with your use case.
|
||||
-->
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<!--
|
||||
Thank you for helping to improve Crossplane!
|
||||
|
||||
We strongly recommend you look through our contributor guide at https://git.io/fj2m9
|
||||
if this is your first time opening a Crossplane pull request. You can find us in
|
||||
https://slack.crossplane.io/messages/dev if you need any help contributing.
|
||||
-->
|
||||
|
||||
### Description of your changes
|
||||
<!--
|
||||
Briefly describe what this pull request does. Be sure to direct your reviewers'
|
||||
attention to anything that needs special consideration.
|
||||
|
||||
We love pull requests that resolve an open Crossplane issue. If yours does, you
|
||||
can uncomment the below line to indicate which issue your PR fixes, for example
|
||||
"Fixes #500":
|
||||
|
||||
Fixes #
|
||||
-->
|
||||
|
||||
### Checklist
|
||||
<!--
|
||||
Please run through the below readiness checklist. The first two items are
|
||||
relevant to every Crossplane pull request.
|
||||
-->
|
||||
I have:
|
||||
- [ ] Run `make reviewable` to ensure this PR is ready for review.
|
||||
- [ ] Ensured this PR contains a neat, self documenting set of commits.
|
||||
|
|
@ -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
|
||||
|
|
@ -12,3 +12,8 @@
|
|||
*.out
|
||||
|
||||
vendor/
|
||||
|
||||
# Upbound build directories
|
||||
.cache
|
||||
.work
|
||||
_output
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "build"]
|
||||
path = build
|
||||
url = git@github.com:upbound/build
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
39
README.md
39
README.md
|
|
@ -1,20 +1,32 @@
|
|||
# angryjet [](https://godoc.org/github.com/negz/angryjet)
|
||||
# crossplane-tools [](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 [<flags>] [<packages>]
|
||||
$ angryjet generate-methodsets --help
|
||||
usage: angryjet generate-methodsets [<flags>] [<packages>]
|
||||
|
||||
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
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit ff9fe7dd3d553dad7b43a3afc960b2372eb5126f
|
||||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue