Include extra user-agent for runners created by actions-runner-controller. (#2177)

This commit is contained in:
Tingluo Huang 2023-01-17 17:38:59 -05:00 committed by GitHub
parent 23fdca4786
commit bb61bb1342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View File

@ -23,6 +23,7 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
"github.com/actions/actions-runner-controller/build"
"github.com/actions/actions-runner-controller/github/actions" "github.com/actions/actions-runner-controller/github/actions"
"github.com/actions/actions-runner-controller/logging" "github.com/actions/actions-runner-controller/logging"
"github.com/go-logr/logr" "github.com/go-logr/logr"
@ -83,7 +84,7 @@ func run(rc RunnerScaleSetListenerConfig, logger logr.Logger) error {
} }
} }
actionsServiceClient, err := actions.NewClient(ctx, rc.ConfigureUrl, creds, "actions-runner-controller", logger) actionsServiceClient, err := actions.NewClient(ctx, rc.ConfigureUrl, creds, fmt.Sprintf("actions-runner-controller/%s", build.Version), logger)
if err != nil { if err != nil {
return fmt.Errorf("failed to create an Actions Service client: %w", err) return fmt.Errorf("failed to create an Actions Service client: %w", err)
} }

View File

@ -6,5 +6,6 @@ const (
) )
const ( const (
EnvVarRunnerJITConfig = "ACTIONS_RUNNER_INPUT_JITCONFIG" EnvVarRunnerJITConfig = "ACTIONS_RUNNER_INPUT_JITCONFIG"
EnvVarRunnerExtraUserAgent = "GITHUB_ACTIONS_RUNNER_EXTRA_USER_AGENT"
) )

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1" "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
"github.com/actions/actions-runner-controller/build"
"github.com/actions/actions-runner-controller/hash" "github.com/actions/actions-runner-controller/hash"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
@ -357,17 +358,23 @@ func (b *resourceBuilder) newEphemeralRunnerPod(ctx context.Context, runner *v1a
for _, c := range runner.Spec.PodTemplateSpec.Spec.Containers { for _, c := range runner.Spec.PodTemplateSpec.Spec.Containers {
if c.Name == EphemeralRunnerContainerName { if c.Name == EphemeralRunnerContainerName {
c.Env = append(c.Env, corev1.EnvVar{ c.Env = append(
Name: EnvVarRunnerJITConfig, c.Env,
ValueFrom: &corev1.EnvVarSource{ corev1.EnvVar{
SecretKeyRef: &corev1.SecretKeySelector{ Name: EnvVarRunnerJITConfig,
LocalObjectReference: corev1.LocalObjectReference{ ValueFrom: &corev1.EnvVarSource{
Name: secret.Name, SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: secret.Name,
},
Key: jitTokenKey,
}, },
Key: jitTokenKey,
}, },
}, },
}) corev1.EnvVar{
Name: EnvVarRunnerExtraUserAgent,
Value: fmt.Sprintf("actions-runner-controller/%s", build.Version),
})
} }
newPod.Spec.Containers = append(newPod.Spec.Containers, c) newPod.Spec.Containers = append(newPod.Spec.Containers, c)