github.com/cilium/cilium@v1.16.2/pkg/kvstore/kvstore.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package kvstore
     5  
     6  import (
     7  	"strings"
     8  
     9  	"github.com/cilium/cilium/pkg/time"
    10  )
    11  
    12  // Value is an abstraction of the data stored in the kvstore as well as the
    13  // mod revision of that data.
    14  type Value struct {
    15  	Data        []byte
    16  	ModRevision uint64
    17  	LeaseID     int64
    18  	SessionID   string
    19  }
    20  
    21  // KeyValuePairs is a map of key=value pairs
    22  type KeyValuePairs map[string]Value
    23  
    24  const (
    25  	// BaseKeyPrefix is the base prefix that should be used for all keys
    26  	BaseKeyPrefix = "cilium"
    27  
    28  	// StatePrefix is the kvstore prefix used to store the Cilium's state.
    29  	StatePrefix = BaseKeyPrefix + "/state"
    30  
    31  	// CachePrefix is the kvstore prefix used to store the information retrieved
    32  	// from a remote cluster and cached locally by KVStoreMesh.
    33  	CachePrefix = BaseKeyPrefix + "/cache"
    34  
    35  	// InitLockPath is the path to the init lock to test quorum
    36  	InitLockPath = BaseKeyPrefix + "/.initlock"
    37  
    38  	// HeartbeatPath is the path to the key at which the operator updates
    39  	// the heartbeat
    40  	HeartbeatPath = BaseKeyPrefix + "/.heartbeat"
    41  
    42  	// HasClusterConfigPath is the path to the key used to convey that the cluster
    43  	// configuration will be eventually created, and remote cilium agents shall
    44  	// wait until it is present. If this key is not set, the cilium configuration
    45  	// might, or might not, be configured, but the agents will continue regardless,
    46  	// falling back to the backward compatible behavior. It must be set before that
    47  	// the agents have the possibility to connect to the kvstore (that is, when
    48  	// it is not yet exposed). The corresponding values is ignored.
    49  	// Starting from v1.16, Cilium always expects the cluster configuration to be
    50  	// present. This key is now deprecated and shall be removed in Cilium v1.17.
    51  	HasClusterConfigPath = BaseKeyPrefix + "/.has-cluster-config"
    52  
    53  	// ClusterConfigPrefix is the kvstore prefix to cluster configuration
    54  	ClusterConfigPrefix = BaseKeyPrefix + "/cluster-config"
    55  
    56  	// SyncedPrefix is the kvstore prefix used to convey whether
    57  	// synchronization from an external source has completed for a given prefix
    58  	SyncedPrefix = BaseKeyPrefix + "/synced"
    59  
    60  	// HeartbeatWriteInterval is the interval in which the heartbeat key at
    61  	// HeartbeatPath is updated
    62  	HeartbeatWriteInterval = time.Minute
    63  )
    64  
    65  // StateToCachePrefix converts a kvstore prefix starting with "cilium/state"
    66  // (holding the cilium state) to the corresponding one holding cached information
    67  // from another kvstore (that is, "cilium/cache").
    68  func StateToCachePrefix(prefix string) string {
    69  	if strings.HasPrefix(prefix, StatePrefix) {
    70  		return strings.Replace(prefix, StatePrefix, CachePrefix, 1)
    71  	}
    72  	return prefix
    73  }