Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user-agent string #352

Merged
merged 5 commits into from
Apr 9, 2021
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
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
GOFLAGS ?= "-tags=${CLOUD_PROVIDER}"

RELEASE_REPO ?= public.ecr.aws/b6u6q9h4
RELEASE_VERSION ?= v0.2.0
RELEASE_VERSION ?= $(shell git describe --tags --always --dirty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What on earth?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RELEASE_MANIFEST = releases/${CLOUD_PROVIDER}/manifest.yaml

## Inject the app version into project.Version
LDFLAGS ?= "-ldflags=-X=github.com/awslabs/karpenter/pkg/utils/project.Version=${RELEASE_VERSION}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these get picked up. Don't we need something on line 8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, line 8 already includes ${GOFLAGS} which includes the LDFLAGS since they are apart of the GOFLAGS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uploading image.png…

GOFLAGS ?= "-tags=${CLOUD_PROVIDER} ${LDFLAGS}"
WITH_GOFLAGS = GOFLAGS=${GOFLAGS}
WITH_RELEASE_REPO = KO_DOCKER_REPO=${RELEASE_REPO}

Expand Down
12 changes: 11 additions & 1 deletion pkg/cloudprovider/aws/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ limitations under the License.
package aws

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/iam"
Expand All @@ -26,6 +28,7 @@ import (
"github.com/awslabs/karpenter/pkg/cloudprovider"
"github.com/awslabs/karpenter/pkg/packing"
"github.com/awslabs/karpenter/pkg/utils/log"
"github.com/awslabs/karpenter/pkg/utils/project"
"github.com/patrickmn/go-cache"
)

Expand All @@ -50,7 +53,7 @@ type Factory struct {
}

func NewFactory(options cloudprovider.Options) *Factory {
sess := withRegion(session.Must(session.NewSession(&aws.Config{STSRegionalEndpoint: endpoints.RegionalSTSEndpoint})))
sess := withUserAgent(withRegion(session.Must(session.NewSession(&aws.Config{STSRegionalEndpoint: endpoints.RegionalSTSEndpoint}))))
ec2api := ec2.New(sess)
subnetProvider := &SubnetProvider{
ec2api: ec2api,
Expand Down Expand Up @@ -101,3 +104,10 @@ func withRegion(sess *session.Session) *session.Session {
sess.Config.Region = aws.String(region)
return sess
}

// withUserAgent adds a karpenter specific user-agent string to AWS session
func withUserAgent(sess *session.Session) *session.Session {
userAgent := fmt.Sprintf("karpenter.sh-%s", project.Version)
sess.Handlers.Build.PushBack(request.MakeAddToUserAgentFreeFormHandler(userAgent))
return sess
}
6 changes: 6 additions & 0 deletions pkg/utils/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import (
"runtime"
)

var (
// Version is the karpenter app version injected during compilation
// when using the Makefile
Version = "unspecified"
)

func RelativeToRoot(path string) string {
_, file, _, _ := runtime.Caller(0)
manifestsRoot := filepath.Join(filepath.Dir(file), "..", "..", "..")
Expand Down