Skip to content
Permalink
Browse files

🏃 added vendor tgz for test projects using git-lfs

  • Loading branch information...
droot committed Apr 11, 2019
1 parent 637f606 commit 5dbed55124f5efdff779888f63f379f2b0bd6395
@@ -0,0 +1 @@
test/*.tgz filter=lfs diff=lfs merge=lfs -text
@@ -9,11 +9,17 @@ go:

git:
depth: 3
lfs_skip_smudge: true

go_import_path: sigs.k8s.io/kubebuilder

before_install:
- go get -u github.com/golang/dep/cmd/dep
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install git-lfs ; fi

before_script:
- git lfs install
- git lfs pull

# Install must be set to prevent default `go get` to run.
# The dependencies have already been vendored by `dep` so
@@ -7,7 +7,7 @@ Kubernetes projects require that you sign a Contributor License Agreement (CLA)
Please see https://git.k8s.io/community/CLA.md for more info.

## Contributing steps

1. Setup [Git LFS plugin](https://git-lfs.github.com/)
1. Submit an issue describing your proposed change to the repo in question.
1. The [repo owners](OWNERS) will respond to your issue promptly.
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.

## How to build kubebuilder locally

1. Setup Git LFS
Install the git-lfs plugin using the instructions from [git-lfs](https://git-lfs.github.com/) page.
Once installed, run `git lfs install` in your repo to setup git lfs hooks.

1. Build
```sh
$ go build -o /output/path/kubebuilder ./cmd
@@ -1,3 +1,19 @@
#!/usr/bin/env bash

# Copyright 2019 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.

#
# Makefile with some common workflow for dev, build and test
#
@@ -9,6 +25,9 @@ all: build test
build:
go build -o bin/kubebuilder ./cmd

generate:
./generated_golden.sh

test:
go test -v ./cmd/... ./pkg/...

@@ -21,6 +21,7 @@ import (
"fmt"
"log"
"os"
"os/exec"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
@@ -33,10 +34,13 @@ import (
type apiOptions struct {
apiScaffolder scaffold.API
resourceFlag, controllerFlag *flag.Flag

// runMake indicates whether to run make or not after scaffolding APIs
runMake bool
}

func (o *apiOptions) bindCmdFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&o.apiScaffolder.RunMake, "make", true,
cmd.Flags().BoolVar(&o.runMake, "make", true,
"if true, run make after generating files")
cmd.Flags().BoolVar(&o.apiScaffolder.DoResource, "resource", true,
"if set, generate the resource without prompting the user")
@@ -83,6 +87,23 @@ func (o *apiOptions) runAddAPI() {
if err := o.apiScaffolder.Scaffold(); err != nil {
log.Fatal(err)
}

if err := o.postScaffold(); err != nil {
log.Fatal(err)
}
}

func (o *apiOptions) postScaffold() error {
if o.runMake {
fmt.Println("Running make...")
cm := exec.Command("make") // #nosec
cm.Stderr = os.Stderr
cm.Stdout = os.Stdout
if err := cm.Run(); err != nil {
return fmt.Errorf("error running make: %v", err)
}
}
return nil
}

func newAPICommand() *cobra.Command {
@@ -35,17 +35,32 @@ scaffold_test_project() {
cd test/$project
# untar Gopkg.lock and vendor directory for appropriate project version
tar -zxf ../vendor.v$version.tgz
../../bin/kubebuilder init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
../../bin/kubebuilder create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update --make=false
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete --make=false
../../bin/kubebuilder create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
../../bin/kubebuilder alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update --make=false
../../bin/kubebuilder create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false
../../bin/kubebuilder alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create --make=false
../../bin/kubebuilder create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false
../../bin/kubebuilder alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update --make=false
../../bin/kubebuilder create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false

kb=../../bin/kubebuilder

$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
if [ $version == "1" ]; then
$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
$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
# 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 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
fi
make
rm -f Gopkg.lock
rm -rf ./vendor
@@ -18,8 +18,6 @@ package scaffold

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

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

// DoController indicates whether to scaffold controller files or not
DoController bool

// RunMake indicates whether to run make or not after scaffolding APIs
RunMake bool
}

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

if api.RunMake {
fmt.Println("Running make...")
cm := exec.Command("make") // #nosec
cm.Stderr = os.Stderr
cm.Stdout = os.Stdout
if err := cm.Run(); err != nil {
return fmt.Errorf("error running make: %v", err)
}
}

return nil
}

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

err := (&Scaffold{}).Execute(
input.Options{},
// &resourcev1.Register{Resource: r},
&resourcev1.Doc{
&resourcev2.ResourceDoc{
Input: input.Input{
Path: filepath.Join("api", r.Version, "doc.go"),
},
@@ -206,15 +188,6 @@ func (api *API) scaffoldV2() error {
return fmt.Errorf("error updating main.go with reconciler code: %v", err)
}
}
//
// if api.RunMake {
// fmt.Println("Running make...")
// cm := exec.Command("make") // #nosec
// cm.Stderr = os.Stderr
// cm.Stdout = os.Stdout
// if err := cm.Run(); err != nil {
// return fmt.Errorf("error running make: %v", err)
// }
// }

return nil
}
@@ -0,0 +1,62 @@
/*
Copyright 2018 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 v2

import (
"path/filepath"

"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
"sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource"
)

var _ input.File = &ResourceDoc{}

// Doc scaffolds the api/version/doc.go directory
type ResourceDoc struct {
input.Input

// Resource is a resource for the API version
Resource *resource.Resource

// Comments are additional lines to write to the doc.go file
Comments []string
}

// GetInput implements input.File
func (a *ResourceDoc) GetInput() (input.Input, error) {
if a.Path == "" {
a.Path = filepath.Join("api", a.Resource.Version, "doc.go")
}
a.TemplateBody = resourceDocGoTemplate
return a.Input, nil
}

// Validate validates the values
func (a *ResourceDoc) Validate() error {
return a.Resource.Validate()
}

var resourceDocGoTemplate = `{{ .Boilerplate }}
// Package {{.Resource.Version}} contains API Schema definitions for the {{ .Resource.Group }} {{.Resource.Version}} API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen={{ .Repo }}/api/{{ .Resource.Version }}
// +k8s:defaulter-gen=TypeMeta
// +groupName={{ .Resource.Group }}.{{ .Domain }}
package {{.Resource.Version}}
`
20 test.sh
@@ -22,13 +22,10 @@ source common.sh
function test_init_project {
header_text "performing init project"
kubebuilder init --domain example.com <<< "n"
# make
}

function test_make_project {
header_text "running make in project"
# kubebuilder init --domain example.com <<< "n"
# dep ensure -v
make
}

@@ -88,6 +85,17 @@ y
EOF
}

function test_project {
project_dir=$1
version=$2
header_text "performing tests in dir $project_dir for project version v$version"
cd test/$project_dir
tar -zxf ../vendor.v$version.tgz
make
rm -rf ./vendor && rm -f Gopkg.lock
cd -
}

prepare_staging_dir
fetch_tools
build_kb
@@ -130,6 +138,10 @@ cd ${go_workspace}/src/sigs.k8s.io/kubebuilder

go test ./cmd/... ./pkg/...

./generated_golden.sh
# test project v1
test_project project 1

# test project v2
test_project project_v2 2

exit $rc
@@ -17,7 +17,7 @@ limitations under the License.
// Package v1 contains API Schema definitions for the crew v1 API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=sigs.k8s.io/kubebuilder/test/project_v2/pkg/apis/crew
// +k8s:conversion-gen=sigs.k8s.io/kubebuilder/test/project_v2/api/v1
// +k8s:defaulter-gen=TypeMeta
// +groupName=crew.testproject.org
package v1

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 5dbed55

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