From 9fa90954a70293efe0d3f837739b1c1675dd33b4 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Fri, 7 Jun 2024 16:55:57 +0000 Subject: [PATCH] Add common extra specs The garm-provider-common package gives us a few extra specs we can tweak. Some of those extra specs are useful for systems that use cloud-init to initialize. Some are useful even without cloud init. The following extra specs are added to the GCP provider: * enable_boot_debug - sets the -x option * runner_install_template - allows us to overwrite the default runner install template. * extra_context - the runner_install_template can be a golang template which can define some variables that can be expanded from a hashtable of string key/value pairs. Signed-off-by: Gabriel Adrian Samfira --- README.md | 15 +++++++++++++++ internal/spec/spec.go | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f030a4f..3444f3e 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,21 @@ To this end, this provider supports the following extra specs schema: "source_snapshot": { "type": "string", "description": "The source snapshot to create this disk." + }, + "enable_boot_debug": { + "type": "boolean", + "description": "Enable boot debug on the VM." + }, + "runner_install_template": { + "type": "string", + "description": "This option can be used to override the default runner install template. If used, the caller is responsible for the correctness of the template as well as the suitability of the template for the target OS. Use the extra_context extra spec if your template has variables in it that need to be expanded." + }, + "extra_context": { + "type": "object", + "description": "Extra context that will be passed to the runner_install_template.", + "additionalProperties": { + "type": "string" + } } }, "additionalProperties": false diff --git a/internal/spec/spec.go b/internal/spec/spec.go index d3fd39b..d6903fb 100644 --- a/internal/spec/spec.go +++ b/internal/spec/spec.go @@ -79,6 +79,21 @@ const ( "source_snapshot": { "type": "string", "description": "The source snapshot to create this disk." + }, + "enable_boot_debug": { + "type": "boolean", + "description": "Enable boot debug on the VM." + }, + "runner_install_template": { + "type": "string", + "description": "This option can be used to override the default runner install template. If used, the caller is responsible for the correctness of the template as well as the suitability of the template for the target OS. Use the extra_context extra spec if your template has variables in it that need to be expanded." + }, + "extra_context": { + "type": "object", + "description": "Extra context that will be passed to the runner_install_template.", + "additionalProperties": { + "type": "string" + } } }, "additionalProperties": false @@ -160,13 +175,14 @@ func (e *extraSpecs) Validate() error { } type extraSpecs struct { - DiskSize int64 `json:"disksize,omitempty"` - NetworkID string `json:"network_id,omitempty"` - SubnetworkID string `json:"subnetwork_id,omitempty"` - NicType string `json:"nic_type,omitempty"` - CustomLabels map[string]string `json:"custom_labels,omitempty"` - NetworkTags []string `json:"network_tags,omitempty"` - SourceSnapshot string `json:"source_snapshot,omitempty"` + DiskSize int64 `json:"disksize,omitempty"` + NetworkID string `json:"network_id,omitempty"` + SubnetworkID string `json:"subnetwork_id,omitempty"` + NicType string `json:"nic_type,omitempty"` + CustomLabels map[string]string `json:"custom_labels,omitempty"` + NetworkTags []string `json:"network_tags,omitempty"` + SourceSnapshot string `json:"source_snapshot,omitempty"` + EnableBootDebug *bool `json:"enable_boot_debug"` } func GetRunnerSpecFromBootstrapParams(cfg *config.Config, data params.BootstrapInstance, controllerID string) (*RunnerSpec, error) { @@ -215,6 +231,7 @@ type RunnerSpec struct { CustomLabels map[string]string NetworkTags []string SourceSnapshot string + EnableBootDebug bool } func (r *RunnerSpec) MergeExtraSpecs(extraSpecs *extraSpecs) { @@ -239,6 +256,9 @@ func (r *RunnerSpec) MergeExtraSpecs(extraSpecs *extraSpecs) { if extraSpecs.SourceSnapshot != "" { r.SourceSnapshot = extraSpecs.SourceSnapshot } + if extraSpecs.EnableBootDebug != nil { + r.EnableBootDebug = *extraSpecs.EnableBootDebug + } } func (r *RunnerSpec) Validate() error { @@ -257,11 +277,13 @@ func (r *RunnerSpec) Validate() error { if r.NicType == "" { return fmt.Errorf("missing nic type") } - return nil } func (r RunnerSpec) ComposeUserData() (string, error) { + bootstrapParams := r.BootstrapParams + bootstrapParams.UserDataOptions.EnableBootDebug = r.EnableBootDebug + switch r.BootstrapParams.OSType { case params.Linux: udata, err := cloudconfig.GetRunnerInstallScript(r.BootstrapParams, r.Tools, r.BootstrapParams.Name) @@ -287,7 +309,7 @@ func (r RunnerSpec) ComposeUserData() (string, error) { script := strings.Join(scriptCommands, "\n") return script, nil case params.Windows: - udata, err := cloudconfig.GetRunnerInstallScript(r.BootstrapParams, r.Tools, r.BootstrapParams.Name) + udata, err := cloudconfig.GetRunnerInstallScript(bootstrapParams, r.Tools, bootstrapParams.Name) if err != nil { return "", fmt.Errorf("failed to generate userdata: %w", err) }