diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-10 17:23:19 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-20 04:39:04 +0300 |
commit | 5e9447161081a73d15ae81cd21da683fde7c2e9b (patch) | |
tree | aacdfe699490353a5f3ed4fc30a91218bdac76a6 /internal/source | |
parent | 111faf403e3df4c6e998a625f7ad8b22da4ff6ee (diff) |
refactor: remove support for disk configuration source
Changelog: removed
Diffstat (limited to 'internal/source')
-rw-r--r-- | internal/source/disk/disk.go | 56 | ||||
-rw-r--r-- | internal/source/domains.go | 94 |
2 files changed, 8 insertions, 142 deletions
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 } |