Port pprof to experimental charts

This commit is contained in:
Nikola Jokic 2026-04-30 21:59:13 +02:00
parent 8c84ab2f42
commit a628793574
No known key found for this signature in database
GPG Key ID: 419BB425B0E501B0
5 changed files with 151 additions and 61 deletions

View File

@ -64,6 +64,9 @@ args:
- "--listener-metrics-endpoint="
- "--metrics-addr=0"
{{- end }}
{{- if .Values.controller.pprof.addr }}
- "--pprof-addr={{ .Values.controller.pprof.addr }}"
{{- end }}
{{- range .Values.controller.manager.config.excludeLabelPropagationPrefixes }}
- "--exclude-label-propagation-prefix={{ . }}"
{{- end }}
@ -86,6 +89,10 @@ args:
{{- $metricsPort := dict "containerPort" ((regexReplaceAll ":([0-9]+)" .Values.controller.metrics.controllerManagerAddr "${1}") | int) "protocol" "TCP" "name" "metrics" -}}
{{- $ports = append $ports $metricsPort -}}
{{- end }}
{{- if .Values.controller.pprof.addr }}
{{- $pprofPort := dict "containerPort" ((required "Values.controller.pprof.addr must end with a numeric port" (regexFind "[0-9]+$" .Values.controller.pprof.addr)) | int) "protocol" "TCP" "name" "pprof" -}}
{{- $ports = append $ports $pprofPort -}}
{{- end }}
{{- with .Values.controller.manager.container.extraPorts }}
{{- if kindIs "slice" . }}
{{- $ports = concat $ports . -}}

View File

@ -73,3 +73,64 @@ tests:
- contains:
path: spec.template.spec.containers[0].args
content: "--listener-metrics-endpoint=/metrics"
- it: should not include pprof arg by default
release:
name: "test-arc"
namespace: "test-ns"
asserts:
- notContains:
path: spec.template.spec.containers[0].args
content: "--pprof-addr="
- it: should not render pprof port by default
release:
name: "test-arc"
namespace: "test-ns"
asserts:
- notContains:
path: spec.template.spec.containers[0].ports
content:
name: pprof
- it: should include pprof arg when configured
set:
controller:
pprof:
addr: ":6060"
release:
name: "test-arc"
namespace: "test-ns"
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: "--pprof-addr=:6060"
- it: should render pprof port when configured
set:
controller:
pprof:
addr: ":6060"
release:
name: "test-arc"
namespace: "test-ns"
asserts:
- contains:
path: spec.template.spec.containers[0].ports
content:
name: pprof
containerPort: 6060
protocol: TCP
- it: should fail when pprof addr is malformed (no numeric port)
set:
controller:
pprof:
addr: "localhost"
release:
name: "test-arc"
namespace: "test-ns"
asserts:
- failedTemplate:
errorMessage: "Values.controller.pprof.addr must end with a numeric port"
template: deployment.yaml

View File

@ -50,3 +50,82 @@ func TestTemplate_RenderedDeployment_UsesChartMetadataLabels(t *testing.T) {
assert.Equal(t, "gha-rs-controller-"+chart.Version, deployment.Labels["helm.sh/chart"])
assert.Equal(t, chart.AppVersion, deployment.Labels["app.kubernetes.io/version"])
}
func TestTemplate_PprofDisabledByDefault(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../../gha-runner-scale-set-controller-experimental")
require.NoError(t, err)
releaseName := "test-arc"
namespaceName := "test-" + strings.ToLower(random.UniqueId())
options := &helm.Options{
Logger: logger.Discard,
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/deployment.yaml"})
var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(t, output, &deployment)
require.NotEmpty(t, deployment.Spec.Template.Spec.Containers, "Expected at least one container")
managerContainer := deployment.Spec.Template.Spec.Containers[0]
// Assert no pprof arg when default values
for _, arg := range managerContainer.Args {
assert.NotContains(t, arg, "--pprof-addr=", "Expected no pprof arg by default")
}
// Assert no pprof port when default values
for _, port := range managerContainer.Ports {
assert.NotEqual(t, "pprof", port.Name, "Expected no pprof port by default")
}
}
func TestTemplate_PprofEnabledWhenConfigured(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../../gha-runner-scale-set-controller-experimental")
require.NoError(t, err)
releaseName := "test-arc"
namespaceName := "test-" + strings.ToLower(random.UniqueId())
options := &helm.Options{
Logger: logger.Discard,
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
SetValues: map[string]string{
"controller.pprof.addr": ":6060",
},
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/deployment.yaml"})
var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(t, output, &deployment)
require.NotEmpty(t, deployment.Spec.Template.Spec.Containers, "Expected at least one container")
managerContainer := deployment.Spec.Template.Spec.Containers[0]
// Assert pprof arg is present
foundPprofArg := false
for _, arg := range managerContainer.Args {
if arg == "--pprof-addr=:6060" {
foundPprofArg = true
break
}
}
assert.True(t, foundPprofArg, "Expected --pprof-addr=:6060 arg when controller.pprof.addr is configured")
// Assert pprof port is present
foundPprofPort := false
for _, port := range managerContainer.Ports {
if port.Name == "pprof" && port.ContainerPort == 6060 && port.Protocol == "TCP" {
foundPprofPort = true
break
}
}
assert.True(t, foundPprofPort, "Expected pprof port (6060) when controller.pprof.addr is configured")
}

View File

@ -108,3 +108,7 @@ controller:
# listenerAddr: ":8080"
# listenerEndpoint: "/metrics"
# Pprof configuration. If omitted, pprof is disabled.
pprof: {}
# addr: ":6060"

View File

@ -1,61 +0,0 @@
package tests
import (
"os"
"path/filepath"
"strings"
"testing"
v1alpha1 "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
"github.com/gruntwork-io/terratest/modules/helm"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)
type Chart struct {
Version string `yaml:"version"`
AppVersion string `yaml:"appVersion"`
}
func TestTemplate_RenderedAutoscalingRunnerSet_UsesChartMetadataLabels(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../../gha-runner-scale-set-experimental")
require.NoError(t, err)
chartContent, err := os.ReadFile(filepath.Join(helmChartPath, "Chart.yaml"))
require.NoError(t, err)
chart := new(Chart)
err = yaml.Unmarshal(chartContent, chart)
require.NoError(t, err)
releaseName := "test-runners"
namespaceName := "test-" + strings.ToLower(random.UniqueId())
options := &helm.Options{
Logger: logger.Discard,
SetValues: map[string]string{
"scaleset.name": "test",
"auth.url": "https://github.com/actions",
"auth.githubToken": "gh_token12345",
"controllerServiceAccount.name": "arc",
"controllerServiceAccount.namespace": "arc-system",
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/autoscalingrunnserset.yaml"})
var autoscalingRunnerSet v1alpha1.AutoscalingRunnerSet
helm.UnmarshalK8SYaml(t, output, &autoscalingRunnerSet)
assert.Equal(t, "gha-rs-"+chart.Version, autoscalingRunnerSet.Labels["helm.sh/chart"])
assert.Equal(t, chart.AppVersion, autoscalingRunnerSet.Labels["app.kubernetes.io/version"])
assert.Equal(t, "gha-rs-"+chart.Version, autoscalingRunnerSet.Spec.Template.Labels["helm.sh/chart"])
assert.Equal(t, chart.AppVersion, autoscalingRunnerSet.Spec.Template.Labels["app.kubernetes.io/version"])
}