Skip to content

Commit 8bc87f7

Browse files
Merge pull request #393 from hanleyyin/dynamicUserAgent
Set the user-agent based on the destination repo of the built image
2 parents 4478e5e + 3f763b4 commit 8bc87f7

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

.github/workflows/on-release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
env:
99
PUBLIC_REGISTRY: public.ecr.aws/k1n1h4h4
1010
PRIVATE_REGISTRY: 105154636954.dkr.ecr.us-east-1.amazonaws.com
11+
ECR_USER_AGENT: aws-privateca-issuer
12+
EKS_USER_AGENT: aws-privateca-connector-for-kubernetes-eks-addon
1113

1214
jobs:
1315
build:
@@ -44,6 +46,7 @@ jobs:
4446
with:
4547
build-args: |
4648
pkg_version=${{ steps.tag.outputs.tag }}
49+
user_agent=${{ env.ECR_USER_AGENT }}
4750
context: .
4851
platforms: linux/amd64,linux/arm64
4952
tags: |
@@ -65,6 +68,7 @@ jobs:
6568
with:
6669
build-args: |
6770
pkg_version=${{ steps.tag.outputs.tag }}
71+
user_agent=${{ env.EKS_USER_AGENT }}
6872
context: .
6973
platforms: linux/arm64
7074
provenance: false
@@ -76,6 +80,7 @@ jobs:
7680
with:
7781
build-args: |
7882
pkg_version=${{ steps.tag.outputs.tag }}
83+
user_agent=${{ env.EKS_USER_AGENT }}
7984
context: .
8085
platforms: linux/amd64
8186
provenance: false
@@ -87,6 +92,7 @@ jobs:
8792
with:
8893
build-args: |
8994
pkg_version=${{ steps.tag.outputs.tag }}
95+
user_agent=${{ env.EKS_USER_AGENT }}
9096
context: .
9197
platforms: linux/amd64,linux/arm64
9298
provenance: false

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ RUN --mount=type=cache,target=${go_cache} --mount=type=cache,target=${go_mod_cac
3030

3131
ARG pkg_version
3232

33+
ARG user_agent="aws-privateca-issuer"
34+
3335
# Build
3436
RUN --mount=type=cache,target=${go_cache} --mount=type=cache,target=${go_mod_cache} \
3537
VERSION=$pkg_version && \
38+
USER_AGENT=$user_agent && \
3639
go build \
3740
-ldflags="-X=github.com/cert-manager/acm-pca-issuer/internal/version.Version=${VERSION} \
38-
-X github.com/cert-manager/aws-privateca-issuer/pkg/api/injections.PlugInVersion=${VERSION}" \
41+
-X github.com/cert-manager/aws-privateca-issuer/pkg/api/injections.PlugInVersion=${VERSION} \
42+
-X github.com/cert-manager/aws-privateca-issuer/pkg/api/injections.UserAgent=${USER_AGENT}" \
3943
-mod=readonly \
4044
-o manager main.go
4145

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ blog-test:
8585
# Build manager binary
8686
manager: generate fmt vet lint
8787
go build \
88-
-ldflags="-X github.com/cert-manager/aws-privateca-issuer/pkg/api/injections.PlugInVersion=${VERSION}" \
88+
-ldflags="-X github.com/cert-manager/aws-privateca-issuer/pkg/api/injections.PlugInVersion=${VERSION} \
89+
-X github.com/cert-manager/aws-privateca-issuer/pkg/api/injections.UserAgent=aws-privateca-issuer" \
8990
-o bin/manager main.go
9091

9192
# Run against the configured Kubernetes cluster in ~/.kube/config
@@ -148,6 +149,7 @@ docker-build: test
148149
--build-arg go_cache=${GOCACHE} \
149150
--build-arg go_mod_cache=${GOMODCACHE} \
150151
--build-arg pkg_version=${VERSION} \
152+
--build-arg user_agent=aws-privateca-issuer \
151153
--tag ${IMG} \
152154
--file Dockerfile \
153155
--platform=linux/amd64,linux/arm64 \

pkg/api/injections/injection_targets.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ var (
44
// PlugInVersion is the git version of the cert-manager plugin
55
PlugInVersion string
66
)
7+
8+
var (
9+
UserAgent string
10+
)

pkg/aws/pca.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func GetProvisioner(ctx context.Context, client client.Client, name types.Namesp
156156

157157
provisioner := &PCAProvisioner{
158158
pcaClient: acmpca.NewFromConfig(config, acmpca.WithAPIOptions(
159-
middleware.AddUserAgentKeyValue("aws-privateca-issuer", injections.PlugInVersion),
159+
middleware.AddUserAgentKeyValue(injections.UserAgent, injections.PlugInVersion),
160160
)),
161161
arn: spec.Arn,
162162
}

0 commit comments

Comments
 (0)