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

Update garm-provider-common #182

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
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
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.20

require (
github.com/BurntSushi/toml v1.2.1
github.com/cloudbase/garm-provider-common v0.0.0-20230924074517-dd3e26769a05
github.com/cloudbase/garm-provider-common v0.1.0
github.com/go-openapi/errors v0.20.4
github.com/go-openapi/runtime v0.26.0
github.com/go-openapi/strfmt v0.21.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudbase/garm-provider-common v0.0.0-20230924074517-dd3e26769a05 h1:V9TQBCnwTeKX+gpmlEtZAQ5gNbYrdGelAA3jgnGde1c=
github.com/cloudbase/garm-provider-common v0.0.0-20230924074517-dd3e26769a05/go.mod h1:NgR629o2NYWTffZt3uURmu3orjMDQ2vh6KJ5ytwh7Qw=
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/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
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=
Expand Down
13 changes: 11 additions & 2 deletions runner/pool/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"

runnerErrors "github.com/cloudbase/garm-provider-common/errors"
commonParams "github.com/cloudbase/garm-provider-common/params"
dbCommon "github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/params"
"github.com/cloudbase/garm/runner/common"
Expand Down Expand Up @@ -224,7 +225,7 @@ func (r *enterprise) GetGithubRunners() ([]*github.Runner, error) {
return allRunners, nil
}

func (r *enterprise) FetchTools() ([]*github.RunnerApplicationDownload, error) {
func (r *enterprise) FetchTools() ([]commonParams.RunnerApplicationDownload, error) {
r.mux.Lock()
defer r.mux.Unlock()
tools, ghResp, err := r.ghcEnterpriseCli.ListRunnerApplicationDownloads(r.ctx, r.cfg.Name)
Expand All @@ -235,7 +236,15 @@ func (r *enterprise) FetchTools() ([]*github.RunnerApplicationDownload, error) {
return nil, errors.Wrap(err, "fetching runner tools")
}

return tools, nil
ret := []commonParams.RunnerApplicationDownload{}
for _, tool := range tools {
if tool == nil {
continue
}
ret = append(ret, commonParams.RunnerApplicationDownload(*tool))
}

return ret, nil
}

func (r *enterprise) FetchDbInstances() ([]params.Instance, error) {
Expand Down
3 changes: 2 additions & 1 deletion runner/pool/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pool
import (
"context"

commonParams "github.com/cloudbase/garm-provider-common/params"
"github.com/cloudbase/garm/params"
"github.com/cloudbase/garm/runner/common"

Expand All @@ -29,7 +30,7 @@ type poolHelper interface {
GetGithubRegistrationToken() (string, error)
GetRunnerInfoFromWorkflow(job params.WorkflowJob) (params.RunnerInfo, error)
RemoveGithubRunner(runnerID int64) (*github.Response, error)
FetchTools() ([]*github.RunnerApplicationDownload, error)
FetchTools() ([]commonParams.RunnerApplicationDownload, error)

InstallHook(ctx context.Context, req *github.Hook) (params.HookInfo, error)
UninstallHook(ctx context.Context, url string) error
Expand Down
13 changes: 11 additions & 2 deletions runner/pool/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sync"

runnerErrors "github.com/cloudbase/garm-provider-common/errors"
commonParams "github.com/cloudbase/garm-provider-common/params"
dbCommon "github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/params"
"github.com/cloudbase/garm/runner/common"
Expand Down Expand Up @@ -236,7 +237,7 @@ func (r *organization) GetGithubRunners() ([]*github.Runner, error) {
return allRunners, nil
}

func (r *organization) FetchTools() ([]*github.RunnerApplicationDownload, error) {
func (r *organization) FetchTools() ([]commonParams.RunnerApplicationDownload, error) {
r.mux.Lock()
defer r.mux.Unlock()
tools, ghResp, err := r.ghcli.ListOrganizationRunnerApplicationDownloads(r.ctx, r.cfg.Name)
Expand All @@ -247,7 +248,15 @@ func (r *organization) FetchTools() ([]*github.RunnerApplicationDownload, error)
return nil, errors.Wrap(err, "fetching runner tools")
}

return tools, nil
ret := []commonParams.RunnerApplicationDownload{}
for _, tool := range tools {
if tool == nil {
continue
}
ret = append(ret, commonParams.RunnerApplicationDownload(*tool))
}

return ret, nil
}

func (r *organization) FetchDbInstances() ([]params.Instance, error) {
Expand Down
2 changes: 1 addition & 1 deletion runner/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type basePoolManager struct {
store dbCommon.Store

providers map[string]common.Provider
tools []*github.RunnerApplicationDownload
tools []commonParams.RunnerApplicationDownload
quit chan struct{}

helper poolHelper
Expand Down
13 changes: 11 additions & 2 deletions runner/pool/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sync"

runnerErrors "github.com/cloudbase/garm-provider-common/errors"
commonParams "github.com/cloudbase/garm-provider-common/params"
dbCommon "github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/params"
"github.com/cloudbase/garm/runner/common"
Expand Down Expand Up @@ -200,7 +201,7 @@ func (r *repository) GetGithubRunners() ([]*github.Runner, error) {
return allRunners, nil
}

func (r *repository) FetchTools() ([]*github.RunnerApplicationDownload, error) {
func (r *repository) FetchTools() ([]commonParams.RunnerApplicationDownload, error) {
r.mux.Lock()
defer r.mux.Unlock()
tools, ghResp, err := r.ghcli.ListRunnerApplicationDownloads(r.ctx, r.cfg.Owner, r.cfg.Name)
Expand All @@ -211,7 +212,15 @@ func (r *repository) FetchTools() ([]*github.RunnerApplicationDownload, error) {
return nil, errors.Wrap(err, "fetching runner tools")
}

return tools, nil
ret := []commonParams.RunnerApplicationDownload{}
for _, tool := range tools {
if tool == nil {
continue
}
ret = append(ret, commonParams.RunnerApplicationDownload(*tool))
}

return ret, nil
}

func (r *repository) FetchDbInstances() ([]params.Instance, error) {
Expand Down
20 changes: 8 additions & 12 deletions runner/providers/lxd/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/cloudbase/garm/params"
"github.com/cloudbase/garm/runner/common"

"github.com/google/go-github/v55/github"
lxd "github.com/lxc/lxd/client"
"github.com/lxc/lxd/shared/api"
"github.com/pkg/errors"
Expand Down Expand Up @@ -173,35 +172,32 @@ func (l *LXD) getProfiles(flavor string) ([]string, error) {
return ret, nil
}

func (l *LXD) getTools(tools []*github.RunnerApplicationDownload, osType commonParams.OSType, architecture string) (github.RunnerApplicationDownload, error) {
func (l *LXD) 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 github.RunnerApplicationDownload{}, fmt.Errorf("this provider does not support OS type: %s", osType)
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 == nil {
continue
}
if tool.OS == nil || tool.Architecture == nil {
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.Architecture == architecture && *tool.OS == string(osType) {
return *tool, nil
if tool.GetArchitecture() == architecture && tool.GetOS() == string(osType) {
return tool, nil
}

arch, ok := lxdToGithubArchMap[architecture]
if ok && arch == *tool.Architecture && *tool.OS == string(osType) {
return *tool, nil
if ok && arch == tool.GetArchitecture() && tool.GetOS() == string(osType) {
return tool, nil
}
}
return github.RunnerApplicationDownload{}, fmt.Errorf("failed to find tools for OS %s and arch %s", osType, architecture)
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.
Expand Down
Loading