Skip to content

Commit

Permalink
Add "--version" flag
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTheEvilOne committed Mar 31, 2022
1 parent 31bf9d6 commit 5efcb76
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 11 deletions.
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ KUBECONFIG := dev/kubeconfig.yaml
MANAGER_CONFIG_FILE := example/00-componentconfig.yaml
PROJECT_NAME := 23technologies
VERSION := $(shell cat "${REPO_ROOT}/VERSION")
LD_FLAGS := "-w -X github.com/${PROJECT_NAME}/${EXTENSION_PREFIX}-${NAME}/pkg/version.Version=${VERSION}"
LD_FLAGS := "-w $(shell $(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/get-build-ld-flags.sh k8s.io/component-base $(REPO_ROOT)/VERSION $(EXTENSION_PREFIX)-$(NAME))"
LEADER_ELECTION := false
IGNORE_OPERATION_ANNOTATION := true
GARDENER_VERSION := $(grep "gardener/gardener v" go.mod | tr "[:blank:]" "\\n" | tail -1)
Expand Down Expand Up @@ -150,11 +150,3 @@ install-requirements:

.PHONY: verify-extended
verify-extended: install-requirements check-generate check format test-clean

#########################################
# Rules for infra-cli
#########################################

.PHONY: install-infra-cli
install-infra-cli:
@go install -mod=vendor ./cmd/infra-cli
9 changes: 8 additions & 1 deletion pkg/cmd/admission/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
gardenerhealthz "github.com/gardener/gardener/pkg/healthz"
"github.com/spf13/cobra"
"k8s.io/component-base/config"
"k8s.io/component-base/version/verflag"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -59,6 +60,10 @@ func NewAdmissionCommand(ctx context.Context) *cobra.Command {
cmdDefinition := &cobra.Command{
Use: fmt.Sprintf("admission-%s", ionos.Type),

PreRun: func(cmdDefinition *cobra.Command, args []string) {
verflag.PrintAndExitIfRequested()
},

RunE: func(cmdDefinition *cobra.Command, args []string) error {
if err := aggOption.Complete(); err != nil {
return fmt.Errorf("Error completing options: %w", err)
Expand Down Expand Up @@ -102,7 +107,9 @@ func NewAdmissionCommand(ctx context.Context) *cobra.Command {
},
}

aggOption.AddFlags(cmdDefinition.Flags())
cmdFlags := cmdDefinition.Flags()
aggOption.AddFlags(cmdFlags)
verflag.AddFlags(cmdFlags)

return cmdDefinition
}
9 changes: 8 additions & 1 deletion pkg/cmd/controller/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
autoscalingv1beta2 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2"
"k8s.io/component-base/version/verflag"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
Expand Down Expand Up @@ -111,6 +112,10 @@ func NewControllerManagerCommand(ctx context.Context) *cobra.Command {
cmdDefinition := &cobra.Command{
Use: fmt.Sprintf("%s-controller-manager", ionos.Name),

PreRun: func(cmdDefinition *cobra.Command, args []string) {
verflag.PrintAndExitIfRequested()
},

RunE: func(cmdDefinition *cobra.Command, args []string) error {
if err := aggOption.Complete(); err != nil {
return fmt.Errorf("Error completing options: %w", err)
Expand Down Expand Up @@ -208,7 +213,9 @@ func NewControllerManagerCommand(ctx context.Context) *cobra.Command {
},
}

aggOption.AddFlags(cmdDefinition.Flags())
cmdFlags := cmdDefinition.Flags()
aggOption.AddFlags(cmdFlags)
verflag.AddFlags(cmdFlags)

return cmdDefinition
}
111 changes: 111 additions & 0 deletions vendor/k8s.io/component-base/version/verflag/verflag.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ k8s.io/code-generator/third_party/forked/golang/reflect
k8s.io/component-base/config
k8s.io/component-base/config/v1alpha1
k8s.io/component-base/version
k8s.io/component-base/version/verflag
# k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c
## explicit; go 1.13
k8s.io/gengo/args
Expand Down

0 comments on commit 5efcb76

Please sign in to comment.