Skip to content

Commit

Permalink
clean v1: remove the v1 code which is no longer supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed May 1, 2020
1 parent d6e2b99 commit 08861e7
Show file tree
Hide file tree
Showing 211 changed files with 99 additions and 9,552 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
3 changes: 0 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ import (

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

func main() {
c, err := cli.New(
cli.WithPlugins(
&pluginv1.Plugin{},
&pluginv2.Plugin{},
),
cli.WithDefaultPlugins(
&pluginv1.Plugin{},
&pluginv2.Plugin{},
),
cli.WithExtraCommands(
Expand Down
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.

18 changes: 8 additions & 10 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ func (c *cli) initialize() error {
} else if err == nil {
c.configured = true
c.projectVersion = projectConfig.Version

if projectConfig.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")
}
} else {
return fmt.Errorf("failed to read config: %v", err)
}
Expand Down Expand Up @@ -359,16 +364,12 @@ func validatePlugins(plugins ...plugin.Base) error {
// buildRootCmd returns a root command with a subcommand tree reflecting the
// current project's state.
func (c cli) buildRootCmd() *cobra.Command {
configuredAndV1 := c.configured && c.projectVersion == config.Version1

rootCmd := c.defaultCommand()

// kubebuilder alpha
alphaCmd := c.newAlphaCmd()
// kubebuilder alpha webhook (v1 only)
if configuredAndV1 {
alphaCmd.AddCommand(c.newCreateWebhookCmd())
}

// Only add alpha group if it has subcommands
if alphaCmd.HasSubCommands() {
rootCmd.AddCommand(alphaCmd)
}
Expand All @@ -377,10 +378,7 @@ func (c cli) buildRootCmd() *cobra.Command {
createCmd := c.newCreateCmd()
// kubebuilder create api
createCmd.AddCommand(c.newCreateAPICmd())
// kubebuilder create webhook (!v1)
if !configuredAndV1 {
createCmd.AddCommand(c.newCreateWebhookCmd())
}
createCmd.AddCommand(c.newCreateWebhookCmd())
if createCmd.HasSubCommands() {
rootCmd.AddCommand(createCmd)
}
Expand Down
45 changes: 0 additions & 45 deletions pkg/model/resource/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package resource

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

Expand Down Expand Up @@ -85,10 +83,6 @@ type Options struct {

// Namespaced is true if the resource is namespaced.
Namespaced bool

// CreateExampleReconcileBody will create a Deployment in the Reconcile example.
// v1 only
CreateExampleReconcileBody bool
}

// Validate verifies that all the fields have valid values
Expand Down Expand Up @@ -165,45 +159,6 @@ func (opts *Options) safeImport(unsafe string) string {
return safe
}

// NewV1Resource creates a new resource from the options specific to v1
func (opts *Options) NewV1Resource(c *config.Config, doResource bool) *Resource {
res := opts.newResource()

replacer := res.Replacer()

// NOTE: while directories can have "-" and ".", v1 needs that directory to be a Go package
// and that is the reason why we remove them for the directory
pkg := replacer.Replace(path.Join(c.Repo, "pkg", "apis", "%[group-package-name]", "%[version]"))
domain := c.Domain

// pkg and domain may need to be changed in case we are referring to a builtin core resource:
// - Check if we are scaffolding the resource now => project resource
// - Check if we already scaffolded the resource => project resource
// - Check if the resource group is a well-known core group => builtin core resource
// - In any other case, default to => project resource
// TODO: need to support '--resource-pkg-path' flag for specifying resourcePath
if !doResource {
file := replacer.Replace(filepath.Join(
"pkg", "apis", "%[group-package-name]", "%[version]", "%[kind]_types.go"))
if _, err := os.Stat(file); os.IsNotExist(err) {
if coreDomain, found := coreGroups[opts.Group]; found {
pkg = replacer.Replace(path.Join("k8s.io", "api", "%[group]", "%[version]"))
domain = coreDomain
}
}
}

res.Package = pkg
res.Domain = opts.Group
if domain != "" {
res.Domain += "." + domain
}

res.CreateExampleReconcileBody = opts.CreateExampleReconcileBody

return res
}

// NewResource creates a new resource from the options
func (opts *Options) NewResource(c *config.Config, doResource bool) *Resource {
res := opts.newResource()
Expand Down
4 changes: 0 additions & 4 deletions pkg/model/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ type Resource struct {

// Namespaced is true if the resource is namespaced.
Namespaced bool `json:"namespaced,omitempty"`

// CreateExampleReconcileBody will create a Deployment in the Reconcile example.
// v1 only
CreateExampleReconcileBody bool `json:"-"`
}

// GVK returns the group-version-kind information to check against tracked resources in the configuration file
Expand Down
Loading

0 comments on commit 08861e7

Please sign in to comment.