Skip to content

Commit 5dbed55

Browse files
committed
🏃 added vendor tgz for test projects using git-lfs
1 parent 637f606 commit 5dbed55

28 files changed

+166
-895
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/*.tgz filter=lfs diff=lfs merge=lfs -text

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ go:
99

1010
git:
1111
depth: 3
12+
lfs_skip_smudge: true
1213

1314
go_import_path: sigs.k8s.io/kubebuilder
1415

1516
before_install:
1617
- go get -u github.com/golang/dep/cmd/dep
18+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install git-lfs ; fi
19+
20+
before_script:
21+
- git lfs install
22+
- git lfs pull
1723

1824
# Install must be set to prevent default `go get` to run.
1925
# The dependencies have already been vendored by `dep` so

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Kubernetes projects require that you sign a Contributor License Agreement (CLA)
77
Please see https://git.k8s.io/community/CLA.md for more info.
88

99
## Contributing steps
10-
10+
1. Setup [Git LFS plugin](https://git-lfs.github.com/)
1111
1. Submit an issue describing your proposed change to the repo in question.
1212
1. The [repo owners](OWNERS) will respond to your issue promptly.
1313
1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above).
@@ -16,6 +16,10 @@ Please see https://git.k8s.io/community/CLA.md for more info.
1616

1717
## How to build kubebuilder locally
1818

19+
1. Setup Git LFS
20+
Install the git-lfs plugin using the instructions from [git-lfs](https://git-lfs.github.com/) page.
21+
Once installed, run `git lfs install` in your repo to setup git lfs hooks.
22+
1923
1. Build
2024
```sh
2125
$ go build -o /output/path/kubebuilder ./cmd

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2019 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+
117
#
218
# Makefile with some common workflow for dev, build and test
319
#
@@ -9,6 +25,9 @@ all: build test
925
build:
1026
go build -o bin/kubebuilder ./cmd
1127

28+
generate:
29+
./generated_golden.sh
30+
1231
test:
1332
go test -v ./cmd/... ./pkg/...
1433

cmd/api.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"log"
2323
"os"
24+
"os/exec"
2425

2526
"github.com/spf13/cobra"
2627
flag "github.com/spf13/pflag"
@@ -33,10 +34,13 @@ import (
3334
type apiOptions struct {
3435
apiScaffolder scaffold.API
3536
resourceFlag, controllerFlag *flag.Flag
37+
38+
// runMake indicates whether to run make or not after scaffolding APIs
39+
runMake bool
3640
}
3741

3842
func (o *apiOptions) bindCmdFlags(cmd *cobra.Command) {
39-
cmd.Flags().BoolVar(&o.apiScaffolder.RunMake, "make", true,
43+
cmd.Flags().BoolVar(&o.runMake, "make", true,
4044
"if true, run make after generating files")
4145
cmd.Flags().BoolVar(&o.apiScaffolder.DoResource, "resource", true,
4246
"if set, generate the resource without prompting the user")
@@ -83,6 +87,23 @@ func (o *apiOptions) runAddAPI() {
8387
if err := o.apiScaffolder.Scaffold(); err != nil {
8488
log.Fatal(err)
8589
}
90+
91+
if err := o.postScaffold(); err != nil {
92+
log.Fatal(err)
93+
}
94+
}
95+
96+
func (o *apiOptions) postScaffold() error {
97+
if o.runMake {
98+
fmt.Println("Running make...")
99+
cm := exec.Command("make") // #nosec
100+
cm.Stderr = os.Stderr
101+
cm.Stdout = os.Stdout
102+
if err := cm.Run(); err != nil {
103+
return fmt.Errorf("error running make: %v", err)
104+
}
105+
}
106+
return nil
86107
}
87108

88109
func newAPICommand() *cobra.Command {

generated_golden.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,32 @@ scaffold_test_project() {
3535
cd test/$project
3636
# untar Gopkg.lock and vendor directory for appropriate project version
3737
tar -zxf ../vendor.v$version.tgz
38-
../../bin/kubebuilder init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
39-
../../bin/kubebuilder create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
40-
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update --make=false
41-
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete --make=false
42-
../../bin/kubebuilder create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
43-
../../bin/kubebuilder alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update --make=false
44-
../../bin/kubebuilder create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false
45-
../../bin/kubebuilder alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create --make=false
46-
../../bin/kubebuilder create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false
47-
../../bin/kubebuilder alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update --make=false
48-
../../bin/kubebuilder create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false
38+
39+
kb=../../bin/kubebuilder
40+
41+
$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
42+
if [ $version == "1" ]; then
43+
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
44+
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update --make=false
45+
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete --make=false
46+
$kb create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
47+
$kb alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update --make=false
48+
$kb create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false
49+
$kb alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create --make=false
50+
$kb create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false
51+
$kb alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update --make=false
52+
$kb create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false
53+
elif [ $version == "2" ]; then
54+
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
55+
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update --make=false
56+
$kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete --make=false
57+
# TODO(droot): Adding a second group is a valid test case and kubebuilder is expected to report an error in this case. It
58+
# doesn't do that currently so leaving it commented so that we can enable it later.
59+
# $kb create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
60+
$kb create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false
61+
$kb alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update --make=false
62+
# $kb create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false
63+
fi
4964
make
5065
rm -f Gopkg.lock
5166
rm -rf ./vendor

pkg/scaffold/api.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package scaffold
1818

1919
import (
2020
"fmt"
21-
"os"
22-
"os/exec"
2321
"path/filepath"
2422
"strings"
2523

@@ -44,9 +42,6 @@ type API struct {
4442

4543
// DoController indicates whether to scaffold controller files or not
4644
DoController bool
47-
48-
// RunMake indicates whether to run make or not after scaffolding APIs
49-
RunMake bool
5045
}
5146

5247
// Validate validates whether API scaffold has correct bits to generate
@@ -140,16 +135,6 @@ func (api *API) scaffoldV1() error {
140135
}
141136
}
142137

143-
if api.RunMake {
144-
fmt.Println("Running make...")
145-
cm := exec.Command("make") // #nosec
146-
cm.Stderr = os.Stderr
147-
cm.Stdout = os.Stdout
148-
if err := cm.Run(); err != nil {
149-
return fmt.Errorf("error running make: %v", err)
150-
}
151-
}
152-
153138
return nil
154139
}
155140

@@ -159,13 +144,10 @@ func (api *API) scaffoldV2() error {
159144
if api.DoResource {
160145
fmt.Println(filepath.Join("api", r.Version,
161146
fmt.Sprintf("%s_types.go", strings.ToLower(r.Kind))))
162-
// fmt.Println(filepath.Join("pkg", "apis", r.Group, r.Version,
163-
// fmt.Sprintf("%s_types_test.go", strings.ToLower(r.Kind))))
164147

165148
err := (&Scaffold{}).Execute(
166149
input.Options{},
167-
// &resourcev1.Register{Resource: r},
168-
&resourcev1.Doc{
150+
&resourcev2.ResourceDoc{
169151
Input: input.Input{
170152
Path: filepath.Join("api", r.Version, "doc.go"),
171153
},
@@ -206,15 +188,6 @@ func (api *API) scaffoldV2() error {
206188
return fmt.Errorf("error updating main.go with reconciler code: %v", err)
207189
}
208190
}
209-
//
210-
// if api.RunMake {
211-
// fmt.Println("Running make...")
212-
// cm := exec.Command("make") // #nosec
213-
// cm.Stderr = os.Stderr
214-
// cm.Stdout = os.Stdout
215-
// if err := cm.Run(); err != nil {
216-
// return fmt.Errorf("error running make: %v", err)
217-
// }
218-
// }
191+
219192
return nil
220193
}

pkg/scaffold/v2/resource_doc.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 v2
18+
19+
import (
20+
"path/filepath"
21+
22+
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
23+
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
24+
)
25+
26+
var _ input.File = &ResourceDoc{}
27+
28+
// Doc scaffolds the api/version/doc.go directory
29+
type ResourceDoc struct {
30+
input.Input
31+
32+
// Resource is a resource for the API version
33+
Resource *resource.Resource
34+
35+
// Comments are additional lines to write to the doc.go file
36+
Comments []string
37+
}
38+
39+
// GetInput implements input.File
40+
func (a *ResourceDoc) GetInput() (input.Input, error) {
41+
if a.Path == "" {
42+
a.Path = filepath.Join("api", a.Resource.Version, "doc.go")
43+
}
44+
a.TemplateBody = resourceDocGoTemplate
45+
return a.Input, nil
46+
}
47+
48+
// Validate validates the values
49+
func (a *ResourceDoc) Validate() error {
50+
return a.Resource.Validate()
51+
}
52+
53+
var resourceDocGoTemplate = `{{ .Boilerplate }}
54+
55+
// Package {{.Resource.Version}} contains API Schema definitions for the {{ .Resource.Group }} {{.Resource.Version}} API group
56+
// +k8s:openapi-gen=true
57+
// +k8s:deepcopy-gen=package,register
58+
// +k8s:conversion-gen={{ .Repo }}/api/{{ .Resource.Version }}
59+
// +k8s:defaulter-gen=TypeMeta
60+
// +groupName={{ .Resource.Group }}.{{ .Domain }}
61+
package {{.Resource.Version}}
62+
`

test.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ source common.sh
2222
function test_init_project {
2323
header_text "performing init project"
2424
kubebuilder init --domain example.com <<< "n"
25-
# make
2625
}
2726

2827
function test_make_project {
2928
header_text "running make in project"
30-
# kubebuilder init --domain example.com <<< "n"
31-
# dep ensure -v
3229
make
3330
}
3431

@@ -88,6 +85,17 @@ y
8885
EOF
8986
}
9087

88+
function test_project {
89+
project_dir=$1
90+
version=$2
91+
header_text "performing tests in dir $project_dir for project version v$version"
92+
cd test/$project_dir
93+
tar -zxf ../vendor.v$version.tgz
94+
make
95+
rm -rf ./vendor && rm -f Gopkg.lock
96+
cd -
97+
}
98+
9199
prepare_staging_dir
92100
fetch_tools
93101
build_kb
@@ -130,6 +138,10 @@ cd ${go_workspace}/src/sigs.k8s.io/kubebuilder
130138

131139
go test ./cmd/... ./pkg/...
132140

133-
./generated_golden.sh
141+
# test project v1
142+
test_project project 1
143+
144+
# test project v2
145+
test_project project_v2 2
134146

135147
exit $rc

test/project_v2/api/v1/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
// Package v1 contains API Schema definitions for the crew v1 API group
1818
// +k8s:openapi-gen=true
1919
// +k8s:deepcopy-gen=package,register
20-
// +k8s:conversion-gen=sigs.k8s.io/kubebuilder/test/project_v2/pkg/apis/crew
20+
// +k8s:conversion-gen=sigs.k8s.io/kubebuilder/test/project_v2/api/v1
2121
// +k8s:defaulter-gen=TypeMeta
2222
// +groupName=crew.testproject.org
2323
package v1

test/project_v2/api/v1beta1/doc.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)