File: worker_factory.go

package info (click to toggle)
gitlab-agent 16.1.3-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 6,324 kB
  • sloc: makefile: 175; sh: 52; ruby: 3
file content (56 lines) | stat: -rw-r--r-- 1,856 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package chartops

import (
	"net/http"

	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/gitops/rpc"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modagent"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/logz"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/retry"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/pkg/agentcfg"
	"go.uber.org/zap"
)

type workerFactory struct {
	log               *zap.Logger
	helm              func(log *zap.Logger, chartCfg *agentcfg.ChartCF) Helm
	httpClient        http.RoundTripper
	gitopsClient      rpc.GitopsClient
	installPollConfig retry.PollConfigFactory
	watchPollConfig   retry.PollConfigFactory
}

func (f *workerFactory) New(agentId int64, source modagent.WorkSource[*agentcfg.ChartCF]) modagent.Worker {
	chartCfg := source.Configuration()
	l := f.log.With(logz.WorkerId(source.ID()), logz.AgentId(agentId))
	return &worker{
		log:               l,
		chartCfg:          chartCfg,
		installPollConfig: f.installPollConfig(),
		helm:              f.helm(l, chartCfg),
		httpClient:        f.httpClient,
		objWatcher: &rpc.ObjectsToSynchronizeWatcher{
			Log:          l,
			GitopsClient: f.gitopsClient,
			PollConfig:   f.watchPollConfig,
		},
	}
}

func (f *workerFactory) SourcesFromConfiguration(cfg *agentcfg.AgentConfiguration) []modagent.WorkSource[*agentcfg.ChartCF] {
	res := make([]modagent.WorkSource[*agentcfg.ChartCF], 0, len(cfg.Gitops.Charts))
	for _, chart := range cfg.Gitops.Charts {
		res = append(res, (*manifestSource)(chart))
	}
	return res
}

type manifestSource agentcfg.ChartCF

func (s *manifestSource) ID() string {
	return *s.Namespace + "/" + s.ReleaseName
}

func (s *manifestSource) Configuration() *agentcfg.ChartCF {
	return (*agentcfg.ChartCF)(s)
}