Implement runner controller

This commit is contained in:
Moto Ishizawa
2020-01-28 21:58:01 +09:00
parent cea4d084e4
commit aaf6b0bcae
7 changed files with 253 additions and 15 deletions

29
main.go
View File

@@ -17,11 +17,15 @@ limitations under the License.
package main
import (
"context"
"errors"
"flag"
"os"
"github.com/google/go-github/v29/github"
actionsv1alpha1 "github.com/summerwind/actions-runner-controller/api/v1alpha1"
"github.com/summerwind/actions-runner-controller/controllers"
"golang.org/x/oauth2"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
@@ -50,6 +54,18 @@ func main() {
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.Parse()
ghToken := os.Getenv("GITHUB_TOKEN")
if ghToken == "" {
err := errors.New("github token is not specified")
setupLog.Error(err, "environment variable 'GITHUB_TOKEN' must be set")
os.Exit(1)
}
tc := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ghToken},
))
ghClient := github.NewClient(tc)
ctrl.SetLogger(zap.New(func(o *zap.Options) {
o.Development = true
}))
@@ -65,11 +81,14 @@ func main() {
os.Exit(1)
}
if err = (&controllers.RunnerReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Runner"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
runnerReconciler := &controllers.RunnerReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Runner"),
Scheme: mgr.GetScheme(),
GitHubClient: ghClient,
}
if err = runnerReconciler.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Runner")
os.Exit(1)
}