Add nodename to UA string for deploy controller

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/3436/head
Brad Davidson 2021-06-10 11:27:36 -07:00 committed by Brad Davidson
parent 2afa3dbe1c
commit 6ef000091a
2 changed files with 20 additions and 2 deletions

View File

@ -31,8 +31,9 @@ import (
)
const (
ns = "kube-system"
startKey = "_start_"
ControllerName = "deploy"
ns = "kube-system"
startKey = "_start_"
)
func WatchFiles(ctx context.Context, apply apply.Apply, addons v1.AddonController, disables map[string]bool, bases ...string) error {

View File

@ -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
}