Skip to content

Commit

Permalink
Add support for repo-level runners. Fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen committed Jun 28, 2020
1 parent eaa5d57 commit cbcd59d
Show file tree
Hide file tree
Showing 7 changed files with 5,487 additions and 5,392 deletions.
10,748 changes: 5,410 additions & 5,338 deletions deploy/crds/garo.tietoevry.com_githubactionrunners_crd.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ spec:
minRunners: 1
maxRunners: 1
organization: yourOrg
# if runner for repo
# repository: "theRepoName"
tokenRef:
key: GH_TOKEN
name: actions-runner
Expand All @@ -25,6 +27,9 @@ spec:
value: /certs/client
- name: GH_ORG
value: yourOrg
# if runner for repo:
# - name: GH_REPO
# value: theRepoName
envFrom:
- secretRef:
name: actions-runner
Expand Down
104 changes: 56 additions & 48 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pkg/apis/garo/v1alpha1/githubactionrunner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// GithubActionRunnerSpec defines the desired state of GithubActionRunner
type GithubActionRunnerSpec struct {
// kubebuilder:validation:Required
Organization string `json:"organization"`
// kubebuilder:validation:Optional
Repository string `json:"repository,omitempty"`
// +kubebuilder:validation:Minimum=0
MinRunners int `json:"minRunners"`
// +kubebuilder:validation:Minimum=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (r *ReconcileGithubActionRunner) Reconcile(request reconcile.Request) (reco
return reconcile.Result{}, err
}

runners, err := r.githubApi.GetOrgRunners(instance.Spec.Organization, token)
runners, err := r.githubApi.GetRunners(instance.Spec.Organization, instance.Spec.Repository, token)

if err != nil {
reqLogger.Error(err, "error from github api")
Expand Down
14 changes: 11 additions & 3 deletions pkg/githubapi/runnerapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type IRunnerApi interface {
GetOrgRunners(organization string, token string) ([]*github.Runner, error)
GetRunners(organization string, repository string, token string) ([]*github.Runner, error)
}

type RunnerApi struct {
Expand All @@ -19,7 +19,7 @@ func NewRunnerApi() RunnerApi {
}

// Return all runners for the org
func (r RunnerApi) GetOrgRunners(organization string, token string) ([]*github.Runner, error) {
func (r RunnerApi) GetRunners(organization string, repository string, token string) ([]*github.Runner, error) {
ts := oauth2.StaticTokenSource(&(oauth2.Token{
AccessToken: token,
}))
Expand All @@ -30,7 +30,15 @@ func (r RunnerApi) GetOrgRunners(organization string, token string) ([]*github.R
opts := &github.ListOptions{PerPage: 30}

for {
runners, response, err := client.Actions.ListOrganizationRunners(context.TODO(), organization, opts)
var runners *github.Runners
var response *github.Response
var err error

if repository != "" {
runners, response, err = client.Actions.ListRunners(context.TODO(), organization, repository, opts)
} else {
runners, response, err = client.Actions.ListOrganizationRunners(context.TODO(), organization, opts)
}
if err != nil {
return allRunners, err
}
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package version

var (
Version = "0.1.6"
Version = "0.2.0"
)

0 comments on commit cbcd59d

Please sign in to comment.