Skip to content

Commit

Permalink
feat: add CLI tag
Browse files Browse the repository at this point in the history
feat: sepearate version apart

fix: add version in Makefile

fix: add testdata made by generate

fix: small lint

fix: lint

fix: lint issue
  • Loading branch information
yyy1000 committed May 4, 2023
1 parent 9af6ca4 commit 492acb4
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ help: ## Display this help
##@ Build

LD_FLAGS=-ldflags " \
-X main.kubeBuilderVersion=$(shell git describe --tags --dirty --broken) \
-X main.goos=$(shell go env GOOS) \
-X main.goarch=$(shell go env GOARCH) \
-X main.gitCommit=$(shell git rev-parse HEAD) \
-X main.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
-X sigs.k8s.io/kubebuilder/v3/pkg/version.kubeBuilderVersion=$(shell git describe --tags --dirty --broken) \
-X sigs.k8s.io/kubebuilder/v3/pkg/version.goos=$(shell go env GOOS) \
-X sigs.k8s.io/kubebuilder/v3/pkg/version.goarch=$(shell go env GOARCH) \
-X sigs.k8s.io/kubebuilder/v3/pkg/version.gitCommit=$(shell git rev-parse HEAD) \
-X sigs.k8s.io/kubebuilder/v3/pkg/version.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
"
.PHONY: build
build: ## Build the project locally
Expand Down
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
golangv3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3"
golangv4 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4"
grafanav1alpha1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha"
"sigs.k8s.io/kubebuilder/v3/pkg/version"
)

func main() {
Expand Down Expand Up @@ -68,7 +69,7 @@ func main() {

c, err := cli.New(
cli.WithCommandName("kubebuilder"),
cli.WithVersion(versionString()),
cli.WithVersion(version.VersionString()),
cli.WithPlugins(
golangv2.Plugin{},
golangv3.Plugin{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# More info: https://book.kubebuilder.io/reference/project-config.html
componentConfig: true
domain: tutorial.kubebuilder.io
kubebuilderVersion: unknown
layout:
- go.kubebuilder.io/v4
projectName: project
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ type Config interface {
// This method was introduced in project version 3.
SetProjectName(name string) error

// GetCLIVersion returns the Kubebuilder version.
// This method was introduced in project version 3.
GetCLIVersion() string
// SetCLIVersion sets the Kubebuilder version.
// This method was introduced in project version 3.
SetCLIVersion(CLIVersion string) error

// GetPluginChain returns the plugin chain.
// This method was introduced in project version 3.
GetPluginChain() []string
Expand Down
13 changes: 13 additions & 0 deletions pkg/config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ func (c *cfg) SetProjectName(string) error {
}
}

// GetCLIVersion implements config.Config
func (c cfg) GetCLIVersion() string {
return ""
}

// SetCLIVersion implements config.Config
func (c *cfg) SetCLIVersion(string) error {
return config.UnsupportedFieldError{
Version: Version,
Field: "kubebuilder version",
}
}

// GetPluginChain implements config.Config
func (c cfg) GetPluginChain() []string {
return []string{"go.kubebuilder.io/v2"}
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/v3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type cfg struct {
Repository string `json:"repo,omitempty"`
Name string `json:"projectName,omitempty"`
PluginChain stringSlice `json:"layout,omitempty"`
CLIVersion string `json:"kubebuilderVersion,omitempty"`

// Boolean fields
MultiGroup bool `json:"multigroup,omitempty"`
Expand Down Expand Up @@ -126,6 +127,17 @@ func (c *cfg) SetProjectName(name string) error {
return nil
}

// GetCLIVersion implements config.Config
func (c cfg) GetCLIVersion() string {
return c.CLIVersion
}

// SetCLIVersion implements config.Config
func (c *cfg) SetCLIVersion(CLIVersion string) error {
c.CLIVersion = CLIVersion
return nil
}

// GetLayout implements config.Config
func (c cfg) GetPluginChain() []string {
return c.PluginChain
Expand Down
7 changes: 5 additions & 2 deletions pkg/plugins/golang/v4/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
"unicode"

"github.com/spf13/pflag"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4/scaffolds"
"sigs.k8s.io/kubebuilder/v3/pkg/version"
)

// Variables and function to check Go version requirements.
Expand Down Expand Up @@ -104,7 +104,10 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {
}
p.repo = repoPath
}

err := p.config.SetCLIVersion(version.KubebuilderVersion())
if err != nil {
return fmt.Errorf("error set CLI version: %v", err)
}
return p.config.SetRepository(p.repo)
}

Expand Down
9 changes: 7 additions & 2 deletions cmd/version.go → pkg/version/version.go
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 main
package version

import (
"fmt"
Expand Down Expand Up @@ -43,7 +43,7 @@ type version struct {
}

// versionString returns the CLI version
func versionString() string {
func VersionString() string {
return fmt.Sprintf("Version: %#v", version{
kubeBuilderVersion,
kubernetesVendorVersion,
Expand All @@ -53,3 +53,8 @@ func versionString() string {
goarch,
})
}

// KubebuilderVersion returns the Kubebuilder version
func KubebuilderVersion() string {
return kubeBuilderVersion
}
1 change: 1 addition & 0 deletions testdata/project-v4-config/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# More info: https://book.kubebuilder.io/reference/project-config.html
componentConfig: true
domain: testproject.org
kubebuilderVersion: unknown
layout:
- go.kubebuilder.io/v4
projectName: project-v4-config
Expand Down
1 change: 1 addition & 0 deletions testdata/project-v4-declarative-v1/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: testproject.org
kubebuilderVersion: unknown
layout:
- go.kubebuilder.io/v4
- declarative.go.kubebuilder.io/v1
Expand Down
1 change: 1 addition & 0 deletions testdata/project-v4-multigroup/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: testproject.org
kubebuilderVersion: unknown
layout:
- go.kubebuilder.io/v4
multigroup: true
Expand Down
1 change: 1 addition & 0 deletions testdata/project-v4-with-deploy-image/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: testproject.org
kubebuilderVersion: unknown
layout:
- go.kubebuilder.io/v4
plugins:
Expand Down
1 change: 1 addition & 0 deletions testdata/project-v4-with-grafana/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: testproject.org
kubebuilderVersion: unknown
layout:
- go.kubebuilder.io/v4
plugins:
Expand Down
1 change: 1 addition & 0 deletions testdata/project-v4/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: testproject.org
kubebuilderVersion: unknown
layout:
- go.kubebuilder.io/v4
projectName: project-v4
Expand Down

0 comments on commit 492acb4

Please sign in to comment.