mirror of https://github.com/k3s-io/k3s
Add nodename to UA string for deploy controller
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>pull/3436/head
parent
2afa3dbe1c
commit
6ef000091a
|
@ -31,6 +31,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
ControllerName = "deploy"
|
||||
ns = "kube-system"
|
||||
startKey = "_start_"
|
||||
)
|
||||
|
|
|
@ -2,9 +2,14 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/k3s-io/helm-controller/pkg/generated/controllers/helm.cattle.io"
|
||||
"github.com/rancher/k3s/pkg/deploy"
|
||||
"github.com/rancher/k3s/pkg/generated/controllers/k3s.cattle.io"
|
||||
"github.com/rancher/k3s/pkg/version"
|
||||
"github.com/rancher/wrangler-api/pkg/generated/controllers/apps"
|
||||
"github.com/rancher/wrangler-api/pkg/generated/controllers/batch"
|
||||
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
|
||||
|
@ -12,6 +17,8 @@ import (
|
|||
"github.com/rancher/wrangler/pkg/apply"
|
||||
"github.com/rancher/wrangler/pkg/crd"
|
||||
"github.com/rancher/wrangler/pkg/start"
|
||||
"github.com/sirupsen/logrus"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
@ -38,6 +45,16 @@ func NewContext(ctx context.Context, cfg string) (*Context, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Construct a custom user-agent string for the apply client used by the deploy controller
|
||||
// so that we can track which node's deploy controller most recently modified a resource.
|
||||
nodeName := os.Getenv("NODE_NAME")
|
||||
managerName := deploy.ControllerName + "@" + nodeName
|
||||
if nodeName == "" || len(managerName) > validation.FieldManagerMaxLength {
|
||||
logrus.Warn("Deploy controller node name is empty or too long, and will not be tracked via server side apply field management")
|
||||
managerName = deploy.ControllerName
|
||||
}
|
||||
restConfig.UserAgent = fmt.Sprintf("%s/%s (%s/%s) %s/%s", managerName, version.Version, runtime.GOOS, runtime.GOARCH, version.Program, version.GitCommit)
|
||||
|
||||
if err := crds(ctx, restConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue