Documentation ¶
Overview ¶
Package database implements a MeshDB using Kubernetes custom resources.
Index ¶
- Constants
- func HashEdge(source, target types.NodeID) string
- func HashEncodedKey(encoded string) string
- func HashLabelValue(addr string) string
- func HashNodeID(id types.NodeID) string
- func SumKey(key crypto.PublicKey) (string, error)
- func TruncateNodeID(id types.NodeID) string
- type Database
- func (db *Database) Close() error
- func (db *Database) GetPeerByIPv4Addr(ctx context.Context, addr netip.Prefix) (types.MeshNode, error)
- func (db *Database) GetPeerByIPv6Addr(ctx context.Context, addr netip.Prefix) (types.MeshNode, error)
- func (db *Database) GraphStore() storage.GraphStore
- func (db *Database) MeshState() storage.MeshState
- func (db *Database) Networking() storage.Networking
- func (db *Database) RBAC() storage.RBAC
- func (db *Database) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
- type GraphStore
- func (g *GraphStore) AddEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error
- func (g *GraphStore) AddVertex(nodeID types.NodeID, node types.MeshNode, props graph.VertexProperties) error
- func (g *GraphStore) Edge(sourceNode, targetNode types.NodeID) (graph.Edge[types.NodeID], error)
- func (g *GraphStore) ListEdges() ([]graph.Edge[types.NodeID], error)
- func (g *GraphStore) ListVertices() ([]types.NodeID, error)
- func (g *GraphStore) RemoveEdge(sourceNode, targetNode types.NodeID) error
- func (g *GraphStore) RemoveVertex(nodeID types.NodeID) error
- func (g *GraphStore) Subscribe(ctx context.Context, fn storage.PeerSubscribeFunc) (context.CancelFunc, error)
- func (g *GraphStore) UpdateEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error
- func (g *GraphStore) Vertex(nodeID types.NodeID) (node types.MeshNode, props graph.VertexProperties, err error)
- func (g *GraphStore) VertexCount() (int, error)
- type MeshState
- type Networking
- func (nw *Networking) DeleteNetworkACL(ctx context.Context, name string) error
- func (nw *Networking) DeleteRoute(ctx context.Context, name string) error
- func (nw *Networking) GetNetworkACL(ctx context.Context, name string) (types.NetworkACL, error)
- func (nw *Networking) GetRoute(ctx context.Context, name string) (types.Route, error)
- func (nw *Networking) GetRoutesByCIDR(ctx context.Context, cidr netip.Prefix) (types.Routes, error)
- func (nw *Networking) GetRoutesByNode(ctx context.Context, nodeID types.NodeID) (types.Routes, error)
- func (nw *Networking) ListNetworkACLs(ctx context.Context) (types.NetworkACLs, error)
- func (nw *Networking) ListRoutes(ctx context.Context) (types.Routes, error)
- func (nw *Networking) PutNetworkACL(ctx context.Context, acl types.NetworkACL) error
- func (nw *Networking) PutRoute(ctx context.Context, route types.Route) error
- type Options
- type RBAC
- func (r *RBAC) DeleteGroup(ctx context.Context, name string) error
- func (r *RBAC) DeleteRole(ctx context.Context, name string) error
- func (r *RBAC) DeleteRoleBinding(ctx context.Context, name string) error
- func (r *RBAC) GetEnabled(ctx context.Context) (bool, error)
- func (r *RBAC) GetGroup(ctx context.Context, name string) (types.Group, error)
- func (r *RBAC) GetRole(ctx context.Context, name string) (types.Role, error)
- func (r *RBAC) GetRoleBinding(ctx context.Context, name string) (types.RoleBinding, error)
- func (r *RBAC) ListGroups(ctx context.Context) ([]types.Group, error)
- func (r *RBAC) ListNodeRoles(ctx context.Context, nodeID types.NodeID) (types.RolesList, error)
- func (r *RBAC) ListRoleBindings(ctx context.Context) ([]types.RoleBinding, error)
- func (r *RBAC) ListRoles(ctx context.Context) (types.RolesList, error)
- func (r *RBAC) ListUserRoles(ctx context.Context, userID types.NodeID) (types.RolesList, error)
- func (r *RBAC) PutGroup(ctx context.Context, group types.Group) error
- func (r *RBAC) PutRole(ctx context.Context, role types.Role) error
- func (r *RBAC) PutRoleBinding(ctx context.Context, rolebinding types.RoleBinding) error
- func (r *RBAC) SetEnabled(ctx context.Context, enabled bool) error
Constants ¶
const MeshStateConfigName = "webmesh-mesh-state"
MeshStateConfigName is the name of the mesh state object for a given cluster.
const RBACEnabledConfigMap = "webmesh-rbac-enabled"
RBACEnabledConfigMap is the name of the ConfigMap that stores the RBAC enabled state.
const RouteNodeLabel = "webmesh.io/node-id"
RouteNodeLabel is the label used to store the node ID.
Variables ¶
This section is empty.
Functions ¶
func HashEncodedKey ¶
HashEncodedKey hashes the encoded key into a compatible label value.
func HashLabelValue ¶ added in v0.1.4
HashLabelValue is a generic function to hash a label value.
func HashNodeID ¶ added in v0.1.1
HashNodeID hashed a node ID into a compatible kubernetes object name.
func TruncateNodeID ¶
TruncateNodeID truncates a node ID to 63 characters. This is necessary because Kubernetes labels are limited to 63 characters.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is a MeshDB implementation using Kubernetes custom resources.
func New ¶
New returns a new MeshDB instance. It will create a new Database and then wrap it in a meshdb.MeshDB.
func NewFromClient ¶ added in v0.2.2
NewFromClient returns a database from the given client. It does not intialize any controllers.
func (*Database) GetPeerByIPv4Addr ¶ added in v0.1.3
func (db *Database) GetPeerByIPv4Addr(ctx context.Context, addr netip.Prefix) (types.MeshNode, error)
GetPeerByIP returns the peer with the given IP address.
func (*Database) GetPeerByIPv6Addr ¶ added in v0.1.3
func (db *Database) GetPeerByIPv6Addr(ctx context.Context, addr netip.Prefix) (types.MeshNode, error)
GetPeerByIP returns the peer with the given IP address.
func (*Database) GraphStore ¶ added in v0.0.2
func (db *Database) GraphStore() storage.GraphStore
GraphStore returns the interface for querying the peer graph.
func (*Database) Networking ¶
func (db *Database) Networking() storage.Networking
Networking returns the interface for managing networking in the mesh.
type GraphStore ¶
type GraphStore struct {
// contains filtered or unexported fields
}
GraphStore implements the PeerGraphStore interface.
func NewGraphStore ¶
func NewGraphStore(cli client.Client, namespace string) *GraphStore
NewGraphStore returns a new GraphStore instance.
func (*GraphStore) AddEdge ¶
func (g *GraphStore) AddEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error
AddEdge should add an edge between the vertices with the given source and target hashes.
If either vertex doesn't exit, ErrVertexNotFound should be returned for the respective vertex. If the edge already exists, ErrEdgeAlreadyExists should be returned.
func (*GraphStore) AddVertex ¶
func (g *GraphStore) AddVertex(nodeID types.NodeID, node types.MeshNode, props graph.VertexProperties) error
AddVertex should add the given vertex with the given hash value and vertex properties to the graph. If the vertex already exists, it is up to you whether ErrVertexAlreadyExists or no error should be returned.
func (*GraphStore) Edge ¶
Edge should return the edge joining the vertices with the given hash values. It should exclusively look for an edge between the source and the target vertex, not vice versa. The graph implementation does this for undirected graphs itself.
Note that unlike Graph.Edge, this function is supposed to return an Edge[K], i.e. an edge that only contains the vertex hashes instead of the vertices themselves.
If the edge doesn't exist, ErrEdgeNotFound should be returned.
func (*GraphStore) ListVertices ¶
func (g *GraphStore) ListVertices() ([]types.NodeID, error)
ListVertices should return all vertices in the graph in a slice.
func (*GraphStore) RemoveEdge ¶
func (g *GraphStore) RemoveEdge(sourceNode, targetNode types.NodeID) error
RemoveEdge should remove the edge between the vertices with the given source and target hashes.
If either vertex doesn't exist, it is up to you whether ErrVertexNotFound or no error should be returned. If the edge doesn't exist, it is up to you whether ErrEdgeNotFound or no error should be returned.
func (*GraphStore) RemoveVertex ¶
func (g *GraphStore) RemoveVertex(nodeID types.NodeID) error
RemoveVertex should remove the vertex with the given hash value.
func (*GraphStore) Subscribe ¶ added in v0.0.2
func (g *GraphStore) Subscribe(ctx context.Context, fn storage.PeerSubscribeFunc) (context.CancelFunc, error)
Subscribe subscribes to node changes.
func (*GraphStore) UpdateEdge ¶
func (g *GraphStore) UpdateEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error
UpdateEdge should update the edge between the given vertices with the data of the given Edge instance. If the edge doesn't exist, ErrEdgeNotFound should be returned.
func (*GraphStore) Vertex ¶
func (g *GraphStore) Vertex(nodeID types.NodeID) (node types.MeshNode, props graph.VertexProperties, err error)
Vertex should return the vertex and vertex properties with the given hash value. If the vertex doesn't exist, ErrVertexNotFound should be returned.
func (*GraphStore) VertexCount ¶
func (g *GraphStore) VertexCount() (int, error)
VertexCount should return the number of vertices in the graph. This should be equal to the length of the slice returned by ListVertices.
type MeshState ¶
type MeshState struct {
// contains filtered or unexported fields
}
MeshState implements the MeshState interface.
func NewMeshState ¶
NewMeshState returns a new MeshState instance.
func (*MeshState) GetMeshState ¶ added in v0.0.6
GetMeshState returns the mesh state.
func (*MeshState) SetMeshState ¶ added in v0.1.5
SetMeshState sets the mesh state.
type Networking ¶
type Networking struct {
// contains filtered or unexported fields
}
Networking implements the Networking interface.
func NewNetworking ¶
func NewNetworking(cli client.Client, namespace string) *Networking
NewNetworking returns a new Networking instance.
func (*Networking) DeleteNetworkACL ¶
func (nw *Networking) DeleteNetworkACL(ctx context.Context, name string) error
DeleteNetworkACL deletes a NetworkACL by name.
func (*Networking) DeleteRoute ¶
func (nw *Networking) DeleteRoute(ctx context.Context, name string) error
DeleteRoute deletes a Route by name.
func (*Networking) GetNetworkACL ¶
func (nw *Networking) GetNetworkACL(ctx context.Context, name string) (types.NetworkACL, error)
GetNetworkACL returns a NetworkACL by name.
func (*Networking) GetRoutesByCIDR ¶
GetRoutesByCIDR returns a list of Routes for a given CIDR.
func (*Networking) GetRoutesByNode ¶
func (nw *Networking) GetRoutesByNode(ctx context.Context, nodeID types.NodeID) (types.Routes, error)
GetRoutesByNode returns a list of Routes for a given Node.
func (*Networking) ListNetworkACLs ¶
func (nw *Networking) ListNetworkACLs(ctx context.Context) (types.NetworkACLs, error)
ListNetworkACLs returns a list of NetworkACLs.
func (*Networking) ListRoutes ¶
ListRoutes returns a list of Routes.
func (*Networking) PutNetworkACL ¶
func (nw *Networking) PutNetworkACL(ctx context.Context, acl types.NetworkACL) error
PutNetworkACL creates or updates a NetworkACL.
type RBAC ¶
type RBAC struct {
// contains filtered or unexported fields
}
RBAC implements the RBAC interface.
func (*RBAC) DeleteGroup ¶
DeleteGroup deletes a group by name.
func (*RBAC) DeleteRole ¶
DeleteRole deletes a role by name.
func (*RBAC) DeleteRoleBinding ¶
DeleteRoleBinding deletes a rolebinding by name.
func (*RBAC) GetEnabled ¶
GetEnabled returns the RBAC enabled state.
func (*RBAC) GetRoleBinding ¶
GetRoleBinding returns a rolebinding by name.
func (*RBAC) ListGroups ¶
ListGroups returns a list of all groups.
func (*RBAC) ListNodeRoles ¶
ListNodeRoles returns a list of all roles for a node.
func (*RBAC) ListRoleBindings ¶
ListRoleBindings returns a list of all rolebindings.
func (*RBAC) ListUserRoles ¶
ListUserRoles returns a list of all roles for a user.
func (*RBAC) PutRoleBinding ¶
PutRoleBinding creates or updates a rolebinding.