mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-12 12:36:55 +00:00
@@ -9,14 +9,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bradleyfalzon/ghinstallation"
|
"github.com/bradleyfalzon/ghinstallation"
|
||||||
"github.com/go-logr/logr"
|
|
||||||
"github.com/google/go-github/v32/github"
|
"github.com/google/go-github/v32/github"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config contains configuration for Github client
|
// Config contains configuration for Github client
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Log logr.Logger
|
|
||||||
EnterpriseURL string `split_words:"true"`
|
EnterpriseURL string `split_words:"true"`
|
||||||
AppID int64 `split_words:"true"`
|
AppID int64 `split_words:"true"`
|
||||||
AppInstallationID int64 `split_words:"true"`
|
AppInstallationID int64 `split_words:"true"`
|
||||||
@@ -46,7 +44,6 @@ func (c *Config) NewClient() (*Client, error) {
|
|||||||
} else {
|
} else {
|
||||||
tr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, c.AppID, c.AppInstallationID, c.AppPrivateKey)
|
tr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, c.AppID, c.AppInstallationID, c.AppPrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err, "Authentication failed")
|
|
||||||
return nil, fmt.Errorf("authentication failed: %v", err)
|
return nil, fmt.Errorf("authentication failed: %v", err)
|
||||||
}
|
}
|
||||||
httpClient = &http.Client{Transport: tr}
|
httpClient = &http.Client{Transport: tr}
|
||||||
@@ -56,7 +53,6 @@ func (c *Config) NewClient() (*Client, error) {
|
|||||||
var err error
|
var err error
|
||||||
client, err = github.NewEnterpriseClient(c.EnterpriseURL, c.EnterpriseURL, httpClient)
|
client, err = github.NewEnterpriseClient(c.EnterpriseURL, c.EnterpriseURL, httpClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err, "Enterprise client creation failed")
|
|
||||||
return nil, fmt.Errorf("enterprise client creation failed: %v", err)
|
return nil, fmt.Errorf("enterprise client creation failed: %v", err)
|
||||||
}
|
}
|
||||||
githubBaseURL = fmt.Sprintf("%s://%s%s", client.BaseURL.Scheme, client.BaseURL.Host, strings.TrimSuffix(client.BaseURL.Path, "api/v3/"))
|
githubBaseURL = fmt.Sprintf("%s://%s%s", client.BaseURL.Scheme, client.BaseURL.Host, strings.TrimSuffix(client.BaseURL.Path, "api/v3/"))
|
||||||
|
|||||||
8
main.go
8
main.go
@@ -82,15 +82,17 @@ func main() {
|
|||||||
flag.DurationVar(&syncPeriod, "sync-period", 10*time.Minute, "Determines the minimum frequency at which K8s resources managed by this controller are reconciled. When you use autoscaling, set to a lower value like 10 minute, because this corresponds to the minimum time to react on demand change")
|
flag.DurationVar(&syncPeriod, "sync-period", 10*time.Minute, "Determines the minimum frequency at which K8s resources managed by this controller are reconciled. When you use autoscaling, set to a lower value like 10 minute, because this corresponds to the minimum time to react on demand change")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
logger := zap.New(func(o *zap.Options) {
|
||||||
|
o.Development = true
|
||||||
|
})
|
||||||
|
|
||||||
ghClient, err = c.NewClient()
|
ghClient, err = c.NewClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "Error: Client creation failed.", err)
|
fmt.Fprintln(os.Stderr, "Error: Client creation failed.", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrl.SetLogger(zap.New(func(o *zap.Options) {
|
ctrl.SetLogger(logger)
|
||||||
o.Development = true
|
|
||||||
}))
|
|
||||||
|
|
||||||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
|
|||||||
Reference in New Issue
Block a user