Skip to content

Commit

Permalink
Merge pull request #26 from gabriel-samfira/add-common-extra-specs
Browse files Browse the repository at this point in the history
Add common extra specs
  • Loading branch information
gabriel-samfira authored Jun 8, 2024
2 parents c431a19 + 7de1b3d commit e276022
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions internal/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,36 @@ const (
"type": "string",
"description": "The ID of the subnet to use for the VM. Must be in the same region as the VM. This is required if disable_isolated_networks is set to true, otherwise it is ignored."
},
"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."
},
"disable_isolated_networks": {
"type": "boolean",
"description": "Disable network isolation for the VM."
Expand Down Expand Up @@ -184,6 +214,9 @@ type extraSpecs struct {
UseAcceleratedNetworking *bool `json:"use_accelerated_networking"`
VnetSubnetID string `json:"vnet_subnet_id"`
DisableIsolatedNetworks *bool `json:"disable_isolated_networks"`
DisableUpdates *bool `json:"disable_updates"`
EnableBootDebug *bool `json:"enable_boot_debug"`
ExtraPackages []string `json:"extra_packages"`
}

func (e *extraSpecs) cleanInboundPorts() {
Expand Down Expand Up @@ -285,6 +318,7 @@ func GetRunnerSpecFromBootstrapParams(data params.BootstrapInstance, controllerI
UseAcceleratedNetworking: cfg.UseAcceleratedNetworking,
VnetSubnetID: cfg.VnetSubnetID,
DisableIsolatedNetworks: cfg.DisableIsolatedNetworks,
ExtraPackages: extraSpecs.ExtraPackages,
}

if extraSpecs.UseEphemeralStorage != nil {
Expand All @@ -295,6 +329,14 @@ func GetRunnerSpecFromBootstrapParams(data params.BootstrapInstance, controllerI
spec.UseAcceleratedNetworking = *extraSpecs.UseAcceleratedNetworking
}

if extraSpecs.DisableUpdates != nil {
spec.DisableUpdates = *extraSpecs.DisableUpdates
}

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

if extraSpecs.DisableIsolatedNetworks != nil {
spec.DisableIsolatedNetworks = *extraSpecs.DisableIsolatedNetworks
}
Expand Down Expand Up @@ -331,6 +373,9 @@ type RunnerSpec struct {
UseAcceleratedNetworking bool
VnetSubnetID string
DisableIsolatedNetworks bool
DisableUpdates bool
ExtraPackages []string
EnableBootDebug bool
}

func (r RunnerSpec) Validate() error {
Expand Down Expand Up @@ -385,15 +430,19 @@ func (r RunnerSpec) ImageDetails() (providerUtil.ImageDetails, error) {
}

func (r RunnerSpec) ComposeUserData() ([]byte, error) {
bootstrapParams := r.BootstrapParams
bootstrapParams.UserDataOptions.DisableUpdatesOnBoot = r.DisableUpdates
bootstrapParams.UserDataOptions.ExtraPackages = r.ExtraPackages
bootstrapParams.UserDataOptions.EnableBootDebug = r.EnableBootDebug
switch r.BootstrapParams.OSType {
case params.Linux, 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 nil, fmt.Errorf("failed to generate userdata: %w", err)
}
return []byte(udata), nil
}
return nil, fmt.Errorf("unsupported OS type for cloud config: %s", r.BootstrapParams.OSType)
return nil, fmt.Errorf("unsupported OS type for cloud config: %s", bootstrapParams.OSType)
}

func (r RunnerSpec) SecurityRules() []*armnetwork.SecurityRule {
Expand Down

0 comments on commit e276022

Please sign in to comment.