mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 19:50:30 +00:00
This enhances every ARC controller and the various K8s custom resources so that the user can now configure a custom GitHub API credentials (that is different from the default one configured per the ARC instance). Ref https://github.com/actions-runner-controller/actions-runner-controller/issues/1067#issuecomment-1043716646
32 lines
729 B
Go
32 lines
729 B
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"reflect"
|
|
|
|
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
)
|
|
|
|
type testResourceReader struct {
|
|
objects map[types.NamespacedName]client.Object
|
|
}
|
|
|
|
func (r *testResourceReader) Get(_ context.Context, nsName types.NamespacedName, obj client.Object) error {
|
|
ret, ok := r.objects[nsName]
|
|
if !ok {
|
|
return &kerrors.StatusError{ErrStatus: metav1.Status{Reason: metav1.StatusReasonNotFound}}
|
|
}
|
|
v := reflect.ValueOf(obj)
|
|
if v.Kind() != reflect.Ptr {
|
|
return errors.New("obj must be a pointer")
|
|
}
|
|
|
|
v.Elem().Set(reflect.ValueOf(ret).Elem())
|
|
|
|
return nil
|
|
}
|