Skip to content

Commit

Permalink
Merge pull request #2 from cloudbase/enable-windows
Browse files Browse the repository at this point in the history
Enable Windows userdata
  • Loading branch information
gabriel-samfira authored Jan 12, 2024
2 parents 91391ff + 3e6c277 commit 6db5286
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 47 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.5

require (
github.com/BurntSushi/toml v1.2.1
github.com/cloudbase/garm-provider-common v0.1.1
github.com/cloudbase/garm-provider-common v0.1.2-0.20240111235646-a9efac12b060
github.com/juju/clock v1.0.3
github.com/juju/retry v1.0.0
github.com/lxc/incus v0.3.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cloudbase/garm-provider-common v0.1.0 h1:gc2n8nsLjt7G3InAfqZ+75iZjSIUkIx86d6/DFA2+jc=
github.com/cloudbase/garm-provider-common v0.1.0/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc=
github.com/cloudbase/garm-provider-common v0.1.1 h1:9SbkEevpycI/P3J7jEmjJf6VzdrxAIHkLppnjqaKAWU=
github.com/cloudbase/garm-provider-common v0.1.1/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc=
github.com/cloudbase/garm-provider-common v0.1.2-0.20240111235646-a9efac12b060 h1:R1x91MisDJq61uioMULPycnQo6P4HWFyR3Pa9ePz8c4=
github.com/cloudbase/garm-provider-common v0.1.2-0.20240111235646-a9efac12b060/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
48 changes: 6 additions & 42 deletions provider/lxd.go → provider/incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/cloudbase/garm-provider-common/cloudconfig"
commonParams "github.com/cloudbase/garm-provider-common/params"
"github.com/cloudbase/garm-provider-common/util"
)

var _ execution.ExternalProvider = &Incus{}
Expand All @@ -53,19 +54,6 @@ const (
)

var (
// incusToGithubArchMap translates Incus architectures to Github tools architectures.
// TODO: move this in a separate package. This will most likely be used
// by any other provider.
incusToGithubArchMap map[string]string = map[string]string{
"x86_64": "x64",
"amd64": "x64",
"armv7l": "arm",
"aarch64": "arm64",
"x64": "x64",
"arm": "arm",
"arm64": "arm64",
}

configToIncusArchMap map[commonParams.OSArch]string = map[commonParams.OSArch]string{
commonParams.Amd64: "x86_64",
commonParams.Arm64: "aarch64",
Expand Down Expand Up @@ -172,34 +160,6 @@ func (l *Incus) getProfiles(ctx context.Context, flavor string) ([]string, error
return ret, nil
}

func (l *Incus) getTools(tools []commonParams.RunnerApplicationDownload, osType commonParams.OSType, architecture string) (commonParams.RunnerApplicationDownload, error) {
// Validate image OS. Linux only for now.
switch osType {
case commonParams.Linux:
default:
return commonParams.RunnerApplicationDownload{}, fmt.Errorf("this provider does not support OS type: %s", osType)
}

// Find tools for OS/Arch.
for _, tool := range tools {
if tool.GetOS() == "" || tool.GetArchitecture() == "" {
continue
}

// fmt.Println(*tool.Architecture, *tool.OS)
// fmt.Printf("image arch: %s --> osType: %s\n", image.Architecture, string(osType))
if tool.GetArchitecture() == architecture && tool.GetOS() == string(osType) {
return tool, nil
}

arch, ok := incusToGithubArchMap[architecture]
if ok && arch == tool.GetArchitecture() && tool.GetOS() == string(osType) {
return tool, nil
}
}
return commonParams.RunnerApplicationDownload{}, fmt.Errorf("failed to find tools for OS %s and arch %s", osType, architecture)
}

// sadly, the security.secureboot flag is a string encoded boolean.
func (l *Incus) secureBootEnabled() string {
if l.cfg.SecureBoot {
Expand Down Expand Up @@ -228,7 +188,7 @@ func (l *Incus) getCreateInstanceArgs(ctx context.Context, bootstrapParams commo
return api.InstancesPost{}, errors.Wrap(err, "getting instance source")
}

tools, err := l.getTools(bootstrapParams.Tools, bootstrapParams.OSType, arch)
tools, err := util.GetTools(bootstrapParams.OSType, bootstrapParams.OSArch, bootstrapParams.Tools)
if err != nil {
return api.InstancesPost{}, errors.Wrap(err, "getting tools")
}
Expand All @@ -241,6 +201,10 @@ func (l *Incus) getCreateInstanceArgs(ctx context.Context, bootstrapParams commo
return api.InstancesPost{}, errors.Wrap(err, "generating cloud-config")
}

if bootstrapParams.OSType == commonParams.Windows {
cloudCfg = fmt.Sprintf("#ps1_sysnative\n%s", cloudCfg)
}

configMap := map[string]string{
"user.user-data": cloudCfg,
osTypeKeyName: string(bootstrapParams.OSType),
Expand Down

0 comments on commit 6db5286

Please sign in to comment.