Skip to content

Commit 9ae8640

Browse files
authored
Merge pull request #433 from mengqiy/move_scaffolding
Move scaffold pkg and test project from controller-tools
2 parents 7c492d0 + 22f1006 commit 9ae8640

File tree

1,757 files changed

+260229
-13612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,757 files changed

+260229
-13612
lines changed

Gopkg.lock

Lines changed: 457 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Uncomment to update deps with dep tool
22

3-
[prune]
4-
non-go = true
5-
go-tests = true
3+
required = [
4+
"github.com/emicklei/go-restful",
5+
"github.com/go-openapi/spec",
6+
"github.com/onsi/ginkgo", # for integration testing
7+
"github.com/spf13/pflag",
8+
"k8s.io/client-go/plugin/pkg/client/auth/gcp", # for development against gcp
9+
"k8s.io/code-generator/cmd/deepcopy-gen", # for go generate
10+
"sigs.k8s.io/testing_frameworks/integration", # for integration testing
11+
]
612

713
[[constraint]]
814
name = "sigs.k8s.io/controller-tools"
@@ -13,3 +19,7 @@
1319
name = "gopkg.in/fsnotify.v1"
1420
source = "https://github.com/fsnotify/fsnotify.git"
1521
version="v1.4.7"
22+
23+
[prune]
24+
non-go = true
25+
go-tests = true

cmd/kubebuilder/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828
"github.com/spf13/cobra"
2929
flag "github.com/spf13/pflag"
3030

31-
"sigs.k8s.io/controller-tools/pkg/scaffold"
32-
"sigs.k8s.io/controller-tools/pkg/scaffold/controller"
33-
"sigs.k8s.io/controller-tools/pkg/scaffold/input"
34-
"sigs.k8s.io/controller-tools/pkg/scaffold/resource"
3531
"sigs.k8s.io/kubebuilder/cmd/kubebuilder/util"
32+
"sigs.k8s.io/kubebuilder/pkg/scaffold"
33+
"sigs.k8s.io/kubebuilder/pkg/scaffold/controller"
34+
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
35+
"sigs.k8s.io/kubebuilder/pkg/scaffold/resource"
3636
)
3737

3838
type apiOptions struct {

cmd/kubebuilder/init_project.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import (
2929
"github.com/spf13/cobra"
3030
flag "github.com/spf13/pflag"
3131

32-
"sigs.k8s.io/controller-tools/pkg/scaffold"
33-
"sigs.k8s.io/controller-tools/pkg/scaffold/input"
34-
"sigs.k8s.io/controller-tools/pkg/scaffold/manager"
35-
"sigs.k8s.io/controller-tools/pkg/scaffold/project"
3632
"sigs.k8s.io/kubebuilder/cmd/kubebuilder/util"
33+
"sigs.k8s.io/kubebuilder/pkg/scaffold"
34+
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
35+
"sigs.k8s.io/kubebuilder/pkg/scaffold/manager"
36+
"sigs.k8s.io/kubebuilder/pkg/scaffold/project"
3737
)
3838

3939
func newInitProjectCmd() *cobra.Command {

cmd/kubebuilder/vendor_update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"log"
2121

2222
"github.com/spf13/cobra"
23-
"sigs.k8s.io/controller-tools/pkg/scaffold"
24-
"sigs.k8s.io/controller-tools/pkg/scaffold/input"
25-
"sigs.k8s.io/controller-tools/pkg/scaffold/project"
23+
"sigs.k8s.io/kubebuilder/pkg/scaffold"
24+
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
25+
"sigs.k8s.io/kubebuilder/pkg/scaffold/project"
2626
)
2727

2828
func newVendorUpdateCmd() *cobra.Command {

cmd/kubebuilder/webhook.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import (
2727

2828
"k8s.io/apimachinery/pkg/api/meta"
2929
"k8s.io/apimachinery/pkg/runtime/schema"
30-
"sigs.k8s.io/controller-tools/pkg/scaffold"
31-
"sigs.k8s.io/controller-tools/pkg/scaffold/input"
32-
"sigs.k8s.io/controller-tools/pkg/scaffold/resource"
33-
"sigs.k8s.io/controller-tools/pkg/scaffold/webhook"
30+
"sigs.k8s.io/kubebuilder/pkg/scaffold"
31+
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
32+
"sigs.k8s.io/kubebuilder/pkg/scaffold/resource"
33+
"sigs.k8s.io/kubebuilder/pkg/scaffold/webhook"
3434
)
3535

3636
func newWebhookCmd() *cobra.Command {

generated_golden.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
19+
go build -o ./bin/kubebuilder sigs.k8s.io/kubebuilder/cmd/kubebuilder
20+
rm -rf ./test/project/*
21+
cd test/project
22+
ln -s ../../vendor vendor
23+
../../bin/kubebuilder init --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
24+
../../bin/kubebuilder create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
25+
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update
26+
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete
27+
../../bin/kubebuilder create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
28+
../../bin/kubebuilder alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update
29+
../../bin/kubebuilder create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false
30+
../../bin/kubebuilder alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create
31+
../../bin/kubebuilder create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false
32+
../../bin/kubebuilder alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update
33+
../../bin/kubebuilder create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false
34+
make
35+
rm -rf ./bin/
36+
cd -

pkg/scaffold/controller/add.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
"fmt"
21+
"path/filepath"
22+
"strings"
23+
24+
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
25+
"sigs.k8s.io/kubebuilder/pkg/scaffold/resource"
26+
)
27+
28+
var _ input.File = &AddController{}
29+
30+
// AddController scaffolds adds a new Controller.
31+
type AddController struct {
32+
input.Input
33+
34+
// Resource is a resource in the API group
35+
Resource *resource.Resource
36+
}
37+
38+
// GetInput implements input.File
39+
func (a *AddController) GetInput() (input.Input, error) {
40+
if a.Path == "" {
41+
a.Path = filepath.Join("pkg", "controller", fmt.Sprintf(
42+
"add_%s.go", strings.ToLower(a.Resource.Kind)))
43+
}
44+
a.TemplateBody = addControllerTemplate
45+
return a.Input, nil
46+
}
47+
48+
var addControllerTemplate = `{{ .Boilerplate }}
49+
50+
package controller
51+
52+
import (
53+
"{{ .Repo }}/pkg/controller/{{ lower .Resource.Kind }}"
54+
)
55+
56+
func init() {
57+
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
58+
AddToManagerFuncs = append(AddToManagerFuncs, {{ lower .Resource.Kind }}.Add)
59+
}
60+
`

0 commit comments

Comments
 (0)