Skip to content

Commit

Permalink
Merge pull request #189 from gabriel-samfira/add-option-to-disable-ji…
Browse files Browse the repository at this point in the history
…t-config

Add option to disable JIT config
  • Loading branch information
gabriel-samfira committed Dec 11, 2023
2 parents 0e36eb7 + 49e06ef commit c712366
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 15 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
}
36 changes: 27 additions & 9 deletions testdata/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,21 @@ time_to_live = "8760h"
# provider must not be changed, or the pool will no longer work. Make sure you remove any
# pools before removing or changing a provider.
[[provider]]
# An arbitrary string describing this provider.
name = "lxd_local"
# Provider type. Garm is designed to allow creating providers which are used to spin
# up compute resources, which in turn will run the github runner software.
# Currently, LXD is the only supprted provider, but more will be written in the future.
provider_type = "lxd"
# A short description of this provider. The name, description and provider types will
# be included in the information returned by the API when listing available providers.
description = "Local LXD installation"
# An arbitrary string describing this provider.
name = "lxd_local"
# Provider type. Garm is designed to allow creating providers which are used to spin
# up compute resources, which in turn will run the github runner software.
# Currently, LXD is the only supprted provider, but more will be written in the future.
provider_type = "lxd"
# A short description of this provider. The name, description and provider types will
# be included in the information returned by the API when listing available providers.
description = "Local LXD installation"
# 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.
#
# Set this to true if your provider does not support JIT configuration.
disable_jit_config = false
[provider.lxd]
# the path to the unix socket that LXD is listening on. This works if garm and LXD
# are on the same system, and this option takes precedence over the "url" option,
Expand Down Expand Up @@ -191,6 +197,12 @@ time_to_live = "8760h"
name = "openstack_external"
description = "external openstack provider"
provider_type = "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.
#
# Set this to true if your provider does not support JIT configuration.
disable_jit_config = false
[provider.external]
# config file passed to the executable via GARM_PROVIDER_CONFIG_FILE environment variable
config_file = "/etc/garm/providers.d/openstack/keystonerc"
Expand All @@ -203,6 +215,12 @@ provider_type = "external"
name = "azure_external"
description = "external azure provider"
provider_type = "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.
#
# Set this to true if your provider does not support JIT configuration.
disable_jit_config = false
[provider.external]
# config file passed to the executable via GARM_PROVIDER_CONFIG_FILE environment variable
config_file = "/etc/garm/providers.d/azure/config.sh"
Expand Down

0 comments on commit c712366

Please sign in to comment.