Skip to content

Commit

Permalink
clean code - remove V1 implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 authored and Camila Macedo committed Apr 29, 2020
1 parent d6e2b99 commit 6e8987d
Show file tree
Hide file tree
Showing 213 changed files with 135 additions and 9,858 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ go_import_path: sigs.k8s.io/kubebuilder

services: docker

# Install must be set to prevent default `go get` to run.
# The dependencies have already been vendored by `dep` so
# we don't need to fetch them.
install: skip

script: ./test.sh

jobs:
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Please see https://git.k8s.io/community/CLA.md for more info.
## Prerequisites

- [go](https://golang.org/dl/) version v1.13+.
- [dep](https://github.com/golang/dep) dep v0.5+
- [docker](https://docs.docker.com/install/) version 17.03+.
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) version v1.11.3+.
- [kustomize](https://sigs.k8s.io/kustomize/docs/INSTALL.md) v3.1.0+
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ generate: ## Update/generate all mock data. You should run this commands to upda
.PHONY: generate-testdata
generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/kubebuilder
GO111MODULE=on ./generate_testdata.sh

.PHONY: generate-vendor
generate-vendor: ## (Deprecated) Update/generate the vendor by using the path $GOPATH/src/sigs.k8s.io/kubebuilder-test
GO111MODULE=off ./generate_vendor.sh

.PHONY: lint
lint: ## Run code lint checks
./scripts/verify.sh
Expand Down
1 change: 0 additions & 1 deletion check_testdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export TRACE=1
export GO111MODULE=on

fetch_tools
install_go_dep
build_kb

setup_envs
Expand Down
6 changes: 0 additions & 6 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ func (o *editOptions) bindFlags(cmd *cobra.Command) {
}

func (o *editOptions) Validate() error {
if !o.config.IsV2() && !o.config.IsV3() {
if o.config.MultiGroup {
return fmt.Errorf("multiple group support can't be enabled for version %s", o.config.Version)
}
}

return nil
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@ import (
"log"

"sigs.k8s.io/kubebuilder/cmd/version"
"sigs.k8s.io/kubebuilder/internal/config"
"sigs.k8s.io/kubebuilder/pkg/cli"
pluginv1 "sigs.k8s.io/kubebuilder/pkg/plugin/v1"
pluginv2 "sigs.k8s.io/kubebuilder/pkg/plugin/v2"
)

func main() {
if err := config.CheckProjectVersionSupported(); err != nil {
log.Fatal(err)
}

c, err := cli.New(
cli.WithPlugins(
&pluginv1.Plugin{},
&pluginv2.Plugin{},
),
cli.WithDefaultPlugins(
&pluginv1.Plugin{},
&pluginv2.Plugin{},
),
cli.WithExtraCommands(
newEditCmd(),
newUpdateCmd(),
newCompletionCmd(),
version.NewCmd(),
),
Expand Down
79 changes: 0 additions & 79 deletions cmd/update.go

This file was deleted.

49 changes: 0 additions & 49 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,6 @@ function build_kb {
GO111MODULE=on go build $opts -o $tmp_root/kubebuilder/bin/kubebuilder ./cmd
}

# Required to install the go dep in the https://prow.k8s.io/.
function install_dep_by_git {
header_text "Checking for dep"
export PATH=$(go env GOPATH)/src/github.com/golang/dep/bin:$PATH
if ! is_installed dep ; then
header_text "Installing dep"
DEP_DIR=$(go env GOPATH)/src/github.com/golang/dep
mkdir -p $DEP_DIR
pushd $DEP_DIR
git clone https://github.com/golang/dep.git .
DEP_LATEST=$(git describe --abbrev=0 --tags)
git checkout $DEP_LATEST
mkdir bin
GO111MODULE=off go build -ldflags="-X main.version=$DEP_LATEST" -o bin/dep ./cmd/dep
popd
fi
}

function install_go_dep {
header_text "Checking for dep"
export PATH=$(go env GOPATH)/src/github.com/golang/dep/bin:$PATH
if ! is_installed dep ; then
header_text "Installing dep"
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
fi
}

function install_kind {
header_text "Checking for kind"
if ! is_installed kind ; then
Expand Down Expand Up @@ -218,27 +191,6 @@ function setup_envs {
export TEST_DEP=$tmp_root/kubebuilder/init_project
}

# download_vendor_archive downloads vendor tarball for v1 projects. It skips the
# download if tarball exists.
function download_vendor_archive {
archive_name="vendor.v1.tgz"
archive_download_url="https://storage.googleapis.com/kubebuilder-vendor/$archive_name"
archive_path="$tmp_root/$archive_name"
header_text "checking the path $archive_path to download the $archive_name"
if [ -f $archive_path ]; then
header_text "removing file which exists"
rm $archive_path
fi
header_text "downloading vendor archive from $archive_download_url"
curl -sL ${archive_download_url} -o "$archive_path"
}

function restore_go_deps {
header_text "restoring Go dependencies"
download_vendor_archive
tar -zxf $tmp_root/vendor.v1.tgz
}

function cache_project {
header_text "caching initialized projects"
if [ -d "$TEST_DEP" ]; then
Expand All @@ -252,6 +204,5 @@ function dump_project {
header_text "restoring cached project"
if [ -d "$TEST_DEP" ]; then
cp -r $TEST_DEP/* .
restore_go_deps
fi
}
25 changes: 2 additions & 23 deletions generate_testdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,7 @@ scaffold_test_project() {
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 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" ] || [ $version == "3-alpha" ]; then
if [ $version == "2" ] || [ $version == "3-alpha" ]; then
header_text "Starting to generate projects with version $version"
header_text "Generating $project"

Expand Down Expand Up @@ -96,10 +78,8 @@ scaffold_test_project() {
$kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false --pattern=addon
fi
fi
make all test # v2 doesn't test by default
rm -f Gopkg.lock
make all test
rm -f go.sum
rm -rf ./vendor
rm -rf ./bin
export GOPATH=$oldgopath
popd
Expand All @@ -108,7 +88,6 @@ scaffold_test_project() {
set -e

build_kb
scaffold_test_project gopath/src/project 1
scaffold_test_project project-v2 2
scaffold_test_project project-v2-multigroup 2
scaffold_test_project project-v2-addon 2
Expand Down
61 changes: 0 additions & 61 deletions generate_vendor.sh

This file was deleted.

25 changes: 25 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const (

// DefaultVersion is the version which will be used when the version flag is not provided
DefaultVersion = config.Version3Alpha

// To print error with colored
NoticeColor = "\033[1;36m%s\033[0m"
)

func exists(fs afero.Fs, path string) (bool, error) {
Expand Down Expand Up @@ -179,3 +182,25 @@ type saveError struct {
func (e saveError) Error() string {
return fmt.Sprintf("unable to save the configuration: %v", e.err)
}

// CheckProjectVersionSupported returns true if the project is already configured and it is v2
func CheckProjectVersionSupported() error {
cfg, err := Read()
if os.IsNotExist(err) {
return nil
}

if err != nil {
return err
}

if cfg.IsV1() {
return fmt.Errorf(NoticeColor, "The v1 projects are no longer supported.\n"+
"See how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n")
}

if !cfg.IsV2() && !cfg.IsV3() {
return fmt.Errorf("unknown project version %v", cfg.Version)
}
return nil
}
Loading

0 comments on commit 6e8987d

Please sign in to comment.