Skip to content

Commit

Permalink
Set user agent header (#3294)
Browse files Browse the repository at this point in the history
This sets our user agent header. The API server now receives 

> pulumi-kubernetes/4.0.0-alpha.0+dev (darwin/arm64) client-go/v0.31.0

Fixes #3267.
  • Loading branch information
blampe authored Oct 31, 2024
1 parent e0f6e13 commit e49daf0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
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)
}

0 comments on commit e49daf0

Please sign in to comment.