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

chore: unified user-agent format #705

Merged
merged 1 commit into from
Apr 5, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [MAJOR.MINOR.PATCH] - YYYY-MM-DD

- Unified User-Agent format with the Terraform Provider

## v0.18.1 - 2024-04-02

- Add `KafkaSchemaRegistryACL` kind
Expand Down
16 changes: 14 additions & 2 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,26 @@ func isAivenServerError(err error) bool {
return status >= http.StatusInternalServerError
}

// userAgent is a helper function to create a User-Agent string used for the Go client.
func userAgent(kubeVersion, operatorVersion string) string {
// Remove the leading "v" from the version strings, if present.
// This is to unify the version format across the Terraform Provider and the Kubernetes Operator.
//
// Cf. terraform-provider-aiven/A.B.C/X.Y.Z vs. k8s-operator/vA.B.C/vX.Y.Z.
kubeVersion = strings.TrimPrefix(kubeVersion, "v")
operatorVersion = strings.TrimPrefix(operatorVersion, "v")

return fmt.Sprintf("k8s-operator/%s/%s", kubeVersion, operatorVersion)
}

// NewAivenClient returns Aiven client (aiven/aiven-go-client/v2)
func NewAivenClient(token, kubeVersion, operatorVersion string) (*aiven.Client, error) {
return aiven.NewTokenClient(token, fmt.Sprintf("k8s-operator/%s/%s", kubeVersion, operatorVersion))
return aiven.NewTokenClient(token, userAgent(kubeVersion, operatorVersion))
}

// NewAivenGeneratedClient returns Aiven generated client client (aiven/go-client-codegen)
func NewAivenGeneratedClient(token, kubeVersion, operatorVersion string) (avngen.Client, error) {
return avngen.NewClient(avngen.TokenOpt(token), avngen.UserAgentOpt(fmt.Sprintf("k8s-operator/%s/%s", kubeVersion, operatorVersion)))
return avngen.NewClient(avngen.TokenOpt(token), avngen.UserAgentOpt(userAgent(kubeVersion, operatorVersion)))
}

func fromAnyPointer[T any](v *T) T {
Expand Down
Loading