Moving to scaleset client for the controller (#4390)

This commit is contained in:
Nikola Jokic
2026-03-13 14:36:41 +01:00
committed by GitHub
parent 1d9f626c53
commit f99c6eda0b
27 changed files with 2695 additions and 360 deletions
+6 -36
View File
@@ -9,11 +9,11 @@ import (
"net/http"
"net/url"
"os"
"strings"
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1/appconfig"
"github.com/actions/actions-runner-controller/build"
"github.com/actions/actions-runner-controller/logger"
"github.com/actions/actions-runner-controller/vault"
"github.com/actions/actions-runner-controller/vault/azurekeyvault"
"github.com/actions/scaleset"
@@ -23,7 +23,7 @@ import (
const appName = "ghalistener"
type Config struct {
ConfigureUrl string `json:"configure_url"`
ConfigureURL string `json:"configure_url"`
VaultType vault.VaultType `json:"vault_type"`
VaultLookupKey string `json:"vault_lookup_key"`
// If the VaultType is set to "azure_key_vault", this field must be populated.
@@ -102,7 +102,7 @@ func Read(ctx context.Context, configPath string) (*Config, error) {
// Validate checks the configuration for errors.
func (c *Config) Validate() error {
if len(c.ConfigureUrl) == 0 {
if len(c.ConfigureURL) == 0 {
return fmt.Errorf("GitHubConfigUrl is not provided")
}
@@ -137,37 +137,7 @@ func (c *Config) Validate() error {
}
func (c *Config) Logger() (*slog.Logger, error) {
var lvl slog.Level
switch strings.ToLower(c.LogLevel) {
case "debug":
lvl = slog.LevelDebug
case "info":
lvl = slog.LevelInfo
case "warn":
lvl = slog.LevelWarn
case "error":
lvl = slog.LevelError
default:
return nil, fmt.Errorf("invalid log level: %s", c.LogLevel)
}
var logger *slog.Logger
switch c.LogFormat {
case "json":
logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
Level: lvl,
}))
case "text":
logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
Level: lvl,
}))
default:
return nil, fmt.Errorf("invalid log format: %s", c.LogFormat)
}
return logger.With("app", appName), nil
return logger.New(c.LogLevel, c.LogFormat)
}
func (c *Config) ActionsClient(logger *slog.Logger, clientOptions ...scaleset.HTTPOption) (*scaleset.Client, error) {
@@ -207,7 +177,7 @@ func (c *Config) ActionsClient(logger *slog.Logger, clientOptions ...scaleset.HT
case "":
c, err := scaleset.NewClientWithGitHubApp(
scaleset.ClientWithGitHubAppConfig{
GitHubConfigURL: c.ConfigureUrl,
GitHubConfigURL: c.ConfigureURL,
GitHubAppAuth: scaleset.GitHubAppAuth{
ClientID: c.AppConfig.AppID,
InstallationID: c.AppConfig.AppInstallationID,
@@ -224,7 +194,7 @@ func (c *Config) ActionsClient(logger *slog.Logger, clientOptions ...scaleset.HT
default:
c, err := scaleset.NewClientWithPersonalAccessToken(
scaleset.NewClientWithPersonalAccessTokenConfig{
GitHubConfigURL: c.ConfigureUrl,
GitHubConfigURL: c.ConfigureURL,
PersonalAccessToken: c.Token,
SystemInfo: systemInfo,
},
+4 -4
View File
@@ -54,7 +54,7 @@ func TestCustomerServerRootCA(t *testing.T) {
certsString = certsString + string(intermediate)
config := config.Config{
ConfigureUrl: server.ConfigURLForOrg("myorg"),
ConfigureURL: server.ConfigURLForOrg("myorg"),
ServerRootCA: certsString,
AppConfig: &appconfig.AppConfig{
Token: "token",
@@ -85,7 +85,7 @@ func TestProxySettings(t *testing.T) {
defer os.Setenv("http_proxy", prevProxy)
config := config.Config{
ConfigureUrl: "https://github.com/org/repo",
ConfigureURL: "https://github.com/org/repo",
AppConfig: &appconfig.AppConfig{
Token: "token",
},
@@ -103,7 +103,7 @@ func TestProxySettings(t *testing.T) {
defer os.Setenv("https_proxy", prevProxy)
config := config.Config{
ConfigureUrl: "https://github.com/org/repo",
ConfigureURL: "https://github.com/org/repo",
AppConfig: &appconfig.AppConfig{
Token: "token",
},
@@ -124,7 +124,7 @@ func TestProxySettings(t *testing.T) {
defer os.Setenv("no_proxy", prevNoProxy)
config := config.Config{
ConfigureUrl: "https://github.com/org/repo",
ConfigureURL: "https://github.com/org/repo",
AppConfig: &appconfig.AppConfig{
Token: "token",
},
@@ -10,7 +10,7 @@ import (
func TestConfigValidationMinMax(t *testing.T) {
config := &Config{
ConfigureUrl: "github.com/some_org/some_repo",
ConfigureURL: "github.com/some_org/some_repo",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -26,7 +26,7 @@ func TestConfigValidationMinMax(t *testing.T) {
func TestConfigValidationMissingToken(t *testing.T) {
config := &Config{
ConfigureUrl: "github.com/some_org/some_repo",
ConfigureURL: "github.com/some_org/some_repo",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -46,7 +46,7 @@ func TestConfigValidationAppKey(t *testing.T) {
AppID: "1",
AppInstallationID: 10,
},
ConfigureUrl: "github.com/some_org/some_repo",
ConfigureURL: "github.com/some_org/some_repo",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -63,7 +63,7 @@ func TestConfigValidationAppKey(t *testing.T) {
AppID: "Iv23f8doAlphaNumer1c",
AppInstallationID: 10,
},
ConfigureUrl: "github.com/some_org/some_repo",
ConfigureURL: "github.com/some_org/some_repo",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -82,7 +82,7 @@ func TestConfigValidationOnlyOneTypeOfCredentials(t *testing.T) {
AppPrivateKey: "asdf",
Token: "asdf",
},
ConfigureUrl: "github.com/some_org/some_repo",
ConfigureURL: "github.com/some_org/some_repo",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -94,7 +94,7 @@ func TestConfigValidationOnlyOneTypeOfCredentials(t *testing.T) {
func TestConfigValidation(t *testing.T) {
config := &Config{
ConfigureUrl: "https://github.com/actions",
ConfigureURL: "https://github.com/actions",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -125,7 +125,7 @@ func TestConfigValidationConfigUrl(t *testing.T) {
func TestConfigValidationWithVaultConfig(t *testing.T) {
t.Run("valid", func(t *testing.T) {
config := &Config{
ConfigureUrl: "https://github.com/actions",
ConfigureURL: "https://github.com/actions",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -140,7 +140,7 @@ func TestConfigValidationWithVaultConfig(t *testing.T) {
t.Run("invalid vault type", func(t *testing.T) {
config := &Config{
ConfigureUrl: "https://github.com/actions",
ConfigureURL: "https://github.com/actions",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
@@ -155,7 +155,7 @@ func TestConfigValidationWithVaultConfig(t *testing.T) {
t.Run("vault type set without lookup key", func(t *testing.T) {
config := &Config{
ConfigureUrl: "https://github.com/actions",
ConfigureURL: "https://github.com/actions",
EphemeralRunnerSetNamespace: "namespace",
EphemeralRunnerSetName: "deployment",
RunnerScaleSetID: 1,
+1 -1
View File
@@ -40,7 +40,7 @@ func main() {
}
func run(ctx context.Context, config *config.Config) error {
ghConfig, err := actions.ParseGitHubConfigFromURL(config.ConfigureUrl)
ghConfig, err := actions.ParseGitHubConfigFromURL(config.ConfigureURL)
if err != nil {
return fmt.Errorf("failed to parse GitHub config from URL: %w", err)
}