File: worker.go

package info (click to toggle)
gitlab-agent 16.11.5-1
  • links: PTS, VCS
  • area: contrib
  • in suites: experimental
  • size: 7,072 kB
  • sloc: makefile: 193; sh: 55; ruby: 3
file content (49 lines) | stat: -rw-r--r-- 1,451 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
package agent

import (
	"context"

	"github.com/robfig/cron/v3"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modagent"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/syncz"
	"go.uber.org/zap"
	"k8s.io/client-go/kubernetes"
)

type workerFactory struct {
	log                       *zap.Logger
	api                       modagent.API
	kubeClientset             kubernetes.Interface
	gitlabAgentNamespace      string
	gitlabAgentServiceAccount string
	ocsServiceAccountName     string
}

func (f *workerFactory) New(cfg configurationToUpdateData) syncz.Worker {
	config := cfg.containerScanningConfig
	if config == nil {
		return syncz.WorkerFunc(func(ctx context.Context) {}) // do nothing
	}

	cadence, _ := cron.ParseStandard(config.Cadence)

	var targetNamespaces []string
	if config.VulnerabilityReport != nil {
		targetNamespaces = config.VulnerabilityReport.Namespaces
	}

	return &schedulerWorker{
		job: &scanJob{
			log:                       f.log,
			api:                       f.api,
			kubeClientset:             f.kubeClientset,
			gitlabAgentNamespace:      f.gitlabAgentNamespace,
			gitlabAgentServiceAccount: f.gitlabAgentServiceAccount,
			ocsServiceAccountName:     f.ocsServiceAccountName,
			agentID:                   cfg.agentID,
			targetNamespaces:          targetNamespaces,
			resourceRequirements:      config.ResourceRequirements,
		},
		cadence: cadence,
	}
}