This commit is contained in:
parent
94d7147953
commit
0b01584122
5 changed files with 349 additions and 16 deletions
|
|
@ -53,16 +53,8 @@ func ExtractGitHubScopeDetails(gitRepoURL string) (GitHubScopeDetails, error) {
|
|||
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_GITEA_INSTANCE",
|
||||
Value: bootstrapParams.RepoURL,
|
||||
},
|
||||
{
|
||||
Name: "RUNNER_GROUP",
|
||||
|
|
|
|||
47
internal/spec/spec_test.go
Normal file
47
internal/spec/spec_test.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package spec_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/spec"
|
||||
)
|
||||
|
||||
func TestExtractGitHubScopeDetails(t *testing.T) {
|
||||
gitRepoURL := "https://github.com/gabriel-samfira/scripts"
|
||||
details, err := spec.ExtractGitHubScopeDetails(gitRepoURL)
|
||||
if err != nil {
|
||||
t.Errorf("An error occurred: %v", err)
|
||||
}
|
||||
|
||||
if details.BaseURL != "https://github.com" {
|
||||
t.Errorf(`ExtractGitHubScopeDetails("https://github.com/gabriel-samfira/scripts").BaseURL = %s, want match for %s`, details.BaseURL, "https://github.com")
|
||||
}
|
||||
|
||||
if details.Org != "gabriel-samfira" {
|
||||
t.Errorf(`ExtractGitHubScopeDetails("https://github.com/gabriel-samfira/scripts").Org = %s, want match for %s`, details.Org, "gabriel-samfira")
|
||||
}
|
||||
|
||||
if details.Repo != "scripts" {
|
||||
t.Errorf(`ExtractGitHubScopeDetails("https://github.com/gabriel-samfira/scripts").Repo = %s, want match for %s`, details.Repo, "scripts")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractGitHubScopeDetails_Gitea(t *testing.T) {
|
||||
gitRepoURL := "https://gitea.com/Christopher.Hase/garm-test"
|
||||
details, err := spec.ExtractGitHubScopeDetails(gitRepoURL)
|
||||
if err != nil {
|
||||
t.Errorf("An error occurred: %v", err)
|
||||
}
|
||||
|
||||
if details.BaseURL != "https://gitea.com" {
|
||||
t.Errorf(`ExtractGitHubScopeDetails("https://gitea.com/Christopher.Hase/garm-test").BaseURL = %s, want match for %s`, details.BaseURL, "https://gitea.com")
|
||||
}
|
||||
|
||||
if details.Org != "Christopher.Hase" {
|
||||
t.Errorf(`ExtractGitHubScopeDetails("https://gitea.com/Christopher.Hase/garm-test").Org = %s, want match for %s`, details.Org, "Christopher.Hase")
|
||||
}
|
||||
|
||||
if details.Repo != "garm-test" {
|
||||
t.Errorf(`ExtractGitHubScopeDetails("https://gitea.com/Christopher.Hase/garm-test").Repo = %s, want match for %s`, details.Repo, "garm-test")
|
||||
}
|
||||
}
|
||||
|
|
@ -21,10 +21,12 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/config"
|
||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
|
||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/spec"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
@ -36,6 +38,13 @@ import (
|
|||
|
||||
var Version = "v0.0.0-unknown"
|
||||
|
||||
type GitHubScopeDetails struct {
|
||||
BaseURL string
|
||||
Repo string
|
||||
Org string
|
||||
Enterprise string
|
||||
}
|
||||
|
||||
func NewEdgeConnectProvider(configPath, controllerID string) (execution.ExternalProvider, string, error) {
|
||||
conf, err := config.NewConfig(configPath)
|
||||
if err != nil {
|
||||
|
|
@ -72,9 +81,17 @@ type edgeConnectProvider struct {
|
|||
// CreateInstance creates a new compute instance in the provider.
|
||||
func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParams params.BootstrapInstance) (params.ProviderInstance, error) {
|
||||
log.Printf("Executing CreateInstance with %v\n", bootstrapParams)
|
||||
log.Printf("Executing CreateInstance with RepoURL %v\n", bootstrapParams.RepoURL)
|
||||
|
||||
instancename := fmt.Sprintf("garm-%v-%v-%v", a.controllerID[:8], bootstrapParams.PoolID[:8], strings.ToLower(bootstrapParams.Name))
|
||||
|
||||
gitHubScopeDetails, err := spec.ExtractGitHubScopeDetails(bootstrapParams.RepoURL)
|
||||
if err != nil {
|
||||
return params.ProviderInstance{}, err
|
||||
}
|
||||
|
||||
envs := spec.GetRunnerEnvs(gitHubScopeDetails, bootstrapParams)
|
||||
|
||||
podv1 := corev1.Pod{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Pod",
|
||||
|
|
@ -88,17 +105,25 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
Containers: []corev1.Container{
|
||||
corev1.Container{
|
||||
Name: "mganter-test",
|
||||
Image: "edp.buildth.ing/devfw-cicd/nginx",
|
||||
Image: "edp.buildth.ing/devfw-cicd/garm-act-runner:1",
|
||||
ImagePullPolicy: "Always",
|
||||
Ports: []corev1.ContainerPort{
|
||||
corev1.ContainerPort{
|
||||
Name: "HTTP",
|
||||
ContainerPort: 80,
|
||||
Protocol: "TCP",
|
||||
Env: envs,
|
||||
VolumeMounts: []corev1.VolumeMount{
|
||||
corev1.VolumeMount{
|
||||
MountPath: "/runner",
|
||||
Name: "cache-volume",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Volumes: []corev1.Volume{
|
||||
corev1.Volume{
|
||||
Name: "cache-volume",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -215,6 +240,109 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
return instance, 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),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Delete instance will delete the instance in a provider.
|
||||
func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance string) error {
|
||||
log.Printf("Executing DeleteInstance %s\n", instance)
|
||||
|
|
|
|||
74
stdinlala.json
Normal file
74
stdinlala.json
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"name": "garm-ny9HeeQYw2rl",
|
||||
"tools": [
|
||||
{
|
||||
"os": "osx",
|
||||
"architecture": "x64",
|
||||
"download_url": "https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-osx-x64-2.299.1.tar.gz",
|
||||
"filename": "actions-runner-osx-x64-2.299.1.tar.gz",
|
||||
"sha256_checksum": "b0128120f2bc48e5f24df513d77d1457ae845a692f60acf3feba63b8d01a8fdc"
|
||||
},
|
||||
{
|
||||
"os": "linux",
|
||||
"architecture": "x64",
|
||||
"download_url": "https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-x64-2.299.1.tar.gz",
|
||||
"filename": "actions-runner-linux-x64-2.299.1.tar.gz",
|
||||
"sha256_checksum": "147c14700c6cb997421b9a239c012197f11ea9854cd901ee88ead6fe73a72c74"
|
||||
},
|
||||
{
|
||||
"os": "win",
|
||||
"architecture": "x64",
|
||||
"download_url": "https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-win-x64-2.299.1.zip",
|
||||
"filename": "actions-runner-win-x64-2.299.1.zip",
|
||||
"sha256_checksum": "f7940b16451d6352c38066005f3ee6688b53971fcc20e4726c7907b32bfdf539"
|
||||
},
|
||||
{
|
||||
"os": "linux",
|
||||
"architecture": "arm",
|
||||
"download_url": "https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-arm-2.299.1.tar.gz",
|
||||
"filename": "actions-runner-linux-arm-2.299.1.tar.gz",
|
||||
"sha256_checksum": "a4d66a766ff3b9e07e3e068a1d88b04e51c27c9b94ae961717e0a5f9ada998e6"
|
||||
},
|
||||
{
|
||||
"os": "linux",
|
||||
"architecture": "arm64",
|
||||
"download_url": "https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-linux-arm64-2.299.1.tar.gz",
|
||||
"filename": "actions-runner-linux-arm64-2.299.1.tar.gz",
|
||||
"sha256_checksum": "debe1cc9656963000a4fbdbb004f475ace5b84360ace2f7a191c1ccca6a16c00"
|
||||
},
|
||||
{
|
||||
"os": "osx",
|
||||
"architecture": "arm64",
|
||||
"download_url": "https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-osx-arm64-2.299.1.tar.gz",
|
||||
"filename": "actions-runner-osx-arm64-2.299.1.tar.gz",
|
||||
"sha256_checksum": "f73849b9a78459d2e08b9d3d2f60464a55920de120e228b0645b01abe68d9072"
|
||||
},
|
||||
{
|
||||
"os": "win",
|
||||
"architecture": "arm64",
|
||||
"download_url": "https://github.com/actions/runner/releases/download/v2.299.1/actions-runner-win-arm64-2.299.1.zip",
|
||||
"filename": "actions-runner-win-arm64-2.299.1.zip",
|
||||
"sha256_checksum": "d1a9d8209f03589c8dc05ee17ae8d194756377773a4010683348cdd6eefa2da7"
|
||||
}
|
||||
],
|
||||
"repo_url": "https://github.com/gabriel-samfira/scripts",
|
||||
"callback-url": "https://garm.example.com/api/v1/callbacks",
|
||||
"metadata-url": "https://garm.example.com/api/v1/metadata",
|
||||
"instance-token": "super secret JWT token",
|
||||
"extra_specs": {
|
||||
"my_custom_config": "some_value"
|
||||
},
|
||||
"ca-cert-bundle": null,
|
||||
"github-runner-group": "my_group",
|
||||
"os_type": "linux",
|
||||
"arch": "amd64",
|
||||
"flavor": "m1.small",
|
||||
"image": "8ed8a690-69b6-49eb-982f-dcb466895e2d",
|
||||
"labels": [
|
||||
"ubuntu",
|
||||
"openstack",
|
||||
"runner-controller-id:f9286791-1589-4f39-a106-5b68c2a18af4",
|
||||
"runner-pool-id:9dcf590a-1192-4a9c-b3e4-e0902974c2c0"
|
||||
],
|
||||
"pool_id": "9dcf590a"
|
||||
}
|
||||
92
testpod.yaml
Normal file
92
testpod.yaml
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {
|
||||
"labels": {
|
||||
"run": "garm-50cb196d-50fa68a5-garm-ff7ugu1ab8yo"
|
||||
},
|
||||
"name": "garm-50cb196d-50fa68a5-garm-ff7ugu1ab8yo"
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"env": [
|
||||
{
|
||||
"name": "RUNNER_GITEA_INSTANCE",
|
||||
"value": "https://gitea.com"
|
||||
},
|
||||
{
|
||||
"name": "RUNNER_GROUP"
|
||||
},
|
||||
{
|
||||
"name": "RUNNER_NAME",
|
||||
"value": "garm-Ff7Ugu1AB8YO"
|
||||
},
|
||||
{
|
||||
"name": "RUNNER_LABELS",
|
||||
"value": "n,runner-controller-id=50cb196d-0d3d-4223-996f-11e5f10c30ba,runner-pool-id=50fa68a5-cadf-4d84-a78a-eafeb3bfd0b0"
|
||||
},
|
||||
{
|
||||
"name": "RUNNER_NO_DEFAULT_LABELS",
|
||||
"value": "true"
|
||||
},
|
||||
{
|
||||
"name": "DISABLE_RUNNER_UPDATE",
|
||||
"value": "true"
|
||||
},
|
||||
{
|
||||
"name": "RUNNER_WORKDIR",
|
||||
"value": "/runner/_work/"
|
||||
},
|
||||
{
|
||||
"name": "GITHUB_URL",
|
||||
"value": "https://gitea.com"
|
||||
},
|
||||
{
|
||||
"name": "RUNNER_EPHEMERAL",
|
||||
"value": "true"
|
||||
},
|
||||
{
|
||||
"name": "RUNNER_TOKEN",
|
||||
"value": "dummy"
|
||||
},
|
||||
{
|
||||
"name": "METADATA_URL",
|
||||
"value": "https://garm.garm-provider-test.t09.de/api/v1/metadata"
|
||||
},
|
||||
{
|
||||
"name": "BEARER_TOKEN",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlYTc2MjgxLWM2ZTYtNDRkNy04M2IwLTA3YjZjNTRhNWNmMCIsIm5hbWUiOiJnYXJtLUROendIZnB3ajJJcSIsInByb3ZpZGVyX2lkIjoiNTBmYTY4YTUtY2FkZi00ZDg0LWE3OGEtZWFmZWIzYmZkMGIwIiwic2NvcGUiOiJyZXBvc2l0b3J5IiwiZW50aXR5IjoiQ2hyaXN0b3BoZXIuSGFzZS9nYXJtLXRlc3QiLCJjcmVhdGVfYXR0ZW1wdCI6MCwiZm9yZ2VfdHlwZSI6ImdpdGVhIiwiaXNzIjoiZ2FybSIsImV4cCI6MTc1NzQxOTg0MX0.ukbdJo7n64m9l2olye3NRq3KK59iFVjXY5eom08W2UQ"
|
||||
},
|
||||
{
|
||||
"name": "CALLBACK_URL",
|
||||
"value": "https://garm.garm-provider-test.t09.de/api/v1/callbacks"
|
||||
},
|
||||
{
|
||||
"name": "JIT_CONFIG_ENABLED",
|
||||
"value": "false"
|
||||
}
|
||||
],
|
||||
"image": "edp.buildth.ing/devfw-cicd/garm-act-runner:1",
|
||||
"imagePullPolicy": "Always",
|
||||
"name": "mganter-test",
|
||||
"resources": {
|
||||
},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"mountPath": "/runner",
|
||||
"name": "cache-volume"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "cache-volume",
|
||||
"emptyDir": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue