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
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ COPY cmd/ cmd/
COPY scaleway/ scaleway/

ARG TAG
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -ldflags "-w -s -X github.com/scaleway/scaleway-cloud-controller-manager/scaleway.version=${TAG}" -o scaleway-cloud-controller-manager ./cmd/scaleway-cloud-controller-manager
ARG COMMIT_SHA
ARG BUILD_DATE
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -ldflags "-w -s -X github.com/scaleway/scaleway-cloud-controller-manager/scaleway.version=${TAG} -X github.com/scaleway/scaleway-cloud-controller-manager/scaleway.buildDate=${BUILD_DATE} github.com/scaleway/scaleway-cloud-controller-manager/scaleway.gitCommit=${COMMIT_SHA} " -o scaleway-cloud-controller-manager ./cmd/scaleway-cloud-controller-manager

FROM scratch
WORKDIR /
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)
ALL_PLATFORM = linux/amd64,linux/arm/v7,linux/arm64

BUILD_DATE ?= $(shell date -Is)

GOPATH ?= $(GOPATH)

REGISTRY ?= scaleway
Expand All @@ -10,6 +12,7 @@ FULL_IMAGE ?= $(REGISTRY)/$(IMAGE)

TAG ?= $(shell git rev-parse HEAD)
IMAGE_TAG ?= $(shell git rev-parse HEAD)
COMMIT_SHA ?= $(shell git rev-parse HEAD)

DOCKER_CLI_EXPERIMENTAL ?= enabled

Expand All @@ -35,12 +38,12 @@ compile:
.PHONY: docker-build
docker-build:
@echo "Building scaleway-cloud-controller-manager for ${ARCH}"
docker build . --platform=linux/$(ARCH) --build-arg ARCH=$(ARCH) --build-arg TAG=$(TAG) -f Dockerfile -t ${FULL_IMAGE}:${IMAGE_TAG}-$(ARCH)
docker build . --platform=linux/$(ARCH) --build-arg ARCH=$(ARCH) --build-arg TAG=$(TAG) --build-arg COMMIT_SHA=$(COMMIT_SHA) --build-arg BUILD_DATE=$(BUILD_DATE) -f Dockerfile -t ${FULL_IMAGE}:${IMAGE_TAG}-$(ARCH)

.PHONY: docker-buildx-all
docker-buildx-all:
@echo "Making release for tag $(IMAGE_TAG)"
docker buildx build --build-arg TAG=$(TAG) --platform=$(ALL_PLATFORM) --push -t $(FULL_IMAGE):$(IMAGE_TAG) .
docker buildx build --build-arg TAG=$(TAG) --build-arg COMMIT_SHA=$(COMMIT_SHA) --build-arg BUILD_DATE=$(BUILD_DATE) --platform=$(ALL_PLATFORM) --push -t $(FULL_IMAGE):$(IMAGE_TAG) .

## Release
.PHONY: release
Expand Down
18 changes: 9 additions & 9 deletions scaleway/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package scaleway

import (
"errors"
"fmt"
"io"
"os"
"time"
Expand All @@ -35,15 +36,12 @@ const (
cacheUpdateFrequency = time.Minute * 10

// optional fields
scwCcmUserAgent = "SCW_CCM_USER_AGENT"
scwCcmPrefixEnv = "SCW_CCM_PREFIX"
scwCcmTagsEnv = "SCW_CCM_TAGS"
scwCcmTagsDelimiterEnv = "SCW_CCM_TAGS_DELIMITER"
)

var (
version = "0.0.0-dirty"
userAgent = "scaleway/ccm (" + version + ")"
// extraUserAgentEnv is the environment variable that adds some string at the end of the user agent
extraUserAgentEnv = "EXTRA_USER_AGENT"
)

type cloud struct {
Expand All @@ -57,13 +55,19 @@ type cloud struct {
func newCloud(config io.Reader) (cloudprovider.Interface, error) {
logger.SetLogger(logging)

userAgent := fmt.Sprintf("scaleway/ccm %s (%s)", ccmVersion, gitCommit)
if extraUA := os.Getenv(extraUserAgentEnv); extraUA != "" {
userAgent = userAgent + " " + extraUA
}

// Create a Scaleway client
// use theses env variable to set or overwrite profile values
// SCW_ACCESS_KEY
// SCW_SECRET_KEY
// SCW_DEFAULT_ORGANIZATION_ID
// SCW_DEFAULT_REGION
// SCW_DEFAULT_ZONE

scwClient, err := scw.NewClient(
scw.WithUserAgent(userAgent),
scw.WithEnv(),
Expand All @@ -88,10 +92,6 @@ func newCloud(config io.Reader) (cloudprovider.Interface, error) {
}

func init() {
if ua, ok := os.LookupEnv(scwCcmUserAgent); ok {
userAgent = ua
}

cloudprovider.RegisterCloudProvider(providerName, func(config io.Reader) (cloudprovider.Interface, error) {
return newCloud(config)
})
Expand Down
8 changes: 8 additions & 0 deletions scaleway/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scaleway

// These are set during build time via -ldflags
var (
ccmVersion string
gitCommit string
buildDate string
)