Skip to content

Commit

Permalink
add custom useragent to all aws requests
Browse files Browse the repository at this point in the history
  • Loading branch information
vdhanan committed Jun 1, 2021
1 parent 7f908fc commit a17ddc8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ VERSION=v1.0.0
VERSION_AMAZONLINUX=$(VERSION)-amazonlinux
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS?="-X ${PKG}/pkg/driver.driverVersion=${VERSION} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE} -s -w"
LDFLAGS?="-X ${PKG}/pkg/driver.driverVersion=${VERSION} -X ${PKG}/pkg/cloud.driverVersion=${VERSION} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE} -s -w"
GO111MODULE=on
GOPROXY=direct
GOPATH=$(shell go env GOPATH)
Expand Down
2 changes: 1 addition & 1 deletion charts/aws-ebs-csi-driver/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
appVersion: "1.0.0"
name: aws-ebs-csi-driver
description: A Helm chart for AWS EBS CSI Driver
version: 1.2.0
version: 1.3.0
kubeVersion: ">=1.17.0-0"
home: https://github.com/kubernetes-sigs/aws-ebs-csi-driver
sources:
Expand Down
2 changes: 2 additions & 0 deletions charts/aws-ebs-csi-driver/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ spec:
- --logtostderr
- --v=2
env:
- name: CSI_DRIVER_NAME
value: {{ .Chart.Name }}
- name: CSI_ENDPOINT
value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock
- name: CSI_NODE_NAME
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes/base/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ spec:
- --logtostderr
- --v=2
env:
- name: CSI_DRIVER_NAME
value: aws-ebs-csi-driver
- name: CSI_ENDPOINT
value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock
- name: CSI_NODE_NAME
Expand Down
14 changes: 14 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ var (
VolumeNotBeingModified = fmt.Errorf("volume is not being modified")
)

// Set during build time via -ldflags
var driverVersion string

// Disk represents a EBS volume
type Disk struct {
VolumeID string
Expand Down Expand Up @@ -239,6 +242,9 @@ func newEC2Cloud(region string, awsSdkDebugLog bool) (Cloud, error) {
awsConfig.WithLogLevel(aws.LogDebugWithRequestErrors)
}

// Set the env var so that the session appends custom user agent string
os.Setenv("AWS_EXECUTION_ENV", userAgent())

svc := ec2.New(session.Must(session.NewSession(awsConfig)))
svc.Handlers.AfterRetry.PushFrontNamed(request.NamedHandler{
Name: "recordThrottledRequestsHandler",
Expand Down Expand Up @@ -1191,3 +1197,11 @@ func capIOPS(volumeType string, requestedCapacityGiB int64, requstedIOPSPerGB, m
}
return iops, nil
}

func userAgent() string {
appName := os.Getenv("CSI_DRIVER_NAME")
if len(appName) == 0 {
appName = "aws-ebs-csi-driver"
}
return appName + "-" + driverVersion
}

0 comments on commit a17ddc8

Please sign in to comment.