Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
9347eae
:book: suplememting info about release process
camilamacedo86 Feb 18, 2021
5cc7d55
Add tests to the DNS validation package
Adirio Feb 18, 2021
7a7a66f
Remove old TODOs that are no longer valid
Adirio Feb 22, 2021
615f8c2
Merge pull request #2033 from Adirio/cleanup-todos
k8s-ci-robot Feb 22, 2021
33036c5
Merge pull request #2034 from Adirio/tests/dns-validation
k8s-ci-robot Feb 22, 2021
c45c5da
fix unit tests to work with later versions of ginkgo/gomega
joelanford Feb 25, 2021
ed6539a
Merge pull request #2039 from joelanford/fix/test-unit
k8s-ci-robot Feb 25, 2021
d121077
:seedling: fix CI to use the correct g version
camilamacedo86 Feb 25, 2021
d07dfcc
Merge pull request #2040 from camilamacedo86/fix-ci-go-version
k8s-ci-robot Feb 25, 2021
4bf571c
Explicitly define WithCompletion as an Option
Adirio Feb 26, 2021
cfbf62d
Merge pull request #2045 from Adirio/completion-option
k8s-ci-robot Feb 26, 2021
1586c2d
Generalize CRD and webhook version related methods in Config
Adirio Feb 26, 2021
0610cc8
Merge pull request #2047 from Adirio/config-interface
k8s-ci-robot Feb 26, 2021
64ad95f
:seedling: Update golangci-lint to latest version
Feb 25, 2021
a90cbd5
Merge pull request #2041 from goutamtadi1/update-golangci-lint
k8s-ci-robot Feb 27, 2021
75ac496
Add https to the webpage
mkumatag Mar 1, 2021
80177d3
Merge pull request #2050 from mkumatag/fix_link
k8s-ci-robot Mar 1, 2021
2ef938f
Add go mod tidy to be executed after the scaffolding api
dastergon Feb 24, 2021
2b46403
Merge pull request #2037 from dastergon/fix-api-generation
k8s-ci-robot Mar 1, 2021
1a74c97
docs: update CRD path for multi-group api
ahalimx86 Mar 2, 2021
bc7ce7d
netlify.toml: update redirects for v3.0.0
estroz Mar 4, 2021
d905233
(go/v3) bump controller-runtime to v0.7.2
estroz Mar 5, 2021
f81fb0d
feat: improve service monitor configuration
johanneswuerbach Mar 5, 2021
bdfa597
Use client.New instead of manager client in tests
leovct Mar 6, 2021
984816b
Merge pull request #2062 from estroz/docs/update-redirects
k8s-ci-robot Mar 8, 2021
6de8014
Merge pull request #2054 from ahalim-intel/update_migrations
k8s-ci-robot Mar 8, 2021
2018a4f
Merge pull request #2064 from estroz/deps/bump-c-r-0.7.2
k8s-ci-robot Mar 8, 2021
01293b2
Fix the config registry public API
Adirio Mar 9, 2021
9a121a1
test/e2e: export KIND_CLUSTER so local tests get correct cluster name
estroz Mar 9, 2021
b6e2ead
Merge pull request #2071 from estroz/chore/correct-test-cluster-name
k8s-ci-robot Mar 9, 2021
c748ebd
This commit adds a ServiceAccount (config/rbac/service_account.yaml)
estroz Mar 8, 2021
dd3942c
Merge pull request #2070 from estroz/feature/service-account
k8s-ci-robot Mar 9, 2021
4e6c400
Remove CLI interface and expose cli instead
Adirio Mar 10, 2021
2687774
Move the internal machinery utils to appropiate exported packages
Adirio Mar 9, 2021
8e0f0ab
Merge pull request #2074 from Adirio/export-machinery-utils
k8s-ci-robot Mar 10, 2021
f0ab179
Merge pull request #2072 from Adirio/fix-config-registry-api
k8s-ci-robot Mar 10, 2021
de84b80
Merge pull request #2079 from Adirio/cli-external-api
k8s-ci-robot Mar 10, 2021
0675cd5
Merge pull request #2030 from camilamacedo86/imp-release-docs
k8s-ci-robot Mar 10, 2021
fe73ff7
Add `kubebuilder alpha config-gen` subcommand
pwittrock Mar 7, 2021
9742a11
Merge pull request #1831 from pwittrock/main
k8s-ci-robot Mar 13, 2021
a2cc78c
Inject filesystem from cli instead of creating several per command
Adirio Mar 12, 2021
73cda2b
Merge pull request #2080 from Adirio/inject-filesystem
k8s-ci-robot Mar 13, 2021
61dcae6
Export scaffolding machinery
Adirio Mar 14, 2021
f7ad796
Store abstraction for persisting Config
Adirio Mar 14, 2021
23c49c2
Add fish completion
Adirio Mar 15, 2021
cd8812d
Merge pull request #2083 from Adirio/export-config-machinery
k8s-ci-robot Mar 15, 2021
bca394b
Provide third-party devs the option to provide their own alpha subcom…
Adirio Mar 15, 2021
e9caa6e
Merge pull request #2088 from Adirio/fish-code-completion
k8s-ci-robot Mar 15, 2021
fdb87df
Merge pull request #2089 from Adirio/extra-alpha-commands
k8s-ci-robot Mar 15, 2021
83230ae
Improve plugin phase 1.5 EP
Adirio Mar 9, 2021
6ca3450
Merge pull request #2082 from Adirio/export-scaffold-machinery
k8s-ci-robot Mar 15, 2021
fb4beed
Add coverage badge from Coveralls
Adirio Mar 15, 2021
388b36e
Remove kubebuilder hardcoded reference in alpha subcommand description
Adirio Mar 15, 2021
05be3c2
Fix alpha extra commands parent command
Adirio Mar 15, 2021
94b63e2
Merge pull request #2090 from Adirio/add-coverage-badge
k8s-ci-robot Mar 15, 2021
4b4d28a
Merge pull request #2091 from Adirio/alpha-description
k8s-ci-robot Mar 15, 2021
bebd89c
Merge pull request #2092 from Adirio/fix-alpha-subcommands
k8s-ci-robot Mar 15, 2021
9eb0747
Cleanup help messages
Adirio Mar 16, 2021
104672d
Merge pull request #2093 from Adirio/cleanup-help
k8s-ci-robot Mar 16, 2021
82c1b65
Fix coverage report on master
Adirio Mar 16, 2021
e806ba0
Merge pull request #2094 from Adirio/fix-ci
k8s-ci-robot Mar 16, 2021
e5b6435
Merge pull request #2066 from leovct/use-client-new-in-tests
k8s-ci-robot Mar 16, 2021
911f342
Merge pull request #2075 from Adirio/ep-plugin-phase-1.5
k8s-ci-robot Mar 16, 2021
668b999
Enable the storage of multiple plugins as layout
Adirio Mar 17, 2021
406d79d
Merge pull request #2096 from Adirio/config-chain
estroz Mar 17, 2021
faff148
Merge pull request #2065 from johanneswuerbach/improve-service-monitor
k8s-ci-robot Mar 17, 2021
f7b0ae3
pkg/cli/alpha/config-gen: command docs no longer depend on local envi…
estroz Mar 17, 2021
f2e1edb
Plugin phase 1.5 implementation
Adirio Mar 15, 2021
646f742
Merge pull request #2097 from estroz/docs/config-gen-static-cmd-docs
estroz Mar 18, 2021
2983c97
Merge pull request #2060 from Adirio/plugin-phase-1.5
k8s-ci-robot Mar 18, 2021
62e4812
Fix linting issues
Adirio Mar 22, 2021
b789900
Merge pull request #2102 from Adirio/fix-lint
k8s-ci-robot Mar 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move the internal machinery utils to appropiate exported packages
- Go version checks and go-modules-based repo discovery moved to pkg/plugins/golang
- Command execution and user prompt moved to pkg/plugin/util

Signed-off-by: Adrian Orive <[email protected]>
  • Loading branch information
Adirio committed Mar 10, 2021
commit 268777410de4456cc657cbef633609d062f77f4f
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package golang

import (
"fmt"
Expand All @@ -24,6 +24,96 @@ import (
"strings"
)

const (
goVerPattern = `^go(?P<major>[0-9]+)\.(?P<minor>[0-9]+)(?:\.(?P<patch>[0-9]+)|(?P<pre>(?:alpha|beta|rc)[0-9]+))?$`
)

var (
go113 = goVersion{
major: 1,
minor: 13,
}
go116alpha1 = goVersion{
major: 1,
minor: 16,
prerelease: "alpha1",
}

goVerRegexp = regexp.MustCompile(goVerPattern)
)

type goVersion struct {
major, minor, patch int
prerelease string
}

func (v *goVersion) parse(verStr string) error {
m := goVerRegexp.FindStringSubmatch(verStr)
if m == nil {
return fmt.Errorf("invalid version string")
}

var err error

v.major, err = strconv.Atoi(m[1])
if err != nil {
return fmt.Errorf("error parsing major version '%s': %s", m[1], err)
}

v.minor, err = strconv.Atoi(m[2])
if err != nil {
return fmt.Errorf("error parsing minor version '%s': %s", m[2], err)
}

if m[3] != "" {
v.patch, err = strconv.Atoi(m[3])
if err != nil {
return fmt.Errorf("error parsing patch version '%s': %s", m[2], err)
}
}

v.prerelease = m[4]

return nil
}

func (v goVersion) compare(other goVersion) int {
if v.major > other.major {
return 1
}
if v.major < other.major {
return -1
}

if v.minor > other.minor {
return 1
}
if v.minor < other.minor {
return -1
}

if v.patch > other.patch {
return 1
}
if v.patch < other.patch {
return -1
}

if v.prerelease == other.prerelease {
return 0
}
if v.prerelease == "" {
return 1
}
if other.prerelease == "" {
return -1
}
if v.prerelease > other.prerelease {
return 1
}
return -1
}

// ValidateGoVersion verifies that Go is installed and the current go version is supported by kubebuilder
func ValidateGoVersion() error {
err := fetchAndCheckGoVersion()
Expand Down Expand Up @@ -54,24 +144,13 @@ func fetchAndCheckGoVersion() error {
// checkGoVersion should only ever check if the Go version >= 1.13, since the kubebuilder binary only cares
// that the go binary supports go modules which were stabilized in that version (i.e. in go 1.13) by default
func checkGoVersion(verStr string) error {
goVerRegex := `^go?([0-9]+)\.([0-9]+)[\.0-9A-Za-z\-]*$`
m := regexp.MustCompile(goVerRegex).FindStringSubmatch(verStr)
if m == nil {
return fmt.Errorf("invalid version string")
}

major, err := strconv.Atoi(m[1])
if err != nil {
return fmt.Errorf("error parsing major version '%s': %s", m[1], err)
}

minor, err := strconv.Atoi(m[2])
if err != nil {
return fmt.Errorf("error parsing minor version '%s': %s", m[2], err)
var version goVersion
if err := version.parse(verStr); err != nil {
return err
}

if major < 1 || minor < 13 {
return fmt.Errorf("requires version >= 1.13")
if version.compare(go113) < 0 || version.compare(go116alpha1) >= 0 {
return fmt.Errorf("requires 1.13 <= version < 1.16")
}

return nil
Expand Down
189 changes: 189 additions & 0 deletions pkg/plugins/golang/go_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
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 golang

import (
"sort"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)

var _ = Describe("goVersion", func() {
Context("parse", func() {
var v goVersion

BeforeEach(func() {
v = goVersion{}
})

DescribeTable("should succeed for valid versions",
func(version string, expected goVersion) {
Expect(v.parse(version)).NotTo(HaveOccurred())
Expect(v.major).To(Equal(expected.major))
Expect(v.minor).To(Equal(expected.minor))
Expect(v.patch).To(Equal(expected.patch))
Expect(v.prerelease).To(Equal(expected.prerelease))
},
Entry("for minor release", "go1.15", goVersion{
major: 1,
minor: 15,
}),
Entry("for patch release", "go1.15.1", goVersion{
major: 1,
minor: 15,
patch: 1,
}),
Entry("for alpha release", "go1.15alpha1", goVersion{
major: 1,
minor: 15,
prerelease: "alpha1",
}),
Entry("for beta release", "go1.15beta1", goVersion{
major: 1,
minor: 15,
prerelease: "beta1",
}),
Entry("for release candidate", "go1.15rc1", goVersion{
major: 1,
minor: 15,
prerelease: "rc1",
}),
)

DescribeTable("should fail for invalid versions",
func(version string) { Expect(v.parse(version)).To(HaveOccurred()) },
Entry("for invalid prefix", "g1.15"),
Entry("for missing major version", "go.15"),
Entry("for missing minor version", "go1."),
Entry("for patch and prerelease version", "go1.15.1rc1"),
Entry("for invalid major version", "goa.15"),
Entry("for invalid minor version", "go1.a"),
Entry("for invalid patch version", "go1.15.a"),
)
})

Context("compare", func() {
// Test compare() by sorting a list.
var (
versions = []goVersion{
{major: 1, minor: 15, prerelease: "rc2"},
{major: 1, minor: 15, patch: 1},
{major: 1, minor: 16},
{major: 1, minor: 15, prerelease: "beta1"},
{major: 1, minor: 15, prerelease: "alpha2"},
{major: 2, minor: 0},
{major: 1, minor: 15, prerelease: "alpha1"},
{major: 1, minor: 13},
{major: 1, minor: 15, prerelease: "rc1"},
{major: 1, minor: 15},
{major: 1, minor: 15, patch: 2},
{major: 1, minor: 14},
{major: 1, minor: 15, prerelease: "beta2"},
{major: 0, minor: 123},
}

sortedVersions = []goVersion{
{major: 0, minor: 123},
{major: 1, minor: 13},
{major: 1, minor: 14},
{major: 1, minor: 15, prerelease: "alpha1"},
{major: 1, minor: 15, prerelease: "alpha2"},
{major: 1, minor: 15, prerelease: "beta1"},
{major: 1, minor: 15, prerelease: "beta2"},
{major: 1, minor: 15, prerelease: "rc1"},
{major: 1, minor: 15, prerelease: "rc2"},
{major: 1, minor: 15},
{major: 1, minor: 15, patch: 1},
{major: 1, minor: 15, patch: 2},
{major: 1, minor: 16},
{major: 2, minor: 0},
}
)

It("sorts a valid list of versions correctly", func() {
sort.Slice(versions, func(i int, j int) bool {
return versions[i].compare(versions[j]) == -1
})
Expect(versions).To(Equal(sortedVersions))
})
})
})

var _ = Describe("checkGoVersion", func() {
DescribeTable("should return true for supported go versions",
func(version string) { Expect(checkGoVersion(version)).NotTo(HaveOccurred()) },
Entry("for go 1.13", "go1.13"),
Entry("for go 1.13.1", "go1.13.1"),
Entry("for go 1.13.2", "go1.13.2"),
Entry("for go 1.13.3", "go1.13.3"),
Entry("for go 1.13.4", "go1.13.4"),
Entry("for go 1.13.5", "go1.13.5"),
Entry("for go 1.13.6", "go1.13.6"),
Entry("for go 1.13.7", "go1.13.7"),
Entry("for go 1.13.8", "go1.13.8"),
Entry("for go 1.13.9", "go1.13.9"),
Entry("for go 1.13.10", "go1.13.10"),
Entry("for go 1.13.11", "go1.13.11"),
Entry("for go 1.13.12", "go1.13.12"),
Entry("for go 1.13.13", "go1.13.13"),
Entry("for go 1.13.14", "go1.13.14"),
Entry("for go 1.13.15", "go1.13.15"),
Entry("for go 1.14beta1", "go1.14beta1"),
Entry("for go 1.14rc1", "go1.14rc1"),
Entry("for go 1.14", "go1.14"),
Entry("for go 1.14.1", "go1.14.1"),
Entry("for go 1.14.2", "go1.14.2"),
Entry("for go 1.14.3", "go1.14.3"),
Entry("for go 1.14.4", "go1.14.4"),
Entry("for go 1.14.5", "go1.14.5"),
Entry("for go 1.14.6", "go1.14.6"),
Entry("for go 1.14.7", "go1.14.7"),
Entry("for go 1.14.8", "go1.14.8"),
Entry("for go 1.14.9", "go1.14.9"),
Entry("for go 1.14.10", "go1.14.10"),
Entry("for go 1.14.11", "go1.14.11"),
Entry("for go 1.14.12", "go1.14.12"),
Entry("for go 1.14.13", "go1.14.13"),
Entry("for go 1.14.14", "go1.14.14"),
Entry("for go 1.14.15", "go1.14.15"),
Entry("for go 1.15beta1", "go1.15beta1"),
Entry("for go 1.15rc1", "go1.15rc1"),
Entry("for go 1.15rc2", "go1.15rc2"),
Entry("for go 1.15", "go1.15"),
Entry("for go 1.15.1", "go1.15.1"),
Entry("for go 1.15.2", "go1.15.2"),
Entry("for go 1.15.3", "go1.15.3"),
Entry("for go 1.15.4", "go1.15.4"),
Entry("for go 1.15.5", "go1.15.5"),
Entry("for go 1.15.6", "go1.15.6"),
Entry("for go 1.15.7", "go1.15.7"),
Entry("for go 1.15.8", "go1.15.8"),
)

DescribeTable("should return false for non-supported go versions",
func(version string) { Expect(checkGoVersion(version)).To(HaveOccurred()) },
Entry("for invalid go versions", "go"),
Entry("for go 1.13beta1", "go1.13beta1"),
Entry("for go 1.13rc1", "go1.13rc1"),
Entry("for go 1.13rc2", "go1.13rc2"),
Entry("for go 1.16beta1", "go1.16beta1"),
Entry("for go 1.16rc1", "go1.16rc1"),
Entry("for go 1.16", "go1.16"),
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package golang

import (
"encoding/json"
Expand All @@ -34,12 +34,9 @@ type module struct {
}

// findGoModulePath finds the path of the current module, if present.
func findGoModulePath(forceModules bool) (string, error) {
func findGoModulePath() (string, error) {
cmd := exec.Command("go", "mod", "edit", "-json")
cmd.Env = append(cmd.Env, os.Environ()...)
if forceModules {
cmd.Env = append(cmd.Env, "GO111MODULE=on" /* turn on modules just for these commands */)
}
out, err := cmd.Output()
if err != nil {
if exitErr, isExitErr := err.(*exec.ExitError); isExitErr {
Expand All @@ -58,7 +55,7 @@ func findGoModulePath(forceModules bool) (string, error) {
// though a combination of go/packages and `go mod` commands/tricks.
func FindCurrentRepo() (string, error) {
// easiest case: existing go module
path, err := findGoModulePath(false)
path, err := findGoModulePath()
if err == nil {
return path, nil
}
Expand All @@ -79,7 +76,6 @@ func FindCurrentRepo() (string, error) {
// otherwise, try to get `go mod init` to guess for us -- it's pretty good
cmd := exec.Command("go", "mod", "init")
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, "GO111MODULE=on" /* turn on modules just for these commands */)
if _, err := cmd.Output(); err != nil {
if exitErr, isExitErr := err.(*exec.ExitError); isExitErr {
err = fmt.Errorf("%s", string(exitErr.Stderr))
Expand All @@ -90,5 +86,5 @@ func FindCurrentRepo() (string, error) {
}
//nolint:errcheck
defer os.Remove("go.mod") // clean up after ourselves
return findGoModulePath(true)
return findGoModulePath()
}
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/model"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2/scaffolds"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/internal/cmdutil"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/internal/util"
"sigs.k8s.io/kubebuilder/v3/plugins/addon"
)

Expand Down
Loading