Skip to content

Commit dc7c858

Browse files
authored
Remove actions client (#4405)
1 parent 2fc51aa commit dc7c858

31 files changed

+8
-6489
lines changed

.mockery.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ pkgname: "{{.SrcPackageName}}"
99
recursive: false
1010
template: testify
1111
packages:
12-
github.com/actions/actions-runner-controller/github/actions:
13-
config:
14-
inpackage: true
15-
dir: "{{.InterfaceDir}}"
16-
filename: "mocks_test.go"
17-
pkgname: "actions"
18-
interfaces:
19-
ActionsService:
20-
SessionService:
2112
github.com/actions/actions-runner-controller/cmd/ghalistener/metrics:
2213
config:
2314
all: true

apis/actions.github.com/v1alpha1/tls_config_test.go

Lines changed: 0 additions & 105 deletions
This file was deleted.

cmd/ghalistener/config/config_client_test.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,20 @@
11
package config_test
22

33
import (
4-
"context"
5-
"crypto/tls"
64
"encoding/json"
75
"log/slog"
8-
"net/http"
96
"os"
10-
"path/filepath"
117
"testing"
128

139
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1/appconfig"
1410
"github.com/actions/actions-runner-controller/cmd/ghalistener/config"
15-
"github.com/actions/actions-runner-controller/github/actions/testserver"
1611
"github.com/actions/scaleset"
1712
"github.com/stretchr/testify/assert"
1813
"github.com/stretchr/testify/require"
1914
)
2015

2116
var discardLogger = slog.New(slog.DiscardHandler)
2217

23-
func TestCustomerServerRootCA(t *testing.T) {
24-
ctx := context.Background()
25-
certsFolder := filepath.Join(
26-
"../../../",
27-
"github",
28-
"actions",
29-
"testdata",
30-
)
31-
certPath := filepath.Join(certsFolder, "server.crt")
32-
keyPath := filepath.Join(certsFolder, "server.key")
33-
34-
serverCalledSuccessfully := false
35-
36-
server := testserver.NewUnstarted(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
37-
serverCalledSuccessfully = true
38-
w.WriteHeader(http.StatusOK)
39-
w.Write([]byte(`{"count": 0}`))
40-
}))
41-
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
42-
require.NoError(t, err)
43-
44-
server.TLS = &tls.Config{Certificates: []tls.Certificate{cert}}
45-
server.StartTLS()
46-
47-
var certsString string
48-
rootCA, err := os.ReadFile(filepath.Join(certsFolder, "rootCA.crt"))
49-
require.NoError(t, err)
50-
certsString = string(rootCA)
51-
52-
intermediate, err := os.ReadFile(filepath.Join(certsFolder, "intermediate.crt"))
53-
require.NoError(t, err)
54-
certsString = certsString + string(intermediate)
55-
56-
config := config.Config{
57-
ConfigureURL: server.ConfigURLForOrg("myorg"),
58-
ServerRootCA: certsString,
59-
AppConfig: &appconfig.AppConfig{
60-
Token: "token",
61-
},
62-
}
63-
64-
client, err := config.ActionsClient(discardLogger)
65-
require.NoError(t, err)
66-
_, err = client.GetRunnerScaleSet(ctx, 1, "test")
67-
require.NoError(t, err)
68-
assert.True(t, serverCalledSuccessfully)
69-
}
70-
7118
func TestProxySettings(t *testing.T) {
7219
assertHasProxy := func(t *testing.T, debugInfo string, want bool) {
7320
type debugInfoContent struct {

controllers/actions.github.com/ephemeralrunner_controller.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"net/http"
2423
"strconv"
2524
"strings"
2625
"time"
2726

2827
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
29-
"github.com/actions/actions-runner-controller/github/actions"
3028
"github.com/actions/scaleset"
3129
"github.com/go-logr/logr"
3230
corev1 "k8s.io/api/core/v1"
@@ -410,12 +408,8 @@ func (r *EphemeralRunnerReconciler) deleteEphemeralRunnerOrPod(ctx context.Conte
410408

411409
func (r *EphemeralRunnerReconciler) cleanupRunnerFromService(ctx context.Context, ephemeralRunner *v1alpha1.EphemeralRunner, log logr.Logger) (ok bool, err error) {
412410
if err := r.deleteRunnerFromService(ctx, ephemeralRunner, log); err != nil {
413-
actionsError := &actions.ActionsError{}
414-
if !errors.As(err, &actionsError) {
415-
return false, err
416-
}
417-
418-
if actionsError.StatusCode == http.StatusBadRequest && actionsError.IsException("JobStillRunningException") {
411+
if errors.Is(err, scaleset.JobStillRunningError) {
412+
log.Info("Runner job is still running, cannot remove the runner from the service yet")
419413
return false, nil
420414
}
421415

@@ -625,16 +619,10 @@ func (r *EphemeralRunnerReconciler) createRunnerJitConfig(ctx context.Context, e
625619
return jitConfig, nil
626620
}
627621

628-
actionsError := &actions.ActionsError{}
629-
if !errors.As(err, &actionsError) {
622+
if !errors.Is(err, scaleset.RunnerExistsError) {
630623
return nil, fmt.Errorf("failed to generate JIT config with generic error: %w", err)
631624
}
632625

633-
if actionsError.StatusCode != http.StatusConflict ||
634-
!actionsError.IsException("AgentExistsException") {
635-
return nil, fmt.Errorf("failed to generate JIT config with Actions service error: %w", err)
636-
}
637-
638626
// If the runner with the name we want already exists it means:
639627
// - We might have a name collision.
640628
// - Our previous reconciliation loop failed to update the

controllers/actions.github.com/ephemeralrunner_controller_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
16-
"github.com/actions/actions-runner-controller/github/actions"
1716

1817
"github.com/actions/actions-runner-controller/controllers/actions.github.com/multiclient"
1918
scalefake "github.com/actions/actions-runner-controller/controllers/actions.github.com/multiclient/fake"
@@ -1113,12 +1112,7 @@ var _ = Describe("EphemeralRunner", func() {
11131112
scalefake.NewClient(
11141113
scalefake.WithGetRunner(
11151114
nil,
1116-
&actions.ActionsError{
1117-
StatusCode: http.StatusNotFound,
1118-
Err: &actions.ActionsExceptionError{
1119-
ExceptionName: "AgentNotFoundException",
1120-
},
1121-
},
1115+
scaleset.RunnerNotFoundError,
11221116
),
11231117
scalefake.WithGenerateJitRunnerConfig(
11241118
&scaleset.RunnerScaleSetJitRunnerConfig{

controllers/actions.github.com/ephemeralrunnerset_controller.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"net/http"
2423
"sort"
2524
"strconv"
2625

2726
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
2827
"github.com/actions/actions-runner-controller/controllers/actions.github.com/metrics"
2928
"github.com/actions/actions-runner-controller/controllers/actions.github.com/multiclient"
3029
"github.com/actions/actions-runner-controller/github/actions"
30+
"github.com/actions/scaleset"
3131
"github.com/go-logr/logr"
3232
"go.uber.org/multierr"
3333
corev1 "k8s.io/api/core/v1"
@@ -48,9 +48,8 @@ const (
4848
// EphemeralRunnerSetReconciler reconciles a EphemeralRunnerSet object
4949
type EphemeralRunnerSetReconciler struct {
5050
client.Client
51-
Log logr.Logger
52-
Scheme *runtime.Scheme
53-
ActionsClient actions.MultiClient
51+
Log logr.Logger
52+
Scheme *runtime.Scheme
5453

5554
PublishMetrics bool
5655

@@ -484,14 +483,7 @@ func (r *EphemeralRunnerSetReconciler) deleteIdleEphemeralRunners(ctx context.Co
484483

485484
func (r *EphemeralRunnerSetReconciler) deleteEphemeralRunnerWithActionsClient(ctx context.Context, ephemeralRunner *v1alpha1.EphemeralRunner, actionsClient multiclient.Client, log logr.Logger) (bool, error) {
486485
if err := actionsClient.RemoveRunner(ctx, int64(ephemeralRunner.Status.RunnerId)); err != nil {
487-
actionsError := &actions.ActionsError{}
488-
if !errors.As(err, &actionsError) {
489-
log.Error(err, "failed to remove runner from the service", "name", ephemeralRunner.Name, "runnerId", ephemeralRunner.Status.RunnerId)
490-
return false, err
491-
}
492-
493-
if actionsError.StatusCode == http.StatusBadRequest &&
494-
actionsError.IsException("JobStillRunningException") {
486+
if errors.Is(err, scaleset.JobStillRunningError) {
495487
log.Info("Runner is still running a job, skipping deletion", "name", ephemeralRunner.Name, "runnerId", ephemeralRunner.Status.RunnerId)
496488
return false, nil
497489
}

0 commit comments

Comments
 (0)