mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 03:13:15 +00:00
Compare commits
4 Commits
gha-runner
...
rentziass/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5acb44ae0 | ||
|
|
8243fa121c | ||
|
|
93b6e7fa31 | ||
|
|
065655be7e |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
69
controllers/actions.github.com/controllers_test.go
Normal file
69
controllers/actions.github.com/controllers_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package actionsgithubcom
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
actionsv1alpha1 "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *rest.Config
|
||||
k8sClient client.Client
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
logf.SetLogger(zap.New(zap.UseDevMode(true), zap.WriteTo(io.Discard)))
|
||||
|
||||
testEnv := &envtest.Environment{
|
||||
CRDDirectoryPaths: []string{filepath.Join("../..", "config", "crd", "bases")},
|
||||
}
|
||||
|
||||
// Avoids the following error:
|
||||
// 2021-03-19T15:14:11.673+0900 ERROR controller-runtime.controller
|
||||
// Reconciler error {"controller": "testns-tvjzjrunner", "request":
|
||||
// "testns-gdnyx/example-runnerdeploy-zps4z-j5562", "error": "Pod
|
||||
// \"example-runnerdeploy-zps4z-j5562\" is invalid:
|
||||
// [spec.containers[1].image: Required value,
|
||||
// spec.containers[1].securityContext.privileged: Forbidden: disallowed by
|
||||
// cluster policy]"}
|
||||
testEnv.ControlPlane.GetAPIServer().Configure().
|
||||
Append("allow-privileged", "true")
|
||||
|
||||
var err error
|
||||
cfg, err = testEnv.Start()
|
||||
if err != nil || cfg == nil {
|
||||
log.Fatalln(err, "failed to start test environment")
|
||||
}
|
||||
|
||||
err = actionsv1alpha1.AddToScheme(scheme.Scheme)
|
||||
if err != nil {
|
||||
log.Fatalln(err, "failed to add scheme")
|
||||
}
|
||||
|
||||
// +kubebuilder:scaffold:scheme
|
||||
|
||||
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
||||
if err != nil || k8sClient == nil {
|
||||
log.Fatalln(err, "failed to create client")
|
||||
}
|
||||
|
||||
// run the tests
|
||||
code := m.Run()
|
||||
|
||||
err = testEnv.Stop()
|
||||
if err != nil {
|
||||
log.Fatalln(err, "failed to stop test environment")
|
||||
}
|
||||
|
||||
os.Exit(code)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,18 +3,46 @@ package actionsgithubcom
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sync/errgroup"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/manager"
|
||||
)
|
||||
|
||||
const defaultGitHubToken = "gh_token"
|
||||
|
||||
func newAutoscalingRunnerSet(namespace, secretName string) *v1alpha1.AutoscalingRunnerSet {
|
||||
min := 1
|
||||
max := 10
|
||||
return &v1alpha1.AutoscalingRunnerSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-asrs",
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: v1alpha1.AutoscalingRunnerSetSpec{
|
||||
GitHubConfigUrl: "https://github.com/owner/repo",
|
||||
GitHubConfigSecret: secretName,
|
||||
MaxRunners: &max,
|
||||
MinRunners: &min,
|
||||
RunnerGroup: "testgroup",
|
||||
Template: corev1.PodTemplateSpec{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Name: "runner",
|
||||
Image: "ghcr.io/actions/runner",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func startManagers(t ginkgo.GinkgoTInterface, first manager.Manager, others ...manager.Manager) {
|
||||
for _, mgr := range append([]manager.Manager{first}, others...) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -31,7 +59,7 @@ func startManagers(t ginkgo.GinkgoTInterface, first manager.Manager, others ...m
|
||||
}
|
||||
}
|
||||
|
||||
func createNamespace(t ginkgo.GinkgoTInterface, client client.Client) (*corev1.Namespace, manager.Manager) {
|
||||
func createNamespace(t ginkgo.GinkgoTInterface) (*corev1.Namespace, manager.Manager) {
|
||||
ns := &corev1.Namespace{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "testns-autoscaling" + RandStringRunes(5)},
|
||||
}
|
||||
@@ -53,7 +81,7 @@ func createNamespace(t ginkgo.GinkgoTInterface, client client.Client) (*corev1.N
|
||||
return ns, mgr
|
||||
}
|
||||
|
||||
func createDefaultSecret(t ginkgo.GinkgoTInterface, client client.Client, namespace string) *corev1.Secret {
|
||||
func createDefaultSecret(t ginkgo.GinkgoTInterface, namespace string) *corev1.Secret {
|
||||
secret := &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "github-config-secret",
|
||||
|
||||
@@ -16,73 +16,73 @@ limitations under the License.
|
||||
|
||||
package actionsgithubcom
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/onsi/ginkgo/config"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
actionsv1alpha1 "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||
// +kubebuilder:scaffold:imports
|
||||
)
|
||||
|
||||
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
||||
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
||||
|
||||
var (
|
||||
cfg *rest.Config
|
||||
k8sClient client.Client
|
||||
testEnv *envtest.Environment
|
||||
)
|
||||
|
||||
func TestAPIs(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
|
||||
config.GinkgoConfig.FocusStrings = append(config.GinkgoConfig.FocusStrings, os.Getenv("GINKGO_FOCUS"))
|
||||
|
||||
RunSpecs(t, "Controller Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
logf.SetLogger(zap.New(zap.UseDevMode(true), zap.WriteTo(GinkgoWriter)))
|
||||
|
||||
By("bootstrapping test environment")
|
||||
testEnv = &envtest.Environment{
|
||||
CRDDirectoryPaths: []string{filepath.Join("../..", "config", "crd", "bases")},
|
||||
}
|
||||
|
||||
// Avoids the following error:
|
||||
// 2021-03-19T15:14:11.673+0900 ERROR controller-runtime.controller Reconciler error {"controller": "testns-tvjzjrunner", "request": "testns-gdnyx/example-runnerdeploy-zps4z-j5562", "error": "Pod \"example-runnerdeploy-zps4z-j5562\" is invalid: [spec.containers[1].image: Required value, spec.containers[1].securityContext.privileged: Forbidden: disallowed by cluster policy]"}
|
||||
testEnv.ControlPlane.GetAPIServer().Configure().
|
||||
Append("allow-privileged", "true")
|
||||
|
||||
var err error
|
||||
cfg, err = testEnv.Start()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(cfg).ToNot(BeNil())
|
||||
|
||||
err = actionsv1alpha1.AddToScheme(scheme.Scheme)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// +kubebuilder:scaffold:scheme
|
||||
|
||||
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(k8sClient).ToNot(BeNil())
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
By("tearing down the test environment")
|
||||
err := testEnv.Stop()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
// import (
|
||||
// "os"
|
||||
// "path/filepath"
|
||||
// "testing"
|
||||
//
|
||||
// "github.com/onsi/ginkgo/config"
|
||||
//
|
||||
// . "github.com/onsi/ginkgo/v2"
|
||||
// . "github.com/onsi/gomega"
|
||||
//
|
||||
// actionsv1alpha1 "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
|
||||
// "k8s.io/client-go/kubernetes/scheme"
|
||||
// "k8s.io/client-go/rest"
|
||||
// "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
// "sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||
// logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
// "sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||
// // +kubebuilder:scaffold:imports
|
||||
// )
|
||||
//
|
||||
// // These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
||||
// // http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
||||
//
|
||||
// var (
|
||||
// cfg *rest.Config
|
||||
// k8sClient client.Client
|
||||
// testEnv *envtest.Environment
|
||||
// )
|
||||
//
|
||||
// func TestAPIs(t *testing.T) {
|
||||
// RegisterFailHandler(Fail)
|
||||
//
|
||||
// config.GinkgoConfig.FocusStrings = append(config.GinkgoConfig.FocusStrings, os.Getenv("GINKGO_FOCUS"))
|
||||
//
|
||||
// RunSpecs(t, "Controller Suite")
|
||||
// }
|
||||
//
|
||||
// var _ = BeforeSuite(func() {
|
||||
// logf.SetLogger(zap.New(zap.UseDevMode(true), zap.WriteTo(GinkgoWriter)))
|
||||
//
|
||||
// By("bootstrapping test environment")
|
||||
// testEnv = &envtest.Environment{
|
||||
// CRDDirectoryPaths: []string{filepath.Join("../..", "config", "crd", "bases")},
|
||||
// }
|
||||
//
|
||||
// // Avoids the following error:
|
||||
// // 2021-03-19T15:14:11.673+0900 ERROR controller-runtime.controller Reconciler error {"controller": "testns-tvjzjrunner", "request": "testns-gdnyx/example-runnerdeploy-zps4z-j5562", "error": "Pod \"example-runnerdeploy-zps4z-j5562\" is invalid: [spec.containers[1].image: Required value, spec.containers[1].securityContext.privileged: Forbidden: disallowed by cluster policy]"}
|
||||
// testEnv.ControlPlane.GetAPIServer().Configure().
|
||||
// Append("allow-privileged", "true")
|
||||
//
|
||||
// var err error
|
||||
// cfg, err = testEnv.Start()
|
||||
// Expect(err).ToNot(HaveOccurred())
|
||||
// Expect(cfg).ToNot(BeNil())
|
||||
//
|
||||
// err = actionsv1alpha1.AddToScheme(scheme.Scheme)
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
//
|
||||
// // +kubebuilder:scaffold:scheme
|
||||
//
|
||||
// k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
||||
// Expect(err).ToNot(HaveOccurred())
|
||||
// Expect(k8sClient).ToNot(BeNil())
|
||||
// })
|
||||
//
|
||||
// var _ = AfterSuite(func() {
|
||||
// By("tearing down the test environment")
|
||||
// err := testEnv.Stop()
|
||||
// Expect(err).ToNot(HaveOccurred())
|
||||
// })
|
||||
|
||||
1
go.mod
1
go.mod
@@ -22,6 +22,7 @@ require (
|
||||
github.com/onsi/gomega v1.27.2
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.14.0
|
||||
github.com/rentziass/eventually v0.2.0
|
||||
github.com/stretchr/testify v1.8.2
|
||||
github.com/teambition/rrule-go v1.8.2
|
||||
go.uber.org/multierr v1.7.0
|
||||
|
||||
2
go.sum
2
go.sum
@@ -333,6 +333,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
|
||||
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
|
||||
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
|
||||
github.com/rentziass/eventually v0.2.0 h1:zC6GB2nRRlARqfngNGUmdKG5Z6cOwyc0BwleF8kcZHY=
|
||||
github.com/rentziass/eventually v0.2.0/go.mod h1:jiSDJFv0sra6DK66duTH5V4kCfqd9OvmFtflPOExNVI=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
|
||||
Reference in New Issue
Block a user