File: worker_1_watch.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 (30 lines) | stat: -rw-r--r-- 864 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
package manifestops

import (
	"context"

	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/gitops/rpc"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/pkg/agentcfg"
)

func (w *worker) watch(ctx context.Context, desiredState chan<- rpc.ObjectsToSynchronizeData) {
	req := &rpc.ObjectsToSynchronizeRequest{
		ProjectId: *w.project.Id,
		Ref:       rpc.NewRpcRef(w.project.Ref),
		Paths:     configPathsToRpcPaths(w.project.Paths),
	}
	w.objWatcher.Watch(ctx, req, func(ctx context.Context, data rpc.ObjectsToSynchronizeData) {
		select {
		case <-ctx.Done():
		case desiredState <- data:
		}
	})
}

func configPathsToRpcPaths(paths []*agentcfg.PathCF) []*rpc.PathCF {
	p := make([]*rpc.PathCF, 0, len(paths))
	for _, path := range paths {
		p = append(p, &rpc.PathCF{Path: &rpc.PathCF_Glob{Glob: path.Glob}})
	}
	return p
}