Skip to content
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
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ IMAGE_TAGS ?= $(or $(IMG_TAG_FROM_REF),$(DEFAULT_IMAGE_TAGS))
IMG ?= $(KO_DOCKER_REPO):$(IMAGE_TAGS)
RELEASE_DIR ?= release
PLATFORM ?= linux/amd64
VERSION ?= $(shell git describe --always --tag --dirty=-dev)
LDFLAGS := -X=github.com/linode/linode-cloud-controller-manager/version.version=$(VERSION)

#####################################################################
# Dev Setup
Expand Down Expand Up @@ -100,13 +102,13 @@ build-linux: codegen
echo "cross compiling linode-cloud-controller-manager for linux/amd64" && \
GOOS=linux GOARCH=amd64 \
CGO_ENABLED=0 \
go build -o dist/linode-cloud-controller-manager-linux-amd64 .
go build -ldflags="$(LDFLAGS)" -o dist/linode-cloud-controller-manager-linux-amd64 .

.PHONY: build
build: codegen
echo "compiling linode-cloud-controller-manager" && \
CGO_ENABLED=0 \
go build -o dist/linode-cloud-controller-manager .
go build -ldflags="$(LDFLAGS)" -o dist/linode-cloud-controller-manager .

.PHONY: release
release:
Expand All @@ -123,12 +125,12 @@ imgname:
.PHONY: ko-build
# build the container image locally without pushing it to a registry
ko-build:
CGO_ENABLED=0 ko build --local --bare --tags "$(IMAGE_TAGS)" --platform=$(PLATFORM) .
CGO_ENABLED=0 GOFLAGS="-ldflags=$(LDFLAGS)" ko build --local --bare --tags "$(IMAGE_TAGS)" --platform=$(PLATFORM) .

.PHONY: ko-publish
# build the container image and publish it to the registry named by IMG
ko-publish:
CGO_ENABLED=0 KO_DOCKER_REPO="$(KO_DOCKER_REPO)" ko build --bare --tags "$(IMAGE_TAGS)" --platform=$(PLATFORM) .
CGO_ENABLED=0 KO_DOCKER_REPO="$(KO_DOCKER_REPO)" GOFLAGS="-ldflags=$(LDFLAGS)" ko build --bare --tags "$(IMAGE_TAGS)" --platform=$(PLATFORM) .

.PHONY: run
# run the ccm locally, really only makes sense on linux anyway
Expand Down
5 changes: 3 additions & 2 deletions cloud/linode/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/linode/linodego/v2"
"k8s.io/klog/v2"

"github.com/linode/linode-cloud-controller-manager/version"

_ "github.com/hexdigest/gowrap"
)

Expand Down Expand Up @@ -98,7 +100,6 @@ func (t *tokenTransport) RoundTrip(req *http.Request) (*http.Response, error) {
// New creates a new linode client with a given token and default timeout.
func New(timeout time.Duration, tokenProvider TokenProvider) (*linodego.Client, error) {
var client *linodego.Client
userAgent := fmt.Sprintf("linode-cloud-controller-manager %s", linodego.DefaultUserAgent)
apiURL := os.Getenv("LINODE_URL")
if apiURL == "" {
apiURL = DefaultLinodeAPIURL
Expand All @@ -117,7 +118,7 @@ func New(timeout time.Duration, tokenProvider TokenProvider) (*linodego.Client,
if err != nil {
return nil, err
}
client.SetUserAgent(userAgent)
client.SetUserAgent(fmt.Sprintf("linode-CCM/%s", version.GetVersion()))

klog.V(3).Infof("Linode client created with default timeout of %v", timeout)
return client, nil
Expand Down
12 changes: 12 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package version

// version is overridden by build time flags
var version string

func GetVersion() string {
if version == "" {
return "dev"
}

return version
}
11 changes: 11 additions & 0 deletions version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package version

import "testing"

func TestVersion(t *testing.T) {
t.Parallel()
vers := GetVersion()
if vers != "dev" {
t.Errorf("unset version should be dev, got %s", vers)
}
}
Loading