mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-12 04:26:51 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35caf436d4 | ||
|
|
a136714723 | ||
|
|
fde8df608b | ||
|
|
4733edc20d | ||
|
|
3818e584ec | ||
|
|
50487bbb54 | ||
|
|
e2164f9946 | ||
|
|
bdc1279e9e | ||
|
|
3223480bc0 | ||
|
|
e642632a50 | ||
|
|
3c3077a11c |
@@ -5,6 +5,7 @@ resources:
|
|||||||
- bases/actions.summerwind.dev_runners.yaml
|
- bases/actions.summerwind.dev_runners.yaml
|
||||||
- bases/actions.summerwind.dev_runnerreplicasets.yaml
|
- bases/actions.summerwind.dev_runnerreplicasets.yaml
|
||||||
- bases/actions.summerwind.dev_runnerdeployments.yaml
|
- bases/actions.summerwind.dev_runnerdeployments.yaml
|
||||||
|
- bases/actions.summerwind.dev_horizontalrunnerautoscalers.yaml
|
||||||
# +kubebuilder:scaffold:crdkustomizeresource
|
# +kubebuilder:scaffold:crdkustomizeresource
|
||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
|
|||||||
@@ -128,27 +128,10 @@ func (r *HorizontalRunnerAutoscalerReconciler) Reconcile(req ctrl.Request) (ctrl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *HorizontalRunnerAutoscalerReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *HorizontalRunnerAutoscalerReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
r.Recorder = mgr.GetEventRecorderFor("runnerdeployment-controller")
|
r.Recorder = mgr.GetEventRecorderFor("horizontalrunnerautoscaler-controller")
|
||||||
|
|
||||||
if err := mgr.GetFieldIndexer().IndexField(&v1alpha1.RunnerReplicaSet{}, runnerSetOwnerKey, func(rawObj runtime.Object) []string {
|
|
||||||
runnerSet := rawObj.(*v1alpha1.RunnerReplicaSet)
|
|
||||||
owner := metav1.GetControllerOf(runnerSet)
|
|
||||||
if owner == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if owner.APIVersion != v1alpha1.GroupVersion.String() || owner.Kind != "RunnerDeployment" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return []string{owner.Name}
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&v1alpha1.RunnerDeployment{}).
|
For(&v1alpha1.HorizontalRunnerAutoscaler{}).
|
||||||
Owns(&v1alpha1.RunnerReplicaSet{}).
|
|
||||||
Complete(r)
|
Complete(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
308
controllers/integration_test.go
Normal file
308
controllers/integration_test.go
Normal file
@@ -0,0 +1,308 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/summerwind/actions-runner-controller/github/fake"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
actionsv1alpha1 "github.com/summerwind/actions-runner-controller/api/v1alpha1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testEnvironment struct {
|
||||||
|
Namespace *corev1.Namespace
|
||||||
|
Responses *fake.FixedResponses
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
workflowRunsFor3Replicas = `{"total_count": 5, "workflow_runs":[{"status":"queued"}, {"status":"queued"}, {"status":"in_progress"}, {"status":"in_progress"}, {"status":"completed"}]}"`
|
||||||
|
workflowRunsFor1Replicas = `{"total_count": 6, "workflow_runs":[{"status":"queued"}, {"status":"completed"}, {"status":"completed"}, {"status":"completed"}, {"status":"completed"}]}"`
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetupIntegrationTest will set up a testing environment.
|
||||||
|
// This includes:
|
||||||
|
// * creating a Namespace to be used during the test
|
||||||
|
// * starting all the reconcilers
|
||||||
|
// * stopping all the reconcilers after the test ends
|
||||||
|
// Call this function at the start of each of your tests.
|
||||||
|
func SetupIntegrationTest(ctx context.Context) *testEnvironment {
|
||||||
|
var stopCh chan struct{}
|
||||||
|
ns := &corev1.Namespace{}
|
||||||
|
|
||||||
|
responses := &fake.FixedResponses{}
|
||||||
|
responses.ListRepositoryWorkflowRuns = &fake.Handler{
|
||||||
|
Status: 200,
|
||||||
|
Body: workflowRunsFor3Replicas,
|
||||||
|
}
|
||||||
|
server := fake.NewServer(fake.WithFixedResponses(responses))
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
stopCh = make(chan struct{})
|
||||||
|
*ns = corev1.Namespace{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "testns-" + randStringRunes(5)},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := k8sClient.Create(ctx, ns)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to create test namespace")
|
||||||
|
|
||||||
|
mgr, err := ctrl.NewManager(cfg, ctrl.Options{})
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to create manager")
|
||||||
|
|
||||||
|
replicasetController := &RunnerReplicaSetReconciler{
|
||||||
|
Client: mgr.GetClient(),
|
||||||
|
Scheme: scheme.Scheme,
|
||||||
|
Log: logf.Log,
|
||||||
|
Recorder: mgr.GetEventRecorderFor("runnerreplicaset-controller"),
|
||||||
|
}
|
||||||
|
err = replicasetController.SetupWithManager(mgr)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to setup controller")
|
||||||
|
|
||||||
|
deploymentsController := &RunnerDeploymentReconciler{
|
||||||
|
Client: mgr.GetClient(),
|
||||||
|
Scheme: scheme.Scheme,
|
||||||
|
Log: logf.Log,
|
||||||
|
Recorder: mgr.GetEventRecorderFor("runnerdeployment-controller"),
|
||||||
|
}
|
||||||
|
err = deploymentsController.SetupWithManager(mgr)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to setup controller")
|
||||||
|
|
||||||
|
client := newGithubClient(server)
|
||||||
|
|
||||||
|
autoscalerController := &HorizontalRunnerAutoscalerReconciler{
|
||||||
|
Client: mgr.GetClient(),
|
||||||
|
Scheme: scheme.Scheme,
|
||||||
|
Log: logf.Log,
|
||||||
|
GitHubClient: client,
|
||||||
|
Recorder: mgr.GetEventRecorderFor("horizontalrunnerautoscaler-controller"),
|
||||||
|
}
|
||||||
|
err = autoscalerController.SetupWithManager(mgr)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to setup controller")
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer GinkgoRecover()
|
||||||
|
|
||||||
|
err := mgr.Start(stopCh)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to start manager")
|
||||||
|
}()
|
||||||
|
})
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
close(stopCh)
|
||||||
|
|
||||||
|
server.Close()
|
||||||
|
|
||||||
|
err := k8sClient.Delete(ctx, ns)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to delete test namespace")
|
||||||
|
})
|
||||||
|
|
||||||
|
return &testEnvironment{Namespace: ns, Responses: responses}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Context("Inside of a new namespace", func() {
|
||||||
|
ctx := context.TODO()
|
||||||
|
env := SetupIntegrationTest(ctx)
|
||||||
|
ns := env.Namespace
|
||||||
|
responses := env.Responses
|
||||||
|
|
||||||
|
Describe("when no existing resources exist", func() {
|
||||||
|
|
||||||
|
It("should create and scale runners", func() {
|
||||||
|
name := "example-runnerdeploy"
|
||||||
|
|
||||||
|
{
|
||||||
|
rs := &actionsv1alpha1.RunnerDeployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerDeploymentSpec{
|
||||||
|
Replicas: intPtr(1),
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
Repository: "test/valid",
|
||||||
|
Image: "bar",
|
||||||
|
Env: []corev1.EnvVar{
|
||||||
|
{Name: "FOO", Value: "FOOVALUE"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := k8sClient.Create(ctx, rs)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to create test RunnerDeployment resource")
|
||||||
|
|
||||||
|
runnerSets := actionsv1alpha1.RunnerReplicaSetList{Items: []actionsv1alpha1.RunnerReplicaSet{}}
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
func() int {
|
||||||
|
err := k8sClient.List(ctx, &runnerSets, client.InNamespace(ns.Name))
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runner sets")
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(runnerSets.Items)
|
||||||
|
},
|
||||||
|
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(1))
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
func() int {
|
||||||
|
err := k8sClient.List(ctx, &runnerSets, client.InNamespace(ns.Name))
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runner sets")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(runnerSets.Items) == 0 {
|
||||||
|
logf.Log.Info("No runnerreplicasets exist yet")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return *runnerSets.Items[0].Spec.Replicas
|
||||||
|
},
|
||||||
|
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// We wrap the update in the Eventually block to avoid the below error that occurs due to concurrent modification
|
||||||
|
// made by the controller to update .Status.AvailableReplicas and .Status.ReadyReplicas
|
||||||
|
// Operation cannot be fulfilled on runnersets.actions.summerwind.dev "example-runnerset": the object has been modified; please apply your changes to the latest version and try again
|
||||||
|
Eventually(func() error {
|
||||||
|
var rd actionsv1alpha1.RunnerDeployment
|
||||||
|
|
||||||
|
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rd)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerDeployment resource")
|
||||||
|
|
||||||
|
rd.Spec.Replicas = intPtr(2)
|
||||||
|
|
||||||
|
return k8sClient.Update(ctx, &rd)
|
||||||
|
},
|
||||||
|
time.Second*1, time.Millisecond*500).Should(BeNil())
|
||||||
|
|
||||||
|
runnerSets := actionsv1alpha1.RunnerReplicaSetList{Items: []actionsv1alpha1.RunnerReplicaSet{}}
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
func() int {
|
||||||
|
err := k8sClient.List(ctx, &runnerSets, client.InNamespace(ns.Name))
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runner sets")
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(runnerSets.Items)
|
||||||
|
},
|
||||||
|
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(1))
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
func() int {
|
||||||
|
err := k8sClient.List(ctx, &runnerSets, client.InNamespace(ns.Name))
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runner sets")
|
||||||
|
}
|
||||||
|
|
||||||
|
return *runnerSets.Items[0].Spec.Replicas
|
||||||
|
},
|
||||||
|
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(2))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale-up to 3 replicas
|
||||||
|
{
|
||||||
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
|
Name: name,
|
||||||
|
},
|
||||||
|
MinReplicas: intPtr(1),
|
||||||
|
MaxReplicas: intPtr(3),
|
||||||
|
ScaleDownDelaySecondsAfterScaleUp: nil,
|
||||||
|
Metrics: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := k8sClient.Create(ctx, hra)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to create test HorizontalRunnerAutoscaler resource")
|
||||||
|
|
||||||
|
runnerSets := actionsv1alpha1.RunnerReplicaSetList{Items: []actionsv1alpha1.RunnerReplicaSet{}}
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
func() int {
|
||||||
|
err := k8sClient.List(ctx, &runnerSets, client.InNamespace(ns.Name))
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runner sets")
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(runnerSets.Items)
|
||||||
|
},
|
||||||
|
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(1))
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
func() int {
|
||||||
|
err := k8sClient.List(ctx, &runnerSets, client.InNamespace(ns.Name))
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runner sets")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(runnerSets.Items) == 0 {
|
||||||
|
logf.Log.Info("No runnerreplicasets exist yet")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return *runnerSets.Items[0].Spec.Replicas
|
||||||
|
},
|
||||||
|
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(3))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale-down to 1 replica
|
||||||
|
{
|
||||||
|
responses.ListRepositoryWorkflowRuns.Body = workflowRunsFor1Replicas
|
||||||
|
|
||||||
|
var hra actionsv1alpha1.HorizontalRunnerAutoscaler
|
||||||
|
|
||||||
|
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &hra)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to get test HorizontalRunnerAutoscaler resource")
|
||||||
|
|
||||||
|
hra.Annotations = map[string]string{
|
||||||
|
"force-update": "1",
|
||||||
|
}
|
||||||
|
|
||||||
|
err = k8sClient.Update(ctx, &hra)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to get test HorizontalRunnerAutoscaler resource")
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
func() int {
|
||||||
|
var runnerSets actionsv1alpha1.RunnerReplicaSetList
|
||||||
|
|
||||||
|
err := k8sClient.List(ctx, &runnerSets, client.InNamespace(ns.Name))
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runner sets")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(runnerSets.Items) == 0 {
|
||||||
|
logf.Log.Info("No runnerreplicasets exist yet")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return *runnerSets.Items[0].Spec.Replicas
|
||||||
|
},
|
||||||
|
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(1))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -21,111 +21,116 @@ const (
|
|||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
type handler struct {
|
type Handler struct {
|
||||||
Status int
|
Status int
|
||||||
Body string
|
Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
w.WriteHeader(h.Status)
|
w.WriteHeader(h.Status)
|
||||||
fmt.Fprintf(w, h.Body)
|
fmt.Fprintf(w, h.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a fake server for running unit tests
|
type ServerConfig struct {
|
||||||
func NewServer(opts ...Option) *httptest.Server {
|
*FixedResponses
|
||||||
var responses FixedResponses
|
|
||||||
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&responses)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
routes := map[string]handler{
|
// NewServer creates a fake server for running unit tests
|
||||||
|
func NewServer(opts ...Option) *httptest.Server {
|
||||||
|
config := ServerConfig{
|
||||||
|
FixedResponses: &FixedResponses{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&config)
|
||||||
|
}
|
||||||
|
|
||||||
|
routes := map[string]*Handler{
|
||||||
// For CreateRegistrationToken
|
// For CreateRegistrationToken
|
||||||
"/repos/test/valid/actions/runners/registration-token": handler{
|
"/repos/test/valid/actions/runners/registration-token": &Handler{
|
||||||
Status: http.StatusCreated,
|
Status: http.StatusCreated,
|
||||||
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
||||||
},
|
},
|
||||||
"/repos/test/invalid/actions/runners/registration-token": handler{
|
"/repos/test/invalid/actions/runners/registration-token": &Handler{
|
||||||
Status: http.StatusOK,
|
Status: http.StatusOK,
|
||||||
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
||||||
},
|
},
|
||||||
"/repos/test/error/actions/runners/registration-token": handler{
|
"/repos/test/error/actions/runners/registration-token": &Handler{
|
||||||
Status: http.StatusBadRequest,
|
Status: http.StatusBadRequest,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/orgs/test/actions/runners/registration-token": handler{
|
"/orgs/test/actions/runners/registration-token": &Handler{
|
||||||
Status: http.StatusCreated,
|
Status: http.StatusCreated,
|
||||||
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
||||||
},
|
},
|
||||||
"/orgs/invalid/actions/runners/registration-token": handler{
|
"/orgs/invalid/actions/runners/registration-token": &Handler{
|
||||||
Status: http.StatusOK,
|
Status: http.StatusOK,
|
||||||
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
|
||||||
},
|
},
|
||||||
"/orgs/error/actions/runners/registration-token": handler{
|
"/orgs/error/actions/runners/registration-token": &Handler{
|
||||||
Status: http.StatusBadRequest,
|
Status: http.StatusBadRequest,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
|
|
||||||
// For ListRunners
|
// For ListRunners
|
||||||
"/repos/test/valid/actions/runners": handler{
|
"/repos/test/valid/actions/runners": &Handler{
|
||||||
Status: http.StatusOK,
|
Status: http.StatusOK,
|
||||||
Body: RunnersListBody,
|
Body: RunnersListBody,
|
||||||
},
|
},
|
||||||
"/repos/test/invalid/actions/runners": handler{
|
"/repos/test/invalid/actions/runners": &Handler{
|
||||||
Status: http.StatusNoContent,
|
Status: http.StatusNoContent,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/repos/test/error/actions/runners": handler{
|
"/repos/test/error/actions/runners": &Handler{
|
||||||
Status: http.StatusBadRequest,
|
Status: http.StatusBadRequest,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/orgs/test/actions/runners": handler{
|
"/orgs/test/actions/runners": &Handler{
|
||||||
Status: http.StatusOK,
|
Status: http.StatusOK,
|
||||||
Body: RunnersListBody,
|
Body: RunnersListBody,
|
||||||
},
|
},
|
||||||
"/orgs/invalid/actions/runners": handler{
|
"/orgs/invalid/actions/runners": &Handler{
|
||||||
Status: http.StatusNoContent,
|
Status: http.StatusNoContent,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/orgs/error/actions/runners": handler{
|
"/orgs/error/actions/runners": &Handler{
|
||||||
Status: http.StatusBadRequest,
|
Status: http.StatusBadRequest,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
|
|
||||||
// For RemoveRunner
|
// For RemoveRunner
|
||||||
"/repos/test/valid/actions/runners/1": handler{
|
"/repos/test/valid/actions/runners/1": &Handler{
|
||||||
Status: http.StatusNoContent,
|
Status: http.StatusNoContent,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/repos/test/invalid/actions/runners/1": handler{
|
"/repos/test/invalid/actions/runners/1": &Handler{
|
||||||
Status: http.StatusOK,
|
Status: http.StatusOK,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/repos/test/error/actions/runners/1": handler{
|
"/repos/test/error/actions/runners/1": &Handler{
|
||||||
Status: http.StatusBadRequest,
|
Status: http.StatusBadRequest,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/orgs/test/actions/runners/1": handler{
|
"/orgs/test/actions/runners/1": &Handler{
|
||||||
Status: http.StatusNoContent,
|
Status: http.StatusNoContent,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/orgs/invalid/actions/runners/1": handler{
|
"/orgs/invalid/actions/runners/1": &Handler{
|
||||||
Status: http.StatusOK,
|
Status: http.StatusOK,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
"/orgs/error/actions/runners/1": handler{
|
"/orgs/error/actions/runners/1": &Handler{
|
||||||
Status: http.StatusBadRequest,
|
Status: http.StatusBadRequest,
|
||||||
Body: "",
|
Body: "",
|
||||||
},
|
},
|
||||||
|
|
||||||
// For auto-scaling based on the number of queued(pending) workflow runs
|
// For auto-scaling based on the number of queued(pending) workflow runs
|
||||||
"/repos/test/valid/actions/runs": responses.listRepositoryWorkflowRuns.handler(),
|
"/repos/test/valid/actions/runs": config.FixedResponses.ListRepositoryWorkflowRuns,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
for path, handler := range routes {
|
for path, handler := range routes {
|
||||||
h := handler
|
mux.Handle(path, handler)
|
||||||
mux.Handle(path, &h)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return httptest.NewServer(mux)
|
return httptest.NewServer(mux)
|
||||||
|
|||||||
@@ -1,28 +1,22 @@
|
|||||||
package fake
|
package fake
|
||||||
|
|
||||||
type FixedResponses struct {
|
type FixedResponses struct {
|
||||||
listRepositoryWorkflowRuns FixedResponse
|
ListRepositoryWorkflowRuns *Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
type FixedResponse struct {
|
type Option func(*ServerConfig)
|
||||||
Status int
|
|
||||||
Body string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r FixedResponse) handler() handler {
|
|
||||||
return handler{
|
|
||||||
Status: r.Status,
|
|
||||||
Body: r.Body,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Option func(responses *FixedResponses)
|
|
||||||
|
|
||||||
func WithListRepositoryWorkflowRunsResponse(status int, body string) Option {
|
func WithListRepositoryWorkflowRunsResponse(status int, body string) Option {
|
||||||
return func(r *FixedResponses) {
|
return func(c *ServerConfig) {
|
||||||
r.listRepositoryWorkflowRuns = FixedResponse{
|
c.FixedResponses.ListRepositoryWorkflowRuns = &Handler{
|
||||||
Status: status,
|
Status: status,
|
||||||
Body: body,
|
Body: body,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithFixedResponses(responses *FixedResponses) Option {
|
||||||
|
return func(c *ServerConfig) {
|
||||||
|
c.FixedResponses = responses
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
NAME ?= summerwind/actions-runner
|
NAME ?= summerwind/actions-runner
|
||||||
|
|
||||||
RUNNER_VERSION ?= 2.267.1
|
RUNNER_VERSION ?= 2.272.0
|
||||||
DOCKER_VERSION ?= 19.03.8
|
DOCKER_VERSION ?= 19.03.12
|
||||||
|
|
||||||
docker-build:
|
docker-build:
|
||||||
docker build --build-arg RUNNER_VERSION=${RUNNER_VERSION} --build-arg DOCKER_VERSION=${DOCKER_VERSION} -t ${NAME}:latest -t ${NAME}:v${RUNNER_VERSION} .
|
docker build --build-arg RUNNER_VERSION=${RUNNER_VERSION} --build-arg DOCKER_VERSION=${DOCKER_VERSION} -t ${NAME}:latest -t ${NAME}:v${RUNNER_VERSION} .
|
||||||
|
|||||||
Reference in New Issue
Block a user