File: 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 (59 lines) | stat: -rw-r--r-- 1,730 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
57
58
59
package agent

import (
	"fmt"

	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modagent"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modshared"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/starboard_vulnerability"
)

const (
	defaultGitlabAgentNamespace      = "gitlab-agent"
	defaultGitlabAgentServiceAccount = "gitlab-agent"
)

type Factory struct{}

func (f *Factory) New(cfg *modagent.Config) (modagent.Module, error) {
	kubeClientset, err := cfg.K8sUtilFactory.KubernetesClientSet()
	if err != nil {
		return nil, fmt.Errorf("could not create kubernetes clientset: %w", err)
	}
	return &module{
		log:                       cfg.Log,
		api:                       cfg.Api,
		policiesUpdateDataChannel: make(chan configurationToUpdateData),
		workerFactory: (&workerFactory{
			log:                       cfg.Log,
			api:                       cfg.Api,
			kubeClientset:             kubeClientset,
			gitlabAgentNamespace:      getAgentNamespace(cfg),
			gitlabAgentServiceAccount: getAgentServiceAccount(cfg),
		}).New,
	}, nil
}

func (f *Factory) Name() string {
	return starboard_vulnerability.ModuleName
}

func (f *Factory) StartStopPhase() modshared.ModuleStartStopPhase {
	return modshared.ModuleStartBeforeServers
}

func getAgentNamespace(cfg *modagent.Config) string {
	namespace := cfg.AgentMeta.PodNamespace
	if namespace == "" {
		namespace = defaultGitlabAgentNamespace
	}
	return namespace
}

func getAgentServiceAccount(cfg *modagent.Config) string {
	serviceAccountName := cfg.ServiceAccountName
	if serviceAccountName == "" {
		serviceAccountName = defaultGitlabAgentServiceAccount
	}
	return serviceAccountName
}