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

Set user agent header #3294

Merged
merged 20 commits into from
Oct 31, 2024
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
`before-first-apply` conflict when Pulumi performs a server-side apply for
the first time. (https://github.com/pulumi/pulumi-kubernetes/pull/3275)

- The provider's user agent is now set correctly when communicating with
the Kubernetes API server.
(https://github.com/pulumi/pulumi-kubernetes/issues/3267)

## 4.18.2 (October 16, 2024)

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/openapi"
providerresource "github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/provider/resource"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/ssa"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/version"
pulumischema "github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/providers"
"github.com/pulumi/pulumi/pkg/v3/resource/provider"
Expand Down Expand Up @@ -852,6 +853,7 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
logger.V(9).Infof("kube client timeout set to %v", config.Timeout)
}
config.WarningHandler = rest.NoWarnings{}
config.UserAgent = version.UserAgent
}
}

Expand Down
34 changes: 34 additions & 0 deletions provider/pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,39 @@

package version

import (
"fmt"
"runtime"
"runtime/debug"
)

// Version is initialized by the Go linker to contain the semver of this build.
var Version string

// UserAgent is how the provider identifies itself to the API server.
var UserAgent string

func init() {
bi, ok := debug.ReadBuildInfo()
if !ok {
panic("unable to read build info")
}
clientGoVersion := "unknown"
for _, dep := range bi.Deps {
if dep.Path != "k8s.io/client-go" {
continue
}
clientGoVersion = dep.Version
}
version := "dev"
if Version != "" {
version = Version
}
UserAgent = fmt.Sprintf("%s/%s (%s/%s) client-go/%s",
"pulumi-kubernetes",
version,
runtime.GOOS,
runtime.GOARCH,
clientGoVersion,
)
}
11 changes: 11 additions & 0 deletions provider/pkg/version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package version

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestUserAgent(t *testing.T) {
assert.Regexp(t, "^pulumi-kubernetes/dev (.*/.*) client-go/unknown$", UserAgent)
}
Loading