Add configurable log format to values.yaml and propagate it to listener (#2686)
This commit is contained in:
parent
2fee26ddce
commit
6fe8008640
|
|
@ -56,6 +56,9 @@ spec:
|
||||||
{{- with .Values.flags.logLevel }}
|
{{- with .Values.flags.logLevel }}
|
||||||
- "--log-level={{ . }}"
|
- "--log-level={{ . }}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with .Values.flags.logFormat }}
|
||||||
|
- "--log-format={{ . }}"
|
||||||
|
{{- end }}
|
||||||
{{- with .Values.flags.watchSingleNamespace }}
|
{{- with .Values.flags.watchSingleNamespace }}
|
||||||
- "--watch-single-namespace={{ . }}"
|
- "--watch-single-namespace={{ . }}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,7 @@ func TestTemplate_CreateManagerListenerRole(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, namespaceName, managerListenerRole.Namespace, "Role should have a namespace")
|
assert.Equal(t, namespaceName, managerListenerRole.Namespace, "Role should have a namespace")
|
||||||
assert.Equal(t, "test-arc-gha-runner-scale-set-controller-manager-listener-role", managerListenerRole.Name)
|
assert.Equal(t, "test-arc-gha-runner-scale-set-controller-manager-listener-role", managerListenerRole.Name)
|
||||||
|
|
||||||
assert.Equal(t, 4, len(managerListenerRole.Rules))
|
assert.Equal(t, 4, len(managerListenerRole.Rules))
|
||||||
assert.Equal(t, "pods", managerListenerRole.Rules[0].Resources[0])
|
assert.Equal(t, "pods", managerListenerRole.Rules[0].Resources[0])
|
||||||
assert.Equal(t, "pods/status", managerListenerRole.Rules[1].Resources[0])
|
assert.Equal(t, "pods/status", managerListenerRole.Rules[1].Resources[0])
|
||||||
|
|
@ -356,10 +357,13 @@ func TestTemplate_ControllerDeployment_Defaults(t *testing.T) {
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
||||||
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Args, 3)
|
expectedArgs := []string{
|
||||||
assert.Equal(t, "--auto-scaling-runner-set-only", deployment.Spec.Template.Spec.Containers[0].Args[0])
|
"--auto-scaling-runner-set-only",
|
||||||
assert.Equal(t, "--log-level=debug", deployment.Spec.Template.Spec.Containers[0].Args[1])
|
"--log-level=debug",
|
||||||
assert.Equal(t, "--update-strategy=immediate", deployment.Spec.Template.Spec.Containers[0].Args[2])
|
"--log-format=text",
|
||||||
|
"--update-strategy=immediate",
|
||||||
|
}
|
||||||
|
assert.ElementsMatch(t, expectedArgs, deployment.Spec.Template.Spec.Containers[0].Args)
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Env, 3)
|
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Env, 3)
|
||||||
assert.Equal(t, "CONTROLLER_MANAGER_CONTAINER_IMAGE", deployment.Spec.Template.Spec.Containers[0].Env[0].Name)
|
assert.Equal(t, "CONTROLLER_MANAGER_CONTAINER_IMAGE", deployment.Spec.Template.Spec.Containers[0].Env[0].Name)
|
||||||
|
|
@ -420,6 +424,8 @@ func TestTemplate_ControllerDeployment_Customize(t *testing.T) {
|
||||||
"affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator": "bar",
|
"affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator": "bar",
|
||||||
"priorityClassName": "test-priority-class",
|
"priorityClassName": "test-priority-class",
|
||||||
"flags.updateStrategy": "eventual",
|
"flags.updateStrategy": "eventual",
|
||||||
|
"flags.logLevel": "info",
|
||||||
|
"flags.logFormat": "json",
|
||||||
},
|
},
|
||||||
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
|
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
|
||||||
}
|
}
|
||||||
|
|
@ -484,11 +490,15 @@ func TestTemplate_ControllerDeployment_Customize(t *testing.T) {
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
||||||
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Args, 4)
|
expectArgs := []string{
|
||||||
assert.Equal(t, "--auto-scaling-runner-set-only", deployment.Spec.Template.Spec.Containers[0].Args[0])
|
"--auto-scaling-runner-set-only",
|
||||||
assert.Equal(t, "--auto-scaler-image-pull-secrets=dockerhub", deployment.Spec.Template.Spec.Containers[0].Args[1])
|
"--auto-scaler-image-pull-secrets=dockerhub",
|
||||||
assert.Equal(t, "--log-level=debug", deployment.Spec.Template.Spec.Containers[0].Args[2])
|
"--log-level=info",
|
||||||
assert.Equal(t, "--update-strategy=eventual", deployment.Spec.Template.Spec.Containers[0].Args[3])
|
"--log-format=json",
|
||||||
|
"--update-strategy=eventual",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.ElementsMatch(t, expectArgs, deployment.Spec.Template.Spec.Containers[0].Args)
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Env, 4)
|
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Env, 4)
|
||||||
assert.Equal(t, "CONTROLLER_MANAGER_CONTAINER_IMAGE", deployment.Spec.Template.Spec.Containers[0].Env[0].Name)
|
assert.Equal(t, "CONTROLLER_MANAGER_CONTAINER_IMAGE", deployment.Spec.Template.Spec.Containers[0].Env[0].Name)
|
||||||
|
|
@ -605,12 +615,16 @@ func TestTemplate_EnableLeaderElection(t *testing.T) {
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
||||||
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Args, 5)
|
expectedArgs := []string{
|
||||||
assert.Equal(t, "--auto-scaling-runner-set-only", deployment.Spec.Template.Spec.Containers[0].Args[0])
|
"--auto-scaling-runner-set-only",
|
||||||
assert.Equal(t, "--enable-leader-election", deployment.Spec.Template.Spec.Containers[0].Args[1])
|
"--enable-leader-election",
|
||||||
assert.Equal(t, "--leader-election-id=test-arc-gha-runner-scale-set-controller", deployment.Spec.Template.Spec.Containers[0].Args[2])
|
"--leader-election-id=test-arc-gha-runner-scale-set-controller",
|
||||||
assert.Equal(t, "--log-level=debug", deployment.Spec.Template.Spec.Containers[0].Args[3])
|
"--log-level=debug",
|
||||||
assert.Equal(t, "--update-strategy=immediate", deployment.Spec.Template.Spec.Containers[0].Args[4])
|
"--log-format=text",
|
||||||
|
"--update-strategy=immediate",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.ElementsMatch(t, expectedArgs, deployment.Spec.Template.Spec.Containers[0].Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTemplate_ControllerDeployment_ForwardImagePullSecrets(t *testing.T) {
|
func TestTemplate_ControllerDeployment_ForwardImagePullSecrets(t *testing.T) {
|
||||||
|
|
@ -639,11 +653,15 @@ func TestTemplate_ControllerDeployment_ForwardImagePullSecrets(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, namespaceName, deployment.Namespace)
|
assert.Equal(t, namespaceName, deployment.Namespace)
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Args, 4)
|
expectedArgs := []string{
|
||||||
assert.Equal(t, "--auto-scaling-runner-set-only", deployment.Spec.Template.Spec.Containers[0].Args[0])
|
"--auto-scaling-runner-set-only",
|
||||||
assert.Equal(t, "--auto-scaler-image-pull-secrets=dockerhub,ghcr", deployment.Spec.Template.Spec.Containers[0].Args[1])
|
"--auto-scaler-image-pull-secrets=dockerhub,ghcr",
|
||||||
assert.Equal(t, "--log-level=debug", deployment.Spec.Template.Spec.Containers[0].Args[2])
|
"--log-level=debug",
|
||||||
assert.Equal(t, "--update-strategy=immediate", deployment.Spec.Template.Spec.Containers[0].Args[3])
|
"--log-format=text",
|
||||||
|
"--update-strategy=immediate",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.ElementsMatch(t, expectedArgs, deployment.Spec.Template.Spec.Containers[0].Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTemplate_ControllerDeployment_WatchSingleNamespace(t *testing.T) {
|
func TestTemplate_ControllerDeployment_WatchSingleNamespace(t *testing.T) {
|
||||||
|
|
@ -721,11 +739,15 @@ func TestTemplate_ControllerDeployment_WatchSingleNamespace(t *testing.T) {
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Command, 1)
|
||||||
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
assert.Equal(t, "/manager", deployment.Spec.Template.Spec.Containers[0].Command[0])
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Args, 4)
|
expectedArgs := []string{
|
||||||
assert.Equal(t, "--auto-scaling-runner-set-only", deployment.Spec.Template.Spec.Containers[0].Args[0])
|
"--auto-scaling-runner-set-only",
|
||||||
assert.Equal(t, "--log-level=debug", deployment.Spec.Template.Spec.Containers[0].Args[1])
|
"--log-level=debug",
|
||||||
assert.Equal(t, "--watch-single-namespace=demo", deployment.Spec.Template.Spec.Containers[0].Args[2])
|
"--log-format=text",
|
||||||
assert.Equal(t, "--update-strategy=immediate", deployment.Spec.Template.Spec.Containers[0].Args[3])
|
"--watch-single-namespace=demo",
|
||||||
|
"--update-strategy=immediate",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.ElementsMatch(t, expectedArgs, deployment.Spec.Template.Spec.Containers[0].Args)
|
||||||
|
|
||||||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Env, 3)
|
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].Env, 3)
|
||||||
assert.Equal(t, "CONTROLLER_MANAGER_CONTAINER_IMAGE", deployment.Spec.Template.Spec.Containers[0].Env[0].Name)
|
assert.Equal(t, "CONTROLLER_MANAGER_CONTAINER_IMAGE", deployment.Spec.Template.Spec.Containers[0].Env[0].Name)
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@ flags:
|
||||||
## Log level can be set here with one of the following values: "debug", "info", "warn", "error".
|
## Log level can be set here with one of the following values: "debug", "info", "warn", "error".
|
||||||
## Defaults to "debug".
|
## Defaults to "debug".
|
||||||
logLevel: "debug"
|
logLevel: "debug"
|
||||||
|
## Log format can be set with one of the following values: "text", "json"
|
||||||
|
## Defaults to "text"
|
||||||
|
logFormat: "text"
|
||||||
|
|
||||||
## Restricts the controller to only watch resources in the desired namespace.
|
## Restricts the controller to only watch resources in the desired namespace.
|
||||||
## Defaults to watch all namespaces when unset.
|
## Defaults to watch all namespaces when unset.
|
||||||
|
|
|
||||||
|
|
@ -46,18 +46,30 @@ type RunnerScaleSetListenerConfig struct {
|
||||||
MinRunners int `split_words:"true"`
|
MinRunners int `split_words:"true"`
|
||||||
RunnerScaleSetId int `split_words:"true"`
|
RunnerScaleSetId int `split_words:"true"`
|
||||||
ServerRootCA string `split_words:"true"`
|
ServerRootCA string `split_words:"true"`
|
||||||
|
LogLevel string `split_words:"true"`
|
||||||
|
LogFormat string `split_words:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logger, err := logging.NewLogger(logging.LogLevelDebug, logging.LogFormatText)
|
var rc RunnerScaleSetListenerConfig
|
||||||
if err != nil {
|
if err := envconfig.Process("github", &rc); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: creating logger: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: processing environment variables for RunnerScaleSetListenerConfig: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rc RunnerScaleSetListenerConfig
|
logLevel := string(logging.LogLevelDebug)
|
||||||
if err := envconfig.Process("github", &rc); err != nil {
|
if rc.LogLevel != "" {
|
||||||
logger.Error(err, "Error: processing environment variables for RunnerScaleSetListenerConfig")
|
logLevel = rc.LogLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
logFormat := string(logging.LogFormatText)
|
||||||
|
if rc.LogFormat != "" {
|
||||||
|
logFormat = rc.LogFormat
|
||||||
|
}
|
||||||
|
|
||||||
|
logger, err := logging.NewLogger(logLevel, logFormat)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: creating logger: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
package actionsgithubcom
|
package actionsgithubcom
|
||||||
|
|
||||||
import corev1 "k8s.io/api/core/v1"
|
import (
|
||||||
|
"github.com/actions/actions-runner-controller/logging"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LabelKeyRunnerTemplateHash = "runner-template-hash"
|
LabelKeyRunnerTemplateHash = "runner-template-hash"
|
||||||
|
|
@ -60,5 +63,11 @@ const (
|
||||||
// to the listener when ImagePullPolicy is not specified
|
// to the listener when ImagePullPolicy is not specified
|
||||||
const DefaultScaleSetListenerImagePullPolicy = corev1.PullIfNotPresent
|
const DefaultScaleSetListenerImagePullPolicy = corev1.PullIfNotPresent
|
||||||
|
|
||||||
|
// DefaultScaleSetListenerLogLevel is the default log level applied
|
||||||
|
const DefaultScaleSetListenerLogLevel = string(logging.LogLevelDebug)
|
||||||
|
|
||||||
|
// DefaultScaleSetListenerLogFormat is the default log format applied
|
||||||
|
const DefaultScaleSetListenerLogFormat = string(logging.LogFormatText)
|
||||||
|
|
||||||
// ownerKey is field selector matching the owner name of a particular resource
|
// ownerKey is field selector matching the owner name of a particular resource
|
||||||
const resourceOwnerKey = ".metadata.controller"
|
const resourceOwnerKey = ".metadata.controller"
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/actions/actions-runner-controller/build"
|
"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/hash"
|
"github.com/actions/actions-runner-controller/hash"
|
||||||
|
"github.com/actions/actions-runner-controller/logging"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
@ -46,6 +47,27 @@ func SetListenerImagePullPolicy(pullPolicy string) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var scaleSetListenerLogLevel = DefaultScaleSetListenerLogLevel
|
||||||
|
var scaleSetListenerLogFormat = DefaultScaleSetListenerLogFormat
|
||||||
|
|
||||||
|
func SetListenerLoggingParameters(level string, format string) bool {
|
||||||
|
switch level {
|
||||||
|
case logging.LogLevelDebug, logging.LogLevelInfo, logging.LogLevelWarn, logging.LogLevelError:
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch format {
|
||||||
|
case logging.LogFormatJSON, logging.LogFormatText:
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
scaleSetListenerLogLevel = level
|
||||||
|
scaleSetListenerLogFormat = format
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
type resourceBuilder struct{}
|
type resourceBuilder struct{}
|
||||||
|
|
||||||
func (b *resourceBuilder) newAutoScalingListener(autoscalingRunnerSet *v1alpha1.AutoscalingRunnerSet, ephemeralRunnerSet *v1alpha1.EphemeralRunnerSet, namespace, image string, imagePullSecrets []corev1.LocalObjectReference) (*v1alpha1.AutoscalingListener, error) {
|
func (b *resourceBuilder) newAutoScalingListener(autoscalingRunnerSet *v1alpha1.AutoscalingRunnerSet, ephemeralRunnerSet *v1alpha1.EphemeralRunnerSet, namespace, image string, imagePullSecrets []corev1.LocalObjectReference) (*v1alpha1.AutoscalingListener, error) {
|
||||||
|
|
@ -128,6 +150,14 @@ func (b *resourceBuilder) newScaleSetListenerPod(autoscalingListener *v1alpha1.A
|
||||||
Name: "GITHUB_RUNNER_SCALE_SET_ID",
|
Name: "GITHUB_RUNNER_SCALE_SET_ID",
|
||||||
Value: strconv.Itoa(autoscalingListener.Spec.RunnerScaleSetId),
|
Value: strconv.Itoa(autoscalingListener.Spec.RunnerScaleSetId),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "GITHUB_RUNNER_LOG_LEVEL",
|
||||||
|
Value: scaleSetListenerLogLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "GITHUB_RUNNER_LOG_FORMAT",
|
||||||
|
Value: scaleSetListenerLogFormat,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
listenerEnv = append(listenerEnv, envs...)
|
listenerEnv = append(listenerEnv, envs...)
|
||||||
|
|
||||||
|
|
|
||||||
8
main.go
8
main.go
|
|
@ -182,12 +182,18 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
listenerPullPolicy := os.Getenv("CONTROLLER_MANAGER_LISTENER_IMAGE_PULL_POLICY")
|
listenerPullPolicy := os.Getenv("CONTROLLER_MANAGER_LISTENER_IMAGE_PULL_POLICY")
|
||||||
if ok := actionsgithubcom.SetListenerImagePullPolicy(listenerPullPolicy); ok {
|
if actionsgithubcom.SetListenerImagePullPolicy(listenerPullPolicy) {
|
||||||
log.Info("AutoscalingListener image pull policy changed", "ImagePullPolicy", listenerPullPolicy)
|
log.Info("AutoscalingListener image pull policy changed", "ImagePullPolicy", listenerPullPolicy)
|
||||||
} else {
|
} else {
|
||||||
log.Info("Using default AutoscalingListener image pull policy", "ImagePullPolicy", actionsgithubcom.DefaultScaleSetListenerImagePullPolicy)
|
log.Info("Using default AutoscalingListener image pull policy", "ImagePullPolicy", actionsgithubcom.DefaultScaleSetListenerImagePullPolicy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if actionsgithubcom.SetListenerLoggingParameters(logLevel, logFormat) {
|
||||||
|
log.Info("AutoscalingListener logging parameters changed", "LogLevel", logLevel, "LogFormat", logFormat)
|
||||||
|
} else {
|
||||||
|
log.Info("Using default AutoscalingListener logging parameters", "LogLevel", actionsgithubcom.DefaultScaleSetListenerLogLevel, "LogFormat", actionsgithubcom.DefaultScaleSetListenerLogFormat)
|
||||||
|
}
|
||||||
|
|
||||||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
NewCache: newCache,
|
NewCache: newCache,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue