Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #497 from thestormforge/ua-string
Browse files Browse the repository at this point in the history
Add the Kubernetes version to the application poller requests
  • Loading branch information
jgustie authored Sep 28, 2022
2 parents bbbc720 + 388327f commit 0bf06e9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions controllers/application_poller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import (
"github.com/thestormforge/optimize-controller/v2/internal/scan"
"github.com/thestormforge/optimize-controller/v2/internal/server"
"github.com/thestormforge/optimize-controller/v2/internal/sfio"
"github.com/thestormforge/optimize-controller/v2/internal/version"
"github.com/thestormforge/optimize-go/pkg/api"
applications "github.com/thestormforge/optimize-go/pkg/api/applications/v2"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metameta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/discovery"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -56,7 +56,15 @@ type Poller struct {
}

func (p *Poller) SetupWithManager(mgr ctrl.Manager) error {
appAPI, err := server.NewApplicationAPI(context.Background(), version.GetInfo().String())
// Compute the UA string comment using the Kube API server information
var comment string
if dc, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig()); err == nil {
if serverVersion, err := dc.ServerVersion(); err == nil && serverVersion.GitVersion != "" {
comment = fmt.Sprintf("Kubernetes %s", strings.TrimPrefix(serverVersion.GitVersion, "v"))
}
}

appAPI, err := server.NewApplicationAPI(context.Background(), comment)
if err != nil {
p.Log.Info("Application API is unavailable, skipping setup", "message", err.Error())
return nil
Expand Down

0 comments on commit 0bf06e9

Please sign in to comment.