Skip to content

Commit

Permalink
Make kubebuilder go install-able
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Elias dos Santos <[email protected]>
  • Loading branch information
migueleliasweb committed Jan 17, 2025
1 parent 8c048ff commit 974dad0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ 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 cmd.kubeBuilderVersion=$(shell git describe --tags --dirty --broken) \
-X cmd.goos=$(shell go env GOOS) \
-X cmd.goarch=$(shell go env GOARCH) \
-X cmd.gitCommit=$(shell git rev-parse HEAD) \
-X cmd.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
"
.PHONY: build
build: ## Build the project locally
go build $(LD_FLAGS) -o bin/kubebuilder ./cmd
go build $(LD_FLAGS) -o bin/kubebuilder

.PHONY: install
install: build ## Build and install the binary with the current source code. Use it to test your changes locally.
Expand Down
13 changes: 6 additions & 7 deletions build/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ before:
# Build a binary for each target in targets.
builds:
- id: kubebuilder
main: ./cmd
binary: kubebuilder
mod_timestamp: "{{ .CommitTimestamp }}"
ldflags:
- -X main.kubeBuilderVersion={{ .Version }}
- -X main.goos={{ .Os }}
- -X main.goarch={{ .Arch }}
- -X main.gitCommit={{ .Commit }}
- -X main.buildDate={{ .Date }}
- -X main.kubernetesVendorVersion={{ .Env.KUBERNETES_VERSION }}
- -X cmd.kubeBuilderVersion={{ .Version }}
- -X cmd.goos={{ .Os }}
- -X cmd.goarch={{ .Arch }}
- -X cmd.gitCommit={{ .Commit }}
- -X cmd.buildDate={{ .Date }}
- -X cmd.kubernetesVendorVersion={{ .Env.KUBERNETES_VERSION }}
targets:
- linux_amd64
- linux_arm64
Expand Down
4 changes: 2 additions & 2 deletions cmd/main.go → cmd/cmd.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 cmd

import (
"github.com/sirupsen/logrus"
Expand All @@ -36,7 +36,7 @@ func init() {
logrus.SetFormatter(&logrus.TextFormatter{DisableTimestamp: true})
}

func main() {
func Run() {
// Bundle plugin which built the golang projects scaffold with base.go/v4 and kustomize/v2 plugins
gov4Bundle, _ := plugin.NewBundleWithOptions(plugin.WithName(golang.DefaultNameQualifier),
plugin.WithVersion(plugin.Version{Number: 4}),
Expand Down
2 changes: 1 addition & 1 deletion cmd/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 cmd

import (
"fmt"
Expand Down
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2020 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 main

import "sigs.k8s.io/kubebuilder/v4/cmd"

func main() {
cmd.Run()
}

0 comments on commit 974dad0

Please sign in to comment.