File: persisted_terminating_workspaces.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 (41 lines) | stat: -rw-r--r-- 1,236 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
package agent

// terminatingWorkspacesTrackerKey is used as a key within persistedTerminatingWorkspacesTracker
// to uniquely identify a combination of workspace name and namespace that must be tracked
type terminatingWorkspacesTrackerKey struct {
	name      string
	namespace string
}

// persistedTerminatingWorkspacesTracker is a set to track workspaces that exist
// in Terminating state
type persistedTerminatingWorkspacesTracker map[terminatingWorkspacesTrackerKey]struct{}

func newPersistedTerminatingWorkspacesTracker() persistedTerminatingWorkspacesTracker {
	return make(map[terminatingWorkspacesTrackerKey]struct{})
}

func (p persistedTerminatingWorkspacesTracker) isTerminating(name string, namespace string) bool {
	key := terminatingWorkspacesTrackerKey{
		name:      name,
		namespace: namespace,
	}
	_, ok := p[key]
	return ok
}

func (p persistedTerminatingWorkspacesTracker) add(name string, namespace string) {
	key := terminatingWorkspacesTrackerKey{
		name:      name,
		namespace: namespace,
	}
	p[key] = struct{}{}
}

func (p persistedTerminatingWorkspacesTracker) delete(name string, namespace string) {
	key := terminatingWorkspacesTrackerKey{
		name:      name,
		namespace: namespace,
	}
	delete(p, key)
}