Skip to content

Commit

Permalink
Add option to disable JIT config
Browse files Browse the repository at this point in the history
This change adds a flag on providers that allows users to disable JIT
configuration even when it's available. For context, JIT is available
on github.com and any GHES instance >=3.10.

This option is a stopgap measure for providers that have not yet been
updated to use JIT configs instead of runner registration tokens.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
  • Loading branch information
gabriel-samfira committed Dec 11, 2023
1 parent 0e36eb7 commit 8596859
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
8 changes: 6 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ type Provider struct {
Name string `toml:"name" json:"name"`
ProviderType params.ProviderType `toml:"provider_type" json:"provider-type"`
Description string `toml:"description" json:"description"`
LXD LXD `toml:"lxd" json:"lxd"`
External External `toml:"external" json:"external"`
// DisableJITConfig explicitly disables JIT configuration and forces runner registration
// tokens to be used. This may happen if a provider has not yet been updated to support
// JIT configuration.
DisableJITConfig bool `toml:"disable_jit_config" json:"disable-jit-config"`
LXD LXD `toml:"lxd" json:"lxd"`
External External `toml:"external" json:"external"`
}

func (p *Provider) Validate() error {
Expand Down
14 changes: 14 additions & 0 deletions runner/common/mocks/Provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions runner/common/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Provider interface {
Stop(ctx context.Context, instance string, force bool) error
// Start boots up an instance.
Start(ctx context.Context, instance string) error
// DisableJITConfig tells us if the provider explicitly disables JIT configuration and
// forces runner registration tokens to be used. This may happen if a provider has not yet
// been updated to support JIT configuration.
DisableJITConfig() bool

AsParams() params.Provider
}
19 changes: 15 additions & 4 deletions runner/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,23 @@ func (r *basePoolManager) AddRunner(ctx context.Context, poolID string, aditiona
return errors.Wrap(err, "fetching pool")
}

provider, ok := r.providers[pool.ProviderName]
if !ok {
return fmt.Errorf("unknown provider %s for pool %s", pool.ProviderName, pool.ID)
}

name := fmt.Sprintf("%s-%s", pool.GetRunnerPrefix(), util.NewID())
labels := r.getLabelsForInstance(pool)
// Attempt to create JIT config
jitConfig, runner, err := r.helper.GetJITConfig(ctx, name, pool, labels)
if err != nil {
r.log("failed to get JIT config, falling back to registration token: %s", err)

jitConfig := make(map[string]string)
var runner *github.Runner

if !provider.DisableJITConfig() {
// Attempt to create JIT config
jitConfig, runner, err = r.helper.GetJITConfig(ctx, name, pool, labels)
if err != nil {
r.log("failed to get JIT config, falling back to registration token: %s", err)
}
}

createParams := params.CreateInstanceParams{
Expand Down
10 changes: 10 additions & 0 deletions runner/providers/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,13 @@ func (e *external) AsParams() params.Provider {
ProviderType: e.cfg.ProviderType,
}
}

// DisableJITConfig tells us if the provider explicitly disables JIT configuration and
// forces runner registration tokens to be used. This may happen if a provider has not yet
// been updated to support JIT configuration.
func (e *external) DisableJITConfig() bool {
if e.cfg == nil {
return false
}
return e.cfg.DisableJITConfig
}
10 changes: 10 additions & 0 deletions runner/providers/lxd/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,13 @@ func (l *LXD) Stop(ctx context.Context, instance string, force bool) error {
func (l *LXD) Start(ctx context.Context, instance string) error {
return l.setState(instance, "start", false)
}

// DisableJITConfig tells us if the provider explicitly disables JIT configuration and
// forces runner registration tokens to be used. This may happen if a provider has not yet
// been updated to support JIT configuration.
func (l *LXD) DisableJITConfig() bool {
if l.cfg == nil {
return false
}
return l.cfg.DisableJITConfig
}

0 comments on commit 8596859

Please sign in to comment.