Skip to content
Permalink
Browse files

feat: add multigroup support for v2

  • Loading branch information
camilamacedo86 committed Nov 14, 2019
1 parent c9d5a91 commit af8cf2daeeedad8ead53d28f15886a9c6940b003
Showing with 4,553 additions and 189 deletions.
  1. +1 −0 .gitignore
  2. +89 −0 cmd/edit.go
  3. +1 −0 cmd/main.go
  4. +8 −2 cmd/webhook_v2.go
  5. +36 −30 docs/book/src/migration/multi-group.md
  6. +73 −50 generate_golden.sh
  7. +3 −0 pkg/model/types.go
  8. +49 −24 pkg/scaffold/api.go
  9. +17 −0 pkg/scaffold/input/input.go
  10. +1 −0 pkg/scaffold/project/project.go
  11. +3 −1 pkg/scaffold/scaffold.go
  12. +16 −4 pkg/scaffold/util/util.go
  13. +10 −5 pkg/scaffold/v2/{ → controller}/controller.go
  14. +16 −6 pkg/scaffold/v2/{ → controller}/controller_suitetest.go
  15. +5 −1 pkg/scaffold/v2/group.go
  16. +40 −16 pkg/scaffold/v2/main.go
  17. +7 −3 pkg/scaffold/v2/webhook/webhook.go
  18. +8 −1 plugins/addon/type.go
  19. +24 −0 testdata/project-v2-multigroup/.gitignore
  20. +27 −0 testdata/project-v2-multigroup/Dockerfile
  21. +80 −0 testdata/project-v2-multigroup/Makefile
  22. +26 −0 testdata/project-v2-multigroup/PROJECT
  23. +63 −0 testdata/project-v2-multigroup/apis/crew/v1/captain_types.go
  24. +75 −0 testdata/project-v2-multigroup/apis/crew/v1/captain_webhook.go
  25. +36 −0 testdata/project-v2-multigroup/apis/crew/v1/groupversion_info.go
  26. +114 −0 testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go
  27. +36 −0 testdata/project-v2-multigroup/apis/foo.policy/v1/groupversion_info.go
  28. +63 −0 testdata/project-v2-multigroup/apis/foo.policy/v1/healthcheckpolicy_types.go
  29. +114 −0 testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go
  30. +36 −0 testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/groupversion_info.go
  31. +63 −0 testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/kraken_types.go
  32. +114 −0 testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go
  33. +36 −0 testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/groupversion_info.go
  34. +63 −0 testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/leviathan_types.go
  35. +114 −0 testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go
  36. +64 −0 testdata/project-v2-multigroup/apis/ship/v1/destroyer_types.go
  37. +36 −0 testdata/project-v2-multigroup/apis/ship/v1/groupversion_info.go
  38. +114 −0 testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go
  39. +63 −0 testdata/project-v2-multigroup/apis/ship/v1beta1/frigate_types.go
  40. +33 −0 testdata/project-v2-multigroup/apis/ship/v1beta1/frigate_webhook.go
  41. +36 −0 testdata/project-v2-multigroup/apis/ship/v1beta1/groupversion_info.go
  42. +114 −0 testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go
  43. +64 −0 testdata/project-v2-multigroup/apis/ship/v2alpha1/cruiser_types.go
  44. +36 −0 testdata/project-v2-multigroup/apis/ship/v2alpha1/groupversion_info.go
  45. +114 −0 testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go
  46. +25 −0 testdata/project-v2-multigroup/config/certmanager/certificate.yaml
  47. +5 −0 testdata/project-v2-multigroup/config/certmanager/kustomization.yaml
  48. +16 −0 testdata/project-v2-multigroup/config/certmanager/kustomizeconfig.yaml
  49. +56 −0 testdata/project-v2-multigroup/config/crd/bases/crew.testproject.org_captains.yaml
  50. +56 −0 testdata/project-v2-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml
  51. +56 −0 testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml
  52. +56 −0 testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml
  53. +56 −0 testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml
  54. +56 −0 testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml
  55. +56 −0 testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml
  56. +39 −0 testdata/project-v2-multigroup/config/crd/kustomization.yaml
  57. +17 −0 testdata/project-v2-multigroup/config/crd/kustomizeconfig.yaml
  58. +8 −0 testdata/project-v2-multigroup/config/crd/patches/cainjection_in_captains.yaml
  59. +8 −0 testdata/project-v2-multigroup/config/crd/patches/cainjection_in_cruisers.yaml
  60. +8 −0 testdata/project-v2-multigroup/config/crd/patches/cainjection_in_destroyers.yaml
  61. +8 −0 testdata/project-v2-multigroup/config/crd/patches/cainjection_in_frigates.yaml
  62. +8 −0 testdata/project-v2-multigroup/config/crd/patches/cainjection_in_healthcheckpolicies.yaml
  63. +8 −0 testdata/project-v2-multigroup/config/crd/patches/cainjection_in_krakens.yaml
  64. +8 −0 testdata/project-v2-multigroup/config/crd/patches/cainjection_in_leviathans.yaml
  65. +17 −0 testdata/project-v2-multigroup/config/crd/patches/webhook_in_captains.yaml
  66. +17 −0 testdata/project-v2-multigroup/config/crd/patches/webhook_in_cruisers.yaml
  67. +17 −0 testdata/project-v2-multigroup/config/crd/patches/webhook_in_destroyers.yaml
  68. +17 −0 testdata/project-v2-multigroup/config/crd/patches/webhook_in_frigates.yaml
  69. +17 −0 testdata/project-v2-multigroup/config/crd/patches/webhook_in_healthcheckpolicies.yaml
  70. +17 −0 testdata/project-v2-multigroup/config/crd/patches/webhook_in_krakens.yaml
  71. +17 −0 testdata/project-v2-multigroup/config/crd/patches/webhook_in_leviathans.yaml
  72. +74 −0 testdata/project-v2-multigroup/config/default/kustomization.yaml
  73. +25 −0 testdata/project-v2-multigroup/config/default/manager_auth_proxy_patch.yaml
  74. +23 −0 testdata/project-v2-multigroup/config/default/manager_webhook_patch.yaml
  75. +15 −0 testdata/project-v2-multigroup/config/default/webhookcainjection_patch.yaml
  76. +2 −0 testdata/project-v2-multigroup/config/manager/kustomization.yaml
  77. +39 −0 testdata/project-v2-multigroup/config/manager/manager.yaml
  78. +2 −0 testdata/project-v2-multigroup/config/prometheus/kustomization.yaml
  79. +15 −0 testdata/project-v2-multigroup/config/prometheus/monitor.yaml
  80. +13 −0 testdata/project-v2-multigroup/config/rbac/auth_proxy_role.yaml
  81. +12 −0 testdata/project-v2-multigroup/config/rbac/auth_proxy_role_binding.yaml
  82. +14 −0 testdata/project-v2-multigroup/config/rbac/auth_proxy_service.yaml
  83. +24 −0 testdata/project-v2-multigroup/config/rbac/captain_editor_role.yaml
  84. +20 −0 testdata/project-v2-multigroup/config/rbac/captain_viewer_role.yaml
  85. +24 −0 testdata/project-v2-multigroup/config/rbac/cruiser_editor_role.yaml
  86. +20 −0 testdata/project-v2-multigroup/config/rbac/cruiser_viewer_role.yaml
  87. +24 −0 testdata/project-v2-multigroup/config/rbac/destroyer_editor_role.yaml
  88. +20 −0 testdata/project-v2-multigroup/config/rbac/destroyer_viewer_role.yaml
  89. +24 −0 testdata/project-v2-multigroup/config/rbac/frigate_editor_role.yaml
  90. +20 −0 testdata/project-v2-multigroup/config/rbac/frigate_viewer_role.yaml
  91. +24 −0 testdata/project-v2-multigroup/config/rbac/healthcheckpolicy_editor_role.yaml
  92. +20 −0 testdata/project-v2-multigroup/config/rbac/healthcheckpolicy_viewer_role.yaml
  93. +24 −0 testdata/project-v2-multigroup/config/rbac/kraken_editor_role.yaml
  94. +20 −0 testdata/project-v2-multigroup/config/rbac/kraken_viewer_role.yaml
  95. +11 −0 testdata/project-v2-multigroup/config/rbac/kustomization.yaml
  96. +32 −0 testdata/project-v2-multigroup/config/rbac/leader_election_role.yaml
  97. +12 −0 testdata/project-v2-multigroup/config/rbac/leader_election_role_binding.yaml
  98. +24 −0 testdata/project-v2-multigroup/config/rbac/leviathan_editor_role.yaml
  99. +20 −0 testdata/project-v2-multigroup/config/rbac/leviathan_viewer_role.yaml
  100. +148 −0 testdata/project-v2-multigroup/config/rbac/role.yaml
  101. +12 −0 testdata/project-v2-multigroup/config/rbac/role_binding.yaml
  102. +7 −0 testdata/project-v2-multigroup/config/samples/crew_v1_captain.yaml
  103. +7 −0 testdata/project-v2-multigroup/config/samples/foo.policy_v1_healthcheckpolicy.yaml
  104. +7 −0 testdata/project-v2-multigroup/config/samples/sea-creatures_v1beta1_kraken.yaml
  105. +7 −0 testdata/project-v2-multigroup/config/samples/sea-creatures_v1beta2_leviathan.yaml
  106. +7 −0 testdata/project-v2-multigroup/config/samples/ship_v1_destroyer.yaml
  107. +7 −0 testdata/project-v2-multigroup/config/samples/ship_v1beta1_frigate.yaml
  108. +7 −0 testdata/project-v2-multigroup/config/samples/ship_v2alpha1_cruiser.yaml
  109. +6 −0 testdata/project-v2-multigroup/config/webhook/kustomization.yaml
  110. +25 −0 testdata/project-v2-multigroup/config/webhook/kustomizeconfig.yaml
  111. +52 −0 testdata/project-v2-multigroup/config/webhook/manifests.yaml
  112. +12 −0 testdata/project-v2-multigroup/config/webhook/service.yaml
  113. +53 −0 testdata/project-v2-multigroup/controllers/crew/captain_controller.go
  114. +80 −0 testdata/project-v2-multigroup/controllers/crew/suite_test.go
  115. +53 −0 testdata/project-v2-multigroup/controllers/foo.policy/healthcheckpolicy_controller.go
  116. +80 −0 testdata/project-v2-multigroup/controllers/foo.policy/suite_test.go
  117. +53 −0 testdata/project-v2-multigroup/controllers/sea-creatures/kraken_controller.go
  118. +53 −0 testdata/project-v2-multigroup/controllers/sea-creatures/leviathan_controller.go
  119. +84 −0 testdata/project-v2-multigroup/controllers/sea-creatures/suite_test.go
  120. +53 −0 testdata/project-v2-multigroup/controllers/ship/cruiser_controller.go
  121. +10 −9 ...rollers/namespace_controller.go → project-v2-multigroup/controllers/ship/destroyer_controller.go}
  122. +53 −0 testdata/project-v2-multigroup/controllers/ship/frigate_controller.go
  123. +88 −0 testdata/project-v2-multigroup/controllers/ship/suite_test.go
  124. +12 −0 testdata/project-v2-multigroup/go.mod
  125. +15 −0 testdata/project-v2-multigroup/hack/boilerplate.go.txt
  126. +155 −0 testdata/project-v2-multigroup/main.go
  127. +0 −20 testdata/project-v2/config/rbac/role.yaml
  128. +0 −5 testdata/project-v2/controllers/suite_test.go
  129. +0 −1 testdata/project-v2/go.mod
  130. +0 −11 testdata/project-v2/main.go
@@ -21,3 +21,4 @@ bin/*
# skip testdata go.mod, since it may have
# different result depending on go version
/testdata/project-v2/go.sum
/testdata/project-v2-multigroup/go.sum
@@ -0,0 +1,89 @@
/*
Copyright 2017 The Kubernetes 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 (
"fmt"
"io/ioutil"
"log"

"github.com/spf13/cobra"

"sigs.k8s.io/kubebuilder/pkg/scaffold"
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
"sigs.k8s.io/kubebuilder/pkg/scaffold/project"
"sigs.k8s.io/yaml"
)

func newEditProjectCmd() *cobra.Command {

opts := editProjectCmdOptions{}

editProjectCmd := &cobra.Command{
Use: "edit",
Short: "This command will edit the configuration of the PROJECT file",
Long: `This command will edit the configuration of the PROJECT file`,
Example: `
# To enable the multigroup layout/support
kubebuilder edit --multigroup
# To disable the multigroup layout/support
kubebuilder edit --multigroup=false`,
Run: func(cmd *cobra.Command, args []string) {
dieIfNoProject()

projectInfo, err := scaffold.LoadProjectFile("PROJECT")
if err != nil {
log.Fatalf("failed to read the PROJECT file: %v", err)
}

if projectInfo.Version != project.Version2 {
log.Fatalf("kubebuilder multigroup is for project version: 2, the version of this project is: %s \n", projectInfo.Version)
}

// Set MultiGroup Option
projectInfo.MultiGroup = opts.multigroup

err = saveProjectFile("PROJECT", &projectInfo)
if err != nil {
log.Fatalf("error updating project file with resource information : %v \n", err)
}
},
}

editProjectCmd.Flags().BoolVar(&opts.multigroup, "multigroup", false,
"if set as true, then the tool will generate the project files with multigroup layout")

return editProjectCmd
}

// saveProjectFile saves the given ProjectFile at the given path.
func saveProjectFile(path string, project *input.ProjectFile) error {
content, err := yaml.Marshal(project)
if err != nil {
return fmt.Errorf("error marshalling project info %v", err)
}
err = ioutil.WriteFile(path, content, 0666)
if err != nil {
return fmt.Errorf("failed to save project file at %s %v", path, err)
}
return nil
}

type editProjectCmdOptions struct {
multigroup bool
}
@@ -112,6 +112,7 @@ func main() {

rootCmd.AddCommand(
newInitProjectCmd(),
newEditProjectCmd(),
newCreateCmd(),
version.NewVersionCmd(),
)
@@ -71,8 +71,14 @@ func newWebhookV2Cmd() *cobra.Command {

fmt.Println("Writing scaffold for you to edit...")

fmt.Println(filepath.Join("api", o.res.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(o.res.Kind))))
if projectInfo.MultiGroup {
fmt.Println(filepath.Join("apis", o.res.Group, o.res.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(o.res.Kind))))
} else {
fmt.Println(filepath.Join("api", o.res.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(o.res.Kind))))
}

if o.conversion {
fmt.Println(`Webhook server has been set up for you.
You need to implement the conversion.Hub and conversion.Convertible interfaces for your CRD types.`)
@@ -2,16 +2,15 @@

<aside class="note warning">

<h1>Work In Progress: Manual Work Incoming</h1>
<h1>Note</h1>

Multi-group scaffolding support is not present in the initial version of
Multi-group scaffolding support was not present in the initial version of
the KubeBuilder v2 scaffolding (as of KubeBuilder v2.0.0).

Once you switch to a multi-group layout, additional manual work will be
needed to create new API groups.

Support will eventually be added for scaffolding -- see
[kubernetes-sigs/kubebuilder#923][multi-group-issue] for more information.
To change the layout of your project to support Multi-Group run the command
`kubebuilder edit --multigroup=true`. Once you switch to a multi-group layout, the new Kinds
will be generated in the new layout but additional manual work is needed
to move the old API groups to the new layout.

</aside>

@@ -33,47 +32,54 @@ Then, we'll rename `api` to `apis` to be more clear, and we'll move our
existing APIs into a new subdirectory, "batch":

```bash
mv api apis
mkdir apis/batch
mv apis/v* batch/
mv api/* apis/batch
# After ensuring that all was moved successfully remove the old directory `api/`
rm -rf api/
```


After moving the APIs to a new directory, the same needs to be applied to the controllers:

```bash
mkdir controllers/batch
mv controllers/* controllers/batch/
```

Next, we'll need to update all the references to the old package name. For
CronJob, that'll be `main.go` and `controllers/cronjob_controller.go`. If
you've added additional files to your project, you'll need to track down
Next, we'll need to update all the references to the old package name.
For CronJob, that'll be `main.go` and `controllers/batch/cronjob_controller.go`.

If you've added additional files to your project, you'll need to track down
imports there as well.

Finally, we'll add a new line to `PROJECT` that marks this as
a multi-group project:
Finally, we'll run the command which enable the multi-group layout in the project:

```
kubebuilder edit --multigroup=true
```

When the command `kubebuilder edit --multigroup=true` is executed it will add a new line
to `PROJECT` that marks this a multi-group project:

```yaml
version: "2"
domain: tutorial.kubebuilder.io
repo: tutorial.kubebuilder.io/project
multigroup: true
```

While this option doesn't do anything right now, it'll indicate to
KubeBuilder in future versions that this is a multi-group project.

Now that we've migrated this to a multi-group project, normal KubeBuilder
scaffolding won't work (as of KubeBuilder v2.0.0 -- see the warning at the
top of this page). You'll need to copy the setup that KubeBuilder
normally does to add new groups for the moment:

- Copy over `<kind>_types.go` and `groupversion_info.go` to
`apis/<group>/<version>`
Note that this option indicates to KubeBuilder that this is a multi-group project.

- Register the new group-version with the Scheme in `main.go`

- Add a new `<kind>_controller.go` file

- Add the controller to the manager in `main.go`
In this way, if the project is not new and has previous APIs already implemented will be in the previous structure.
Notice that with the `multi-group` project the Kind API's files are
created under `apis/<group>/<version>` instead of `api/<version>`.
Also, note that the controllers will be created under `pkg/controllers/<group>` instead of `pkg/controllers`.
That is the reason why we moved the previously generated APIs with the provided scripts in the previous steps.
Remember to update the references afterwards.

The [CronJob tutorial][cronjob-tutorial] explains each of these changes in
more detail (in the context of how they're generated by KubeBuilder for
single-group projects).

[multi-group-issue]: https://github.com/kubernetes-sigs/kubebuilder/issues/923 "KubeBuilder Issue #923"

[cronjob-tutorial]: /cronjob-tutorial/cronjob-tutorial.md "Tutorial: Building CronJob"
@@ -19,7 +19,7 @@ set -e
source common.sh

build_kb() {
go build -o ./bin/kubebuilder sigs.k8s.io/kubebuilder/cmd
go build -o ./bin/kubebuilder sigs.k8s.io/kubebuilder/cmd
}


@@ -28,63 +28,86 @@ build_kb() {
# project-version.
#
scaffold_test_project() {
project=$1
version=$2
testdata_dir=$(pwd)/testdata
mkdir -p ./testdata/$project
rm -rf ./testdata/$project/*
pushd .
cd testdata/$project
project=$1
version=$2
testdata_dir=$(pwd)/testdata
mkdir -p ./testdata/$project
rm -rf ./testdata/$project/*
pushd .
cd testdata/$project
kb=$testdata_dir/../bin/kubebuilder
oldgopath=$GOPATH
if [ $version == "1" ]; then
export GO111MODULE=off
export GOPATH=$(pwd)/../.. # go ignores vendor under testdata, so fake out a gopath
# untar Gopkg.lock and vendor directory for appropriate project version
download_vendor_archive
tar -zxf $tmp_root/vendor.v$version.tgz

kb=$testdata_dir/../bin/kubebuilder
$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update --make=false
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete --make=false
$kb create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
$kb alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update --make=false
$kb create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false
$kb alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create --make=false
$kb create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false
$kb alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update --make=false
$kb create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false
elif [ $version == "2" ]; then
header_text 'Starting to generate projects with version 2'
if [ $project == "project-v2" ]; then
header_text 'Generating project-v2'
export GO111MODULE=on
export PATH=$PATH:$(go env GOPATH)/bin
go mod init sigs.k8s.io/kubebuilder/testdata/project-v2 # our repo autodetection will traverse up to the kb module if we don't do this

oldgopath=$GOPATH
if [ $version == "1" ]; then
export GO111MODULE=off
export GOPATH=$(pwd)/../.. # go ignores vendor under testdata, so fake out a gopath
# untar Gopkg.lock and vendor directory for appropriate project version
download_vendor_archive
tar -zxf $tmp_root/vendor.v$version.tgz
header_text 'initializing project-v2 ...'
$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors"

$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update --make=false
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete --make=false
$kb create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
$kb alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update --make=false
$kb create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false
$kb alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create --make=false
$kb create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false
$kb alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update --make=false
$kb create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false
elif [ $version == "2" ]; then
export GO111MODULE=on
export PATH=$PATH:$(go env GOPATH)/bin
go mod init sigs.k8s.io/kubebuilder/testdata/project-v2 # our repo autodetection will traverse up to the kb module if we don't do this
header_text 'Creating APIs ...'
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false
$kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
$kb create webhook --group crew --version v1 --kind FirstMate --conversion
$kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false
elif [ $project == "project-v2-multigroup" ]; then
header_text 'Generating project-v2-multigroup'
export GO111MODULE=on
export PATH=$PATH:$(go env GOPATH)/bin
go mod init sigs.k8s.io/kubebuilder/testdata/project-v2-multigroup # our repo autodetection will traverse up to the kb module if we don't do this

$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors"
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false
$kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
$kb create webhook --group crew --version v1 --kind FirstMate --conversion
$kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false
# TODO(droot): Adding a second group is a valid test case and kubebuilder is expected to report an error in this case. It
# doesn't do that currently so leaving it commented so that we can enable it later.
# $kb create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
$kb create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false
# $kb create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false
fi
make all test # v2 doesn't test by default
rm -f Gopkg.lock
rm -f go.sum
rm -rf ./vendor
rm -rf ./bin
export GOPATH=$oldgopath
popd
header_text 'initializing project-v2-multigroup ...'
$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors"

header_text 'Switching to multigroup layout ...'
$kb edit --multigroup=true

header_text 'Creating APIs ...'
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false
$kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation
$kb create api --group ship --version v1beta1 --kind Frigate --controller=true --resource=true --make=false
$kb create webhook --group ship --version v1beta1 --kind Frigate --conversion
$kb create api --group ship --version v1 --kind Destroyer --controller=true --resource=true --namespaced=false --make=false
$kb create api --group ship --version v2alpha1 --kind Cruiser --controller=true --resource=true --namespaced=false --make=false
$kb create api --group sea-creatures --version v1beta1 --kind Kraken --controller=true --resource=true --make=false
$kb create api --group sea-creatures --version v1beta2 --kind Leviathan --controller=true --resource=true --make=false
$kb create api --group foo.policy --version v1 --kind HealthCheckPolicy --controller=true --resource=true --make=false
fi
fi
make all test # v2 doesn't test by default
rm -f Gopkg.lock
rm -f go.sum
rm -rf ./vendor
rm -rf ./bin
export GOPATH=$oldgopath
popd
}

set -e

build_kb
scaffold_test_project gopath/src/project 1
scaffold_test_project project-v2 2
scaffold_test_project project-v2-multigroup 2
@@ -27,6 +27,9 @@ type Universe struct {
Resource *Resource `json:"resource,omitempty"`

Files []*File `json:"files,omitempty"`

// Multigroup tracks if the project has more than one group
MultiGroup bool `json:"multigroup,omitempty"`
}

// Resource describes the resource currently being generated

0 comments on commit af8cf2d

Please sign in to comment.
You can’t perform that action at this time.