Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common extra specs #6

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 53 additions & 5 deletions internal/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ const (
"subnet_id": {
"type": "string",
"pattern": "^subnet-[0-9a-fA-F]{17}$"
},
"disable_updates": {
"type": "boolean",
"description": "Disable automatic updates on the VM."
},
"enable_boot_debug": {
"type": "boolean",
"description": "Enable boot debug on the VM."
},
"extra_packages": {
"type": "array",
"description": "Extra packages to install on the VM.",
"items": {
"type": "string"
}
},
"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"
}
},
"pre_install_scripts": {
"type": "object",
"description": "A map of pre-install scripts that will be run before the runner install script. These will run as root and can be used to prep a generic image before we attempt to install the runner. The key of the map is the name of the script as it will be written to disk. The value is a byte array with the contents of the script."
}
},
"additionalProperties": false
Expand Down Expand Up @@ -78,7 +108,10 @@ func newExtraSpecsFromBootstrapData(data params.BootstrapInstance) (*extraSpecs,
}

type extraSpecs struct {
SubnetID *string `json:"subnet_id,omitempty"`
SubnetID *string `json:"subnet_id,omitempty"`
DisableUpdates *bool `json:"disable_updates"`
EnableBootDebug *bool `json:"enable_boot_debug"`
ExtraPackages []string `json:"extra_packages"`
}

func GetRunnerSpecFromBootstrapParams(cfg *config.Config, data params.BootstrapInstance, controllerID string) (*RunnerSpec, error) {
Expand All @@ -94,6 +127,7 @@ func GetRunnerSpecFromBootstrapParams(cfg *config.Config, data params.BootstrapI

spec := &RunnerSpec{
Region: cfg.Region,
ExtraPackages: extraSpecs.ExtraPackages,
Tools: tools,
BootstrapParams: data,
SubnetID: cfg.SubnetID,
Expand All @@ -107,6 +141,9 @@ func GetRunnerSpecFromBootstrapParams(cfg *config.Config, data params.BootstrapI

type RunnerSpec struct {
Region string
DisableUpdates bool
ExtraPackages []string
EnableBootDebug bool
Tools params.RunnerApplicationDownload
BootstrapParams params.BootstrapInstance
SubnetID string
Expand All @@ -127,25 +164,36 @@ func (r *RunnerSpec) MergeExtraSpecs(extraSpecs *extraSpecs) {
if extraSpecs.SubnetID != nil && *extraSpecs.SubnetID != "" {
r.SubnetID = *extraSpecs.SubnetID
}
if extraSpecs.DisableUpdates != nil {
r.DisableUpdates = *extraSpecs.DisableUpdates
}

if extraSpecs.EnableBootDebug != nil {
r.EnableBootDebug = *extraSpecs.EnableBootDebug
}
}

func (r *RunnerSpec) ComposeUserData() (string, error) {
switch r.BootstrapParams.OSType {
bootstrapParams := r.BootstrapParams
bootstrapParams.UserDataOptions.DisableUpdatesOnBoot = r.DisableUpdates
bootstrapParams.UserDataOptions.ExtraPackages = r.ExtraPackages
bootstrapParams.UserDataOptions.EnableBootDebug = r.EnableBootDebug
switch bootstrapParams.OSType {
case params.Linux:
udata, err := cloudconfig.GetCloudConfig(r.BootstrapParams, r.Tools, r.BootstrapParams.Name)
udata, err := cloudconfig.GetCloudConfig(bootstrapParams, r.Tools, bootstrapParams.Name)
if err != nil {
return "", fmt.Errorf("failed to generate userdata: %w", err)
}
asBase64 := base64.StdEncoding.EncodeToString([]byte(udata))
return asBase64, nil
case params.Windows:
udata, err := cloudconfig.GetCloudConfig(r.BootstrapParams, r.Tools, r.BootstrapParams.Name)
udata, err := cloudconfig.GetCloudConfig(bootstrapParams, r.Tools, bootstrapParams.Name)
if err != nil {
return "", fmt.Errorf("failed to generate userdata: %w", err)
}
wrapped := fmt.Sprintf("<powershell>%s</powershell>", udata)
asBase64 := base64.StdEncoding.EncodeToString([]byte(wrapped))
return asBase64, nil
}
return "", fmt.Errorf("unsupported OS type for cloud config: %s", r.BootstrapParams.OSType)
return "", fmt.Errorf("unsupported OS type for cloud config: %s", bootstrapParams.OSType)
}
Loading