database

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package database implements a MeshDB using Kubernetes custom resources.

Index

Constants

View Source
const MeshStateConfigName = "webmesh-mesh-state"

MeshStateConfigName is the name of the mesh state object for a given cluster.

View Source
const RBACEnabledConfigMap = "webmesh-rbac-enabled"

RBACEnabledConfigMap is the name of the ConfigMap that stores the RBAC enabled state.

View Source
const RouteNodeLabel = "webmesh.io/node-id"

RouteNodeLabel is the label used to store the node ID.

Variables

This section is empty.

Functions

func HashEdge added in v0.1.1

func HashEdge(source, target types.NodeID) string

HashEdge hashes the edge into a compatible kubernetes object name.

func HashEncodedKey

func HashEncodedKey(encoded string) string

HashEncodedKey hashes the encoded key into a compatible label value.

func HashLabelValue added in v0.1.4

func HashLabelValue(addr string) string

HashLabelValue is a generic function to hash a label value.

func HashNodeID added in v0.1.1

func HashNodeID(id types.NodeID) string

HashNodeID hashed a node ID into a compatible kubernetes object name.

func SumKey

func SumKey(key crypto.PublicKey) (string, error)

SumKey sums the key into a compatible label value.

func TruncateNodeID

func TruncateNodeID(id types.NodeID) string

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

func New(mgr manager.Manager, opts Options) (storage.MeshDB, *Database, error)

New returns a new MeshDB instance. It will create a new Database and then wrap it in a meshdb.MeshDB.

func NewDB added in v0.0.2

func NewDB(mgr manager.Manager, opts Options) (*Database, error)

NewDB returns a new MeshDataStore instance.

func NewFromClient added in v0.2.2

func NewFromClient(cli client.Client, opts Options) *Database

NewFromClient returns a database from the given client. It does not intialize any controllers.

func (*Database) Close

func (db *Database) Close() error

Close closes the database.

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) MeshState

func (db *Database) MeshState() storage.MeshState

MeshState returns the interface for querying mesh state.

func (*Database) Networking

func (db *Database) Networking() storage.Networking

Networking returns the interface for managing networking in the mesh.

func (*Database) RBAC

func (db *Database) RBAC() storage.RBAC

RBAC returns the interface for conditionmanaging RBAC policies in the mesh.

func (*Database) Reconcile added in v0.0.2

func (db *Database) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is called for every update to a peer, route, or edge.

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

func (g *GraphStore) Edge(sourceNode, targetNode types.NodeID) (graph.Edge[types.NodeID], error)

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) ListEdges

func (g *GraphStore) ListEdges() ([]graph.Edge[types.NodeID], error)

ListEdges should return all edges in the graph in a slice.

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

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

func NewMeshState(cli client.Client, namespace string) *MeshState

NewMeshState returns a new MeshState instance.

func (*MeshState) GetMeshState added in v0.0.6

func (st *MeshState) GetMeshState(ctx context.Context) (types.NetworkState, error)

GetMeshState returns the mesh state.

func (*MeshState) SetMeshState added in v0.1.5

func (st *MeshState) SetMeshState(ctx context.Context, state types.NetworkState) error

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) GetRoute

func (nw *Networking) GetRoute(ctx context.Context, name string) (types.Route, error)

GetRoute returns a Route by name.

func (*Networking) GetRoutesByCIDR

func (nw *Networking) GetRoutesByCIDR(ctx context.Context, cidr netip.Prefix) (types.Routes, error)

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

func (nw *Networking) ListRoutes(ctx context.Context) (types.Routes, error)

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.

func (*Networking) PutRoute

func (nw *Networking) PutRoute(ctx context.Context, route types.Route) error

PutRoute creates or updates a Route.

type Options

type Options struct {
	NodeID     types.NodeID
	Namespace  string
	ListenAddr *net.TCPAddr
}

Options are the options for the database.

type RBAC

type RBAC struct {
	// contains filtered or unexported fields
}

RBAC implements the RBAC interface.

func NewRBAC

func NewRBAC(cli client.Client, namespace string) *RBAC

NewRBAC returns a new RBAC instance.

func (*RBAC) DeleteGroup

func (r *RBAC) DeleteGroup(ctx context.Context, name string) error

DeleteGroup deletes a group by name.

func (*RBAC) DeleteRole

func (r *RBAC) DeleteRole(ctx context.Context, name string) error

DeleteRole deletes a role by name.

func (*RBAC) DeleteRoleBinding

func (r *RBAC) DeleteRoleBinding(ctx context.Context, name string) error

DeleteRoleBinding deletes a rolebinding by name.

func (*RBAC) GetEnabled

func (r *RBAC) GetEnabled(ctx context.Context) (bool, error)

GetEnabled returns the RBAC enabled state.

func (*RBAC) GetGroup

func (r *RBAC) GetGroup(ctx context.Context, name string) (types.Group, error)

GetGroup returns a group by name.

func (*RBAC) GetRole

func (r *RBAC) GetRole(ctx context.Context, name string) (types.Role, error)

GetRole returns a role by name.

func (*RBAC) GetRoleBinding

func (r *RBAC) GetRoleBinding(ctx context.Context, name string) (types.RoleBinding, error)

GetRoleBinding returns a rolebinding by name.

func (*RBAC) ListGroups

func (r *RBAC) ListGroups(ctx context.Context) ([]types.Group, error)

ListGroups returns a list of all groups.

func (*RBAC) ListNodeRoles

func (r *RBAC) ListNodeRoles(ctx context.Context, nodeID types.NodeID) (types.RolesList, error)

ListNodeRoles returns a list of all roles for a node.

func (*RBAC) ListRoleBindings

func (r *RBAC) ListRoleBindings(ctx context.Context) ([]types.RoleBinding, error)

ListRoleBindings returns a list of all rolebindings.

func (*RBAC) ListRoles

func (r *RBAC) ListRoles(ctx context.Context) (types.RolesList, error)

ListRoles returns a list of all roles.

func (*RBAC) ListUserRoles

func (r *RBAC) ListUserRoles(ctx context.Context, userID types.NodeID) (types.RolesList, error)

ListUserRoles returns a list of all roles for a user.

func (*RBAC) PutGroup

func (r *RBAC) PutGroup(ctx context.Context, group types.Group) error

PutGroup creates or updates a group.

func (*RBAC) PutRole

func (r *RBAC) PutRole(ctx context.Context, role types.Role) error

PutRole creates or updates a role.

func (*RBAC) PutRoleBinding

func (r *RBAC) PutRoleBinding(ctx context.Context, rolebinding types.RoleBinding) error

PutRoleBinding creates or updates a rolebinding.

func (*RBAC) SetEnabled

func (r *RBAC) SetEnabled(ctx context.Context, enabled bool) error

SetEnabled sets the RBAC enabled state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL