Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.
Merged
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
**

# Exclude folders relevant for build
!.git
!.dockerignore
!api/
!charts/
!cmd/
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ FROM eu.gcr.io/gardener-project/3rd/golang:1.15.5 AS builder

WORKDIR /go/src/github.com/gardener/gardener-resource-manager
COPY . .
RUN make install

ARG EFFECTIVE_VERSION
RUN make install EFFECTIVE_VERSION=$EFFECTIVE_VERSION

############# gardener-resource-manager
FROM eu.gcr.io/gardener-project/3rd/alpine:3.12.1 AS gardener-resource-manager
Expand Down
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

NAME := gardener-resource-manager
IMAGE_REPOSITORY := eu.gcr.io/gardener-project/gardener/$(NAME)
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
VERSION := $(shell cat "$(REPO_ROOT)/VERSION")
LD_FLAGS := "-w -X github.com/gardener/$(NAME)/pkg/version.Version=$(VERSION)"
VERIFY := true
NAME := gardener-resource-manager
IMAGE_REPOSITORY := eu.gcr.io/gardener-project/gardener/$(NAME)
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
VERSION := $(shell cat "$(REPO_ROOT)/VERSION")
EFFECTIVE_VERSION := $(VERSION)-$(shell git rev-parse HEAD)

ifneq ($(strip $(shell git status --porcelain 2>/dev/null)),)
EFFECTIVE_VERSION := $(EFFECTIVE_VERSION)-dirty
endif
LD_FLAGS := "-w $(shell EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) $(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/get-build-ld-flags.sh github.com/gardener/$(NAME) $(REPO_ROOT)/VERSION)"

#########################################
# Rules for local development scenarios #
Expand All @@ -41,22 +45,21 @@ start:

.PHONY: install
install:
@LD_FLAGS=$(LD_FLAGS) $(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/install.sh ./...
@LD_FLAGS=$(LD_FLAGS) $(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/install.sh ./cmd/...

.PHONY: docker-login
docker-login:
@gcloud auth activate-service-account --key-file .kube-secrets/gcr/gcr-readwrite.json

.PHONY: docker-image
docker-image:
@docker build --build-arg VERIFY=$(VERIFY) -t $(IMAGE_REPOSITORY):$(VERSION) -f Dockerfile --target gardener-resource-manager .
# building docker image with tag $(IMAGE_REPOSITORY):$(EFFECTIVE_VERSION)
@docker build --build-arg EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) -t $(IMAGE_REPOSITORY):$(EFFECTIVE_VERSION) --rm --target gardener-resource-manager .

.PHONY: all
ifeq ($(VERIFY),true)
all: verify generate install
else
all: generate install
endif
.PHONY: docker-push
docker-push:
@if ! docker images $(IMAGE_REPOSITORY) | awk '{ print $$2 }' | grep -q -F $(EFFECTIVE_VERSION); then echo "$(IMAGE_REPOSITORY) version $(EFFECTIVE_VERSION) is not yet built. Please run 'make docker-image'"; false; fi
@gcloud docker -- push $(IMAGE_REPOSITORY):$(EFFECTIVE_VERSION)

#####################################################################
# Rules for verification, formatting, linting, testing and cleaning #
Expand Down
6 changes: 4 additions & 2 deletions cmd/gardener-resource-manager/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
secretcontroller "github.com/gardener/gardener-resource-manager/pkg/controller/secret"
"github.com/gardener/gardener-resource-manager/pkg/healthz"
logpkg "github.com/gardener/gardener-resource-manager/pkg/log"
"github.com/gardener/gardener-resource-manager/pkg/version"
)

var log = runtimelog.Log.WithName("gardener-resource-manager")
Expand All @@ -48,13 +49,14 @@ func NewResourceManagerCommand() *cobra.Command {
healthControllerOpts := &healthcontroller.ControllerOptions{}

cmd := &cobra.Command{
Use: "gardener-resource-manager",
Use: "gardener-resource-manager",
Version: version.Get().GitVersion,

RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()

entryLog.Info("Starting gardener-resource-manager...")
entryLog.Info("Starting gardener-resource-manager...", "version", version.Get().GitVersion)
cmd.Flags().VisitAll(func(flag *pflag.Flag) {
entryLog.Info(fmt.Sprintf("FLAG: --%s=%s", flag.Name, flag.Value))
})
Expand Down
51 changes: 49 additions & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,52 @@

package version

// Version is a string that is overwritten during build time using ld flags.
var Version = "binary not built correctly"
import (
"fmt"
"runtime"
"strings"

apimachineryversion "k8s.io/apimachinery/pkg/version"
)

var (
gitVersion = "v0.0.0-dev"
gitCommit string
gitTreeState string
buildDate = "1970-01-01T00:00:00Z"

version *apimachineryversion.Info
)

// Get returns the overall codebase version. It's for detecting
// what code a binary was built from.
// These variables typically come from -ldflags settings and in
// their absence fallback to the settings in pkg/version/version.go
func Get() apimachineryversion.Info {
return *version
}

func init() {
var (
versionParts = strings.Split(gitVersion, ".")
gitMajor string
gitMinor string
)

if len(versionParts) >= 2 {
gitMajor = strings.TrimPrefix(versionParts[0], "v")
gitMinor = versionParts[1]
}

version = &apimachineryversion.Info{
Major: gitMajor,
Minor: gitMinor,
GitVersion: gitVersion,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}