Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Add to the PROJECT file the CLI tag version used to do the scaffold #3387

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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') \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please revert this changes that has no relation with the scope of this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I use this changes to finish this PR... because I move the 'version.go' to other places.
If I don't move, I can't import that value from 'main' package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hun, it does not seem to make sense. This target is used to build the binary, and making changes here does not allow you to import or not a code to be used. We should not perform those changes to address this one.

"
.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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we want to track this one we will need to have the CLI version used per plugin and scaffold.
See that we can init a project within the version X and then afterwords scaffold an API with N+2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it.
So it would be applied to go/v2 and go/v3 also?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should ONLY be applied to the Project Config v3.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not change the config/v2 it is deprecated and the changes should be addressed into the config/v3

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