-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
kvstore.go
73 lines (57 loc) · 2.52 KB
/
kvstore.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package kvstore
import (
"strings"
"github.com/cilium/cilium/pkg/time"
)
// Value is an abstraction of the data stored in the kvstore as well as the
// mod revision of that data.
type Value struct {
Data []byte
ModRevision uint64
LeaseID int64
SessionID string
}
// KeyValuePairs is a map of key=value pairs
type KeyValuePairs map[string]Value
// Capabilities is a bitmask to indicate the capabilities of a backend
type Capabilities uint32
const (
// CapabilityCreateIfExists is true if CreateIfExists is functional
CapabilityCreateIfExists Capabilities = 1 << 0
// CapabilityDeleteOnZeroCount is true if DeleteOnZeroCount is functional
CapabilityDeleteOnZeroCount Capabilities = 1 << 1
// BaseKeyPrefix is the base prefix that should be used for all keys
BaseKeyPrefix = "cilium"
// InitLockPath is the path to the init lock to test quorum
InitLockPath = BaseKeyPrefix + "/.initlock"
// HeartbeatPath is the path to the key at which the operator updates
// the heartbeat
HeartbeatPath = BaseKeyPrefix + "/.heartbeat"
// HasClusterConfigPath is the path to the key used to convey that the cluster
// configuration will be eventually created, and remote cilium agents shall
// wait until it is present. If this key is not set, the cilium configuration
// might, or might not, be configured, but the agents will continue regardless,
// falling back to the backward compatible behavior. It must be set before that
// the agents have the possibility to connect to the kvstore (that is, when
// it is not yet exposed). The corresponding values is ignored.
HasClusterConfigPath = BaseKeyPrefix + "/.has-cluster-config"
// ClusterConfigPrefix is the kvstore prefix to cluster configuration
ClusterConfigPrefix = BaseKeyPrefix + "/cluster-config"
// SyncedPrefix is the kvstore prefix used to convey whether
// synchronization from an external source has completed for a given prefix
SyncedPrefix = BaseKeyPrefix + "/synced"
// HeartbeatWriteInterval is the interval in which the heartbeat key at
// HeartbeatPath is updated
HeartbeatWriteInterval = time.Minute
)
// StateToCachePrefix converts a kvstore prefix starting with "cilium/state"
// (holding the cilium state) to the corresponding one holding cached information
// from another kvstore (that is, "cilium/cache").
func StateToCachePrefix(prefix string) string {
if strings.HasPrefix(prefix, "cilium/state") {
return strings.Replace(prefix, "cilium/state", "cilium/cache", 1)
}
return prefix
}