feat(client): created provider instance
Some checks failed
Go Tests / go-tests (push) Failing after 1m31s
Some checks failed
Go Tests / go-tests (push) Failing after 1m31s
This commit is contained in:
parent
3f375f88ff
commit
37de81a835
6 changed files with 340 additions and 11 deletions
|
|
@ -9,8 +9,8 @@ type AppInstance struct {
|
|||
Key AppInstanceKey `json:"key"`
|
||||
AppKey AppKey `json:"app_key"`
|
||||
Flavor Flavor `json:"flavor"`
|
||||
State string `json:"state"`
|
||||
PowerState string `json:"power_state"`
|
||||
State string `json:"state,omitempty"`
|
||||
PowerState string `json:"power_state,omitempty"`
|
||||
}
|
||||
|
||||
type AppInstanceKey struct {
|
||||
|
|
|
|||
120
internal/spec/spec.go
Normal file
120
internal/spec/spec.go
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
package spec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/cloudbase/garm-provider-common/params"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type GitHubScopeDetails struct {
|
||||
BaseURL string
|
||||
Repo string
|
||||
Org string
|
||||
Enterprise string
|
||||
}
|
||||
|
||||
func ExtractGitHubScopeDetails(gitRepoURL string) (GitHubScopeDetails, error) {
|
||||
if gitRepoURL == "" {
|
||||
return GitHubScopeDetails{}, fmt.Errorf("no gitRepoURL supplied")
|
||||
}
|
||||
u, err := url.Parse(gitRepoURL)
|
||||
if err != nil {
|
||||
return GitHubScopeDetails{}, fmt.Errorf("invalid URL: %w", err)
|
||||
}
|
||||
|
||||
if u.Scheme == "" || u.Host == "" {
|
||||
return GitHubScopeDetails{}, fmt.Errorf("invalid URL: %s", gitRepoURL)
|
||||
}
|
||||
|
||||
pathParts := strings.Split(strings.Trim(u.Path, "/"), "/")
|
||||
|
||||
scope := GitHubScopeDetails{
|
||||
BaseURL: u.Scheme + "://" + u.Host,
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(pathParts) == 1:
|
||||
scope.Org = pathParts[0]
|
||||
case len(pathParts) == 2 && pathParts[0] == "enterprises":
|
||||
scope.Enterprise = pathParts[1]
|
||||
case len(pathParts) == 2:
|
||||
scope.Org = pathParts[0]
|
||||
scope.Repo = pathParts[1]
|
||||
default:
|
||||
return GitHubScopeDetails{}, fmt.Errorf("URL does not match the expected patterns")
|
||||
}
|
||||
|
||||
return scope, nil
|
||||
}
|
||||
|
||||
func GetRunnerEnvs(gitHubScope GitHubScopeDetails, bootstrapParams params.BootstrapInstance) []corev1.EnvVar {
|
||||
return []corev1.EnvVar{
|
||||
{
|
||||
Name: "RUNNER_ORG",
|
||||
Value: gitHubScope.Org,
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_REPO",
|
||||
Value: gitHubScope.Repo,
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_ENTERPRISE",
|
||||
Value: gitHubScope.Enterprise,
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_GROUP",
|
||||
Value: bootstrapParams.GitHubRunnerGroup,
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_NAME",
|
||||
Value: bootstrapParams.Name,
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_LABELS",
|
||||
Value: strings.Join(bootstrapParams.Labels, ","),
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_NO_DEFAULT_LABELS",
|
||||
Value: "true",
|
||||
},
|
||||
{
|
||||
Name: "DISABLE_RUNNER_UPDATE",
|
||||
Value: "true",
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_WORKDIR",
|
||||
Value: "/runner/_work/",
|
||||
},
|
||||
{
|
||||
Name: "GITHUB_URL",
|
||||
Value: gitHubScope.BaseURL,
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_EPHEMERAL",
|
||||
Value: "true",
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_TOKEN",
|
||||
Value: "dummy",
|
||||
},
|
||||
{
|
||||
Name: "METADATA_URL",
|
||||
Value: bootstrapParams.MetadataURL,
|
||||
},
|
||||
{
|
||||
Name: "BEARER_TOKEN",
|
||||
Value: bootstrapParams.InstanceToken,
|
||||
},
|
||||
{
|
||||
Name: "CALLBACK_URL",
|
||||
Value: bootstrapParams.CallbackURL,
|
||||
},
|
||||
{
|
||||
Name: "JIT_CONFIG_ENABLED",
|
||||
Value: fmt.Sprintf("%t", bootstrapParams.JitConfigEnabled),
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue