Add cmd line arg for enterprise url. Fix enterprise bug. (#1)
* Add cmd line arg for enterprise url. Fix enterprise bug. * Fix package import order * Fix comment
This commit is contained in:
parent
623c84fa52
commit
921daff61b
|
|
@ -198,9 +198,8 @@ func (c *MultiGitHubClient) initClientForSecret(secret *corev1.Secret, dependent
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if EnterpriseURL is set.
|
// Fallback to the controller-wide setting if EnterpriseURL is not set and the original client is an enterprise client.
|
||||||
if conf.EnterpriseURL == "" {
|
if conf.EnterpriseURL == "" && c.githubClient.IsEnterprise {
|
||||||
// fallback to the controller-wide setting
|
|
||||||
conf.EnterpriseURL = c.githubClient.GithubBaseURL
|
conf.EnterpriseURL = c.githubClient.GithubBaseURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package github
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/build"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -11,6 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/build"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/github/metrics"
|
"github.com/actions-runner-controller/actions-runner-controller/github/metrics"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/logging"
|
"github.com/actions-runner-controller/actions-runner-controller/logging"
|
||||||
"github.com/bradleyfalzon/ghinstallation/v2"
|
"github.com/bradleyfalzon/ghinstallation/v2"
|
||||||
|
|
@ -43,6 +43,7 @@ type Client struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
// GithubBaseURL to Github without API suffix.
|
// GithubBaseURL to Github without API suffix.
|
||||||
GithubBaseURL string
|
GithubBaseURL string
|
||||||
|
IsEnterprise bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasicAuthTransport struct {
|
type BasicAuthTransport struct {
|
||||||
|
|
@ -95,8 +96,10 @@ func (c *Config) NewClient() (*Client, error) {
|
||||||
|
|
||||||
var client *github.Client
|
var client *github.Client
|
||||||
var githubBaseURL string
|
var githubBaseURL string
|
||||||
|
var isEnterprise bool
|
||||||
if len(c.EnterpriseURL) > 0 {
|
if len(c.EnterpriseURL) > 0 {
|
||||||
var err error
|
var err error
|
||||||
|
isEnterprise = true
|
||||||
client, err = github.NewEnterpriseClient(c.EnterpriseURL, c.EnterpriseURL, httpClient)
|
client, err = github.NewEnterpriseClient(c.EnterpriseURL, c.EnterpriseURL, httpClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("enterprise client creation failed: %v", err)
|
return nil, fmt.Errorf("enterprise client creation failed: %v", err)
|
||||||
|
|
@ -136,12 +139,12 @@ func (c *Config) NewClient() (*Client, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.UserAgent = "actions-runner-controller/" + build.Version
|
client.UserAgent = "actions-runner-controller/" + build.Version
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
Client: client,
|
Client: client,
|
||||||
regTokens: map[string]*github.RegistrationToken{},
|
regTokens: map[string]*github.RegistrationToken{},
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
GithubBaseURL: githubBaseURL,
|
GithubBaseURL: githubBaseURL,
|
||||||
|
IsEnterprise: isEnterprise,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
3
main.go
3
main.go
|
|
@ -19,12 +19,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/build"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
actionsv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
actionsv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/build"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/controllers"
|
"github.com/actions-runner-controller/actions-runner-controller/controllers"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/github"
|
"github.com/actions-runner-controller/actions-runner-controller/github"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/logging"
|
"github.com/actions-runner-controller/actions-runner-controller/logging"
|
||||||
|
|
@ -103,6 +103,7 @@ func main() {
|
||||||
flag.Var(&runnerImagePullSecrets, "runner-image-pull-secret", "The default image-pull secret name for self-hosted runner container.")
|
flag.Var(&runnerImagePullSecrets, "runner-image-pull-secret", "The default image-pull secret name for self-hosted runner container.")
|
||||||
flag.StringVar(&dockerRegistryMirror, "docker-registry-mirror", "", "The default Docker Registry Mirror used by runners.")
|
flag.StringVar(&dockerRegistryMirror, "docker-registry-mirror", "", "The default Docker Registry Mirror used by runners.")
|
||||||
flag.StringVar(&c.Token, "github-token", c.Token, "The personal access token of GitHub.")
|
flag.StringVar(&c.Token, "github-token", c.Token, "The personal access token of GitHub.")
|
||||||
|
flag.StringVar(&c.EnterpriseURL, "github-enterprise-url", c.EnterpriseURL, "Enterprise URL to be used for your GitHub API calls")
|
||||||
flag.Int64Var(&c.AppID, "github-app-id", c.AppID, "The application ID of GitHub App.")
|
flag.Int64Var(&c.AppID, "github-app-id", c.AppID, "The application ID of GitHub App.")
|
||||||
flag.Int64Var(&c.AppInstallationID, "github-app-installation-id", c.AppInstallationID, "The installation ID of GitHub App.")
|
flag.Int64Var(&c.AppInstallationID, "github-app-installation-id", c.AppInstallationID, "The installation ID of GitHub App.")
|
||||||
flag.StringVar(&c.AppPrivateKey, "github-app-private-key", c.AppPrivateKey, "The path of a private key file to authenticate as a GitHub App")
|
flag.StringVar(&c.AppPrivateKey, "github-app-private-key", c.AppPrivateKey, "The path of a private key file to authenticate as a GitHub App")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue