Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#179 from spangenberg/version-support
Browse files Browse the repository at this point in the history
Version support
  • Loading branch information
openshift-merge-robot authored Apr 19, 2019
2 parents 53ba43b + b24f19d commit 91747f6
Show file tree
Hide file tree
Showing 18 changed files with 1,311 additions and 11 deletions.
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.10 AS builder
WORKDIR /go/src/sigs.k8s.io/cluster-api-provider-aws
COPY . .
RUN go build -o ./machine-controller-manager ./cmd/manager
RUN go build -o ./manager ./vendor/github.com/openshift/cluster-api/cmd/manager
# VERSION env gets set in the openshift/release image and refers to the golang version, which interfers with our own
RUN unset VERSION \
&& NO_DOCKER=1 make build

FROM registry.svc.ci.openshift.org/openshift/origin-v4.0:base
RUN INSTALL_PKGS=" \
Expand All @@ -11,5 +12,5 @@ RUN INSTALL_PKGS=" \
yum install -y $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum clean all
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/manager /
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/machine-controller-manager /
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/bin/manager /
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/bin/machine-controller-manager /
9 changes: 5 additions & 4 deletions Dockerfile.rhel7
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM registry.svc.ci.openshift.org/ocp/builder:golang-1.10 AS builder
WORKDIR /go/src/sigs.k8s.io/cluster-api-provider-aws
COPY . .
RUN go build -o ./machine-controller-manager ./cmd/manager
RUN go build -o ./manager ./vendor/github.com/openshift/cluster-api/cmd/manager
# VERSION env gets set in the openshift/release image and refers to the golang version, which interfers with our own
RUN unset VERSION \
&& NO_DOCKER=1 make build

FROM registry.svc.ci.openshift.org/ocp/4.0:base
RUN INSTALL_PKGS=" \
Expand All @@ -11,5 +12,5 @@ RUN INSTALL_PKGS=" \
yum install -y $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum clean all
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/manager /
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/machine-controller-manager /
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/bin/manager /
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-aws/bin/machine-controller-manager /
9 changes: 9 additions & 0 deletions Gopkg.lock

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

8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ GOGCFLAGS ?= -gcflags=all="-N -l"
endif

VERSION ?= $(shell git describe --always --abbrev=7)
REPO_PATH ?= sigs.k8s.io/cluster-api-provider-aws
LD_FLAGS ?= -X $(REPO_PATH)/pkg/version.Raw=$(VERSION) -extldflags "-static"
MUTABLE_TAG ?= latest
IMAGE = origin-aws-machine-controllers

Expand Down Expand Up @@ -58,8 +60,10 @@ bin:

.PHONY: build
build: ## build binaries
$(DOCKER_CMD) go build $(GOGCFLAGS) -o bin/machine-controller-manager -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/manager
$(DOCKER_CMD) go build $(GOGCFLAGS) -o bin/manager -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/vendor/github.com/openshift/cluster-api/cmd/manager
$(DOCKER_CMD) go build $(GOGCFLAGS) -o "bin/machine-controller-manager" \
-ldflags "$(LD_FLAGS)" "$(REPO_PATH)/cmd/manager"
$(DOCKER_CMD) go build $(GOGCFLAGS) -o bin/manager -ldflags '-extldflags "-static"' \
"$(REPO_PATH)/vendor/github.com/openshift/cluster-api/cmd/manager"

aws-actuator:
$(DOCKER_CMD) go build $(GOGCFLAGS) -o bin/aws-actuator sigs.k8s.io/cluster-api-provider-aws/cmd/aws-actuator
Expand Down
11 changes: 11 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main
import (
"flag"
"fmt"
"os"
"time"

"github.com/golang/glog"
Expand All @@ -26,15 +27,25 @@ import (
machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/actuators/machine"
"sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client"
"sigs.k8s.io/cluster-api-provider-aws/pkg/version"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

func main() {
var printVersion bool
flag.BoolVar(&printVersion, "version", false, "print version and exit")

klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
flag.Parse()

if printVersion {
fmt.Println(version.String)
os.Exit(0)
}

flag.VisitAll(func(f1 *flag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/cluster-api-provider-aws/pkg/version"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -193,5 +194,5 @@ func NewClientFromKeys(accessKey, secretAccessKey, region string) (Client, error
// version information to requests made by the AWS SDK.
var addProviderVersionToUserAgent = request.NamedHandler{
Name: "openshift.io/cluster-api-provider-aws",
Fn: request.MakeAddToUserAgentHandler("openshift.io cluster-api-provider-aws", "dummy"),
Fn: request.MakeAddToUserAgentHandler("openshift.io cluster-api-provider-aws", version.Version.String()),
}
20 changes: 20 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package version

import (
"fmt"
"strings"

"github.com/blang/semver"
)

var (
// Raw is the string representation of the version. This will be replaced
// with the calculated version at build time.
Raw = "v0.0.0-was-not-built-properly"

// Version is semver representation of the version.
Version = semver.MustParse(strings.TrimLeft(Raw, "v"))

// String is the human-friendly representation of the version.
String = fmt.Sprintf("ClusterAPIProviderAWS %s", Raw)
)
1 change: 1 addition & 0 deletions vendor/github.com/blang/semver/.gx/lastpubver

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

21 changes: 21 additions & 0 deletions vendor/github.com/blang/semver/.travis.yml

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

22 changes: 22 additions & 0 deletions vendor/github.com/blang/semver/LICENSE

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

194 changes: 194 additions & 0 deletions vendor/github.com/blang/semver/README.md

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

Loading

0 comments on commit 91747f6

Please sign in to comment.