diff options
-rw-r--r-- | app.go | 4 | ||||
-rw-r--r-- | internal/config/config.go | 21 | ||||
-rw-r--r-- | internal/config/flags.go | 3 | ||||
-rw-r--r-- | internal/source/disk/disk.go | 56 | ||||
-rw-r--r-- | internal/source/domains.go | 94 |
5 files changed, 19 insertions, 159 deletions
@@ -413,8 +413,6 @@ func (a *theApp) Run() { a.listenMetricsFD(&wg, a.config.ListenMetrics) } - a.domains.Read(a.config.General.Domain) - wg.Wait() } @@ -495,7 +493,7 @@ func (a *theApp) listenMetricsFD(wg *sync.WaitGroup, fd uintptr) { } func runApp(config *cfg.Config) { - domains, err := source.NewDomains(config.General.DomainConfigurationSource, &config.GitLab) + domains, err := source.NewDomains(&config.GitLab) if err != nil { log.WithError(err).Fatal("could not create domains config source") } diff --git a/internal/config/config.go b/internal/config/config.go index 64dc4666..c57eb15d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -45,15 +45,14 @@ type Config struct { // General groups settings that are general to GitLab Pages and can not // be categorized under other head. type General struct { - Domain string - DomainConfigurationSource string - MaxConns int - MetricsAddress string - RedirectHTTP bool - RootCertificate []byte - RootDir string - RootKey []byte - StatusPath string + Domain string + MaxConns int + MetricsAddress string + RedirectHTTP bool + RootCertificate []byte + RootDir string + RootKey []byte + StatusPath string DisableCrossOriginRequests bool InsecureCiphers bool @@ -187,7 +186,6 @@ func loadConfig() (*Config, error) { config := &Config{ General: General{ Domain: strings.ToLower(*pagesDomain), - DomainConfigurationSource: *domainConfigSource, MaxConns: *maxConns, MetricsAddress: *metricsAddress, RedirectHTTP: *redirectHTTP, @@ -227,7 +225,7 @@ func loadConfig() (*Config, error) { UID: *daemonUID, GID: *daemonGID, InplaceChroot: *daemonInplaceChroot, - EnableJail: *daemonEnableJail || *domainConfigSource == "disk", + EnableJail: *daemonEnableJail, }, Log: Log{ Format: *logFormat, @@ -325,7 +323,6 @@ func LogConfig(config *Config) { "gitlab-server": config.GitLab.PublicServer, "internal-gitlab-server": config.GitLab.InternalServer, "api-secret-key": *gitLabAPISecretKey, - "domain-config-source": config.General.DomainConfigurationSource, "enable-disk": config.GitLab.EnableDisk, "auth-redirect-uri": config.Authentication.RedirectURI, "auth-scope": config.Authentication.Scope, diff --git a/internal/config/flags.go b/internal/config/flags.go index 28a318c4..3ff14bb8 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -41,8 +41,7 @@ var ( gitlabRetrievalInterval = flag.Duration("gitlab-retrieval-interval", time.Second, "The interval to wait before retrying to resolve a domain's configuration via the GitLab API") gitlabRetrievalRetries = flag.Int("gitlab-retrieval-retries", 3, "The maximum number of times to retry to resolve a domain's configuration via the API") - domainConfigSource = flag.String("domain-config-source", "gitlab", "Domain configuration source 'disk', 'auto' or 'gitlab' (default: 'gitlab'). DEPRECATED: gitlab-pages will use the API-based configuration starting from 14.3 see https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/5993") - enableDisk = flag.Bool("enable-disk", true, "Enable disk access, shall be disabled in environments where shared disk storage isn't available") + enableDisk = flag.Bool("enable-disk", true, "Enable disk access, shall be disabled in environments where shared disk storage isn't available") clientID = flag.String("auth-client-id", "", "GitLab application Client ID") clientSecret = flag.String("auth-client-secret", "", "GitLab application Client Secret") diff --git a/internal/source/disk/disk.go b/internal/source/disk/disk.go deleted file mode 100644 index 3596af29..00000000 --- a/internal/source/disk/disk.go +++ /dev/null @@ -1,56 +0,0 @@ -package disk - -import ( - "context" - "strings" - "sync" - "time" - - "gitlab.com/gitlab-org/gitlab-pages/internal/domain" -) - -// Disk struct represents a map of all domains supported by pages that are -// stored on a disk with corresponding `config.json`. -type Disk struct { - dm Map - lock *sync.RWMutex -} - -// New is a factory method for the Disk source. It is initializing a mutex. It -// should not initialize `dm` as we later check the readiness by comparing it -// with a nil value. -func New() *Disk { - return &Disk{ - lock: &sync.RWMutex{}, - } -} - -// GetDomain returns a domain from the domains map if it exists -func (d *Disk) GetDomain(ctx context.Context, host string) (*domain.Domain, error) { - host = strings.ToLower(host) - - d.lock.RLock() - defer d.lock.RUnlock() - - return d.dm[host], nil -} - -// IsReady checks if the domains source is ready for work. The disk source is -// ready after traversing entire filesystem and reading all domains' -// configuration files. -func (d *Disk) IsReady() bool { - return d.dm != nil -} - -// Read starts the domain source, in this case it is reading domains from -// groups on disk concurrently. -func (d *Disk) Read(rootDomain string) { - go Watch(rootDomain, d.updateDomains, time.Second) -} - -func (d *Disk) updateDomains(dm Map) { - d.lock.Lock() - defer d.lock.Unlock() - - d.dm = dm -} diff --git a/internal/source/domains.go b/internal/source/domains.go index 8b7e2be9..b437c6ef 100644 --- a/internal/source/domains.go +++ b/internal/source/domains.go @@ -2,41 +2,23 @@ package source import ( "context" - "fmt" - - "gitlab.com/gitlab-org/labkit/log" "gitlab.com/gitlab-org/gitlab-pages/internal/config" "gitlab.com/gitlab-org/gitlab-pages/internal/domain" - "gitlab.com/gitlab-org/gitlab-pages/internal/source/disk" "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab" ) -type configSource int - -const ( - sourceGitlab configSource = iota - // Disk source is deprecated and support will be removed in 14.3 - // https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 - sourceDisk - sourceAuto -) - -// Domains struct represents a map of all domains supported by pages. It is -// currently using two sources during the transition to the new GitLab domains -// source. +// Domains struct represents a map of all domains supported by pages. type Domains struct { - configSource configSource gitlab Source - disk *disk.Disk // legacy disk source } // NewDomains is a factory method for domains initializing a mutex. It should // not initialize `dm` as we later check the readiness by comparing it with a // nil value. -func NewDomains(source string, cfg *config.GitLab) (*Domains, error) { +func NewDomains(cfg *config.GitLab) (*Domains, error) { domains := &Domains{} - if err := domains.setConfigSource(source, cfg); err != nil { + if err := domains.setConfigSource(cfg); err != nil { return nil, err } @@ -44,43 +26,17 @@ func NewDomains(source string, cfg *config.GitLab) (*Domains, error) { } // setConfigSource and initialize gitlab source -// returns error if -domain-config-source is not valid -// returns error if -domain-config-source=gitlab and init fails -func (d *Domains) setConfigSource(source string, cfg *config.GitLab) error { - switch source { - case "gitlab": - d.configSource = sourceGitlab - return d.setGitLabClient(cfg) - case "auto": - d.configSource = sourceAuto - // enable disk for auto for now - d.disk = disk.New() - return d.setGitLabClient(cfg) - case "disk": - // TODO: disable domains.disk https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 - d.configSource = sourceDisk - d.disk = disk.New() - default: - return fmt.Errorf("invalid option for -domain-config-source: %q", source) - } - - return nil +func (d *Domains) setConfigSource(cfg *config.GitLab) error { + return d.setGitLabClient(cfg) } -// setGitLabClient when domain-config-source is `gitlab` or `auto`, only return error for `gitlab` source func (d *Domains) setGitLabClient(cfg *config.GitLab) error { // We want to notify users about any API issues // Creating a glClient will start polling connectivity in the background // and spam errors in log glClient, err := gitlab.New(cfg) if err != nil { - if d.configSource == sourceGitlab { - return err - } - - log.WithError(err).Warn("failed to initialize GitLab client for `-domain-config-source=auto`") - - return nil + return err } d.gitlab = glClient @@ -96,47 +52,13 @@ func (d *Domains) GetDomain(ctx context.Context, name string) (*domain.Domain, e return d.source(name).GetDomain(ctx, name) } -// Read starts the disk domain source. It is DEPRECATED, because we want to -// remove it entirely when disk source gets removed. -func (d *Domains) Read(rootDomain string) { - // start disk.Read for sourceDisk and sourceAuto - if d.configSource != sourceGitlab { - d.disk.Read(rootDomain) - } -} - // IsReady checks if the disk domain source managed to traverse entire pages // filesystem and is ready for use. It is DEPRECATED, because we want to remove // it entirely when disk source gets removed. func (d *Domains) IsReady() bool { - switch d.configSource { - case sourceGitlab: - return d.gitlab.IsReady() - case sourceDisk: - return d.disk.IsReady() - case sourceAuto: - // if gitlab is configured and is ready - if d.gitlab != nil && d.gitlab.IsReady() { - return true - } - - return d.disk.IsReady() - default: - return false - } + return d.gitlab.IsReady() } func (d *Domains) source(domain string) Source { - switch d.configSource { - case sourceDisk: - return d.disk - case sourceGitlab: - return d.gitlab - default: - if d.gitlab != nil && d.gitlab.IsReady() { - return d.gitlab - } - - return d.disk - } + return d.gitlab } |