Documentation
¶
Overview ¶
Package fakecontrolplane is a control plane that implements api/controlplane/v1 for tests: enrollment with one-time tokens, client certificates from its own CA, and the Connect stream. It records what the operator sends, sends policy snapshots when told to, and can be told to fail. It is not a control plane: no storage, no tenants.
Index ¶
- type Options
- type Server
- func (s *Server) AddToken(token string)
- func (s *Server) CAPEM() []byte
- func (s *Server) Connect(stream controlplanev1.ControlPlaneService_ConnectServer) error
- func (s *Server) DropEnrollResponses(n int)
- func (s *Server) Endpoint() string
- func (s *Server) Enroll(_ context.Context, req *controlplanev1.EnrollRequest) (*controlplanev1.EnrollResponse, error)
- func (s *Server) Events() []*eventsv1.SecurityEvent
- func (s *Server) FailConnect(err error)
- func (s *Server) RequestStats() map[string]*eventsv1.PolicyStats
- func (s *Server) Resync() (bool, error)
- func (s *Server) SendSnapshot(snap *controlplanev1.PolicySnapshot) (bool, error)
- func (s *Server) SetAcceptEvents(accept bool)
- func (s *Server) SetAcceptRequestStats(accept bool)
- func (s *Server) SnapshotVersion() uint64
- func (s *Server) Stats() Stats
- func (s *Server) Stop()
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Addr to listen on; default a random local port.
Addr string
// Hosts its server certificate is valid for, the first one in
// Endpoint; default localhost and 127.0.0.1.
Hosts []string
}
Options configure a server.
type Server ¶
type Server struct {
controlplanev1.UnimplementedControlPlaneServiceServer
// CertLifetime is the lifetime of the client certificates it issues.
CertLifetime time.Duration
// HeartbeatInterval is sent in Welcome.
HeartbeatInterval time.Duration
// AcceptEvents is sent in Welcome: whether replicas send events.
AcceptEvents bool
// AcceptRequestStats is sent in Welcome: whether replicas send request
// counts.
AcceptRequestStats bool
// contains filtered or unexported fields
}
Server is a fake control plane.
func (*Server) Connect ¶
func (s *Server) Connect(stream controlplanev1.ControlPlaneService_ConnectServer) error
Connect implements the stream: Hello first, then Welcome; ClusterState, heartbeats, policy snapshots and their answers, certificate renewal, events and request counts.
func (*Server) DropEnrollResponses ¶
DropEnrollResponses drops the responses of the next n Enroll calls.
func (*Server) Enroll ¶
func (s *Server) Enroll(_ context.Context, req *controlplanev1.EnrollRequest) (*controlplanev1.EnrollResponse, error)
Enroll implements the contract: the first call burns the token; a retry with the same token and public key gets the same certificate.
func (*Server) Events ¶
func (s *Server) Events() []*eventsv1.SecurityEvent
Events returns the distinct events stored, in no order.
func (*Server) FailConnect ¶
FailConnect ends every Connect with err (a gRPC status), or stops failing with nil.
func (*Server) RequestStats ¶ added in v0.3.0
func (s *Server) RequestStats() map[string]*eventsv1.PolicyStats
RequestStats returns the cluster's request counts per policy: the sum of what every replica run counted.
func (*Server) Resync ¶
Resync asks the cluster on the open primary stream for a full ClusterState, and reports whether one was open.
func (*Server) SendSnapshot ¶
func (s *Server) SendSnapshot(snap *controlplanev1.PolicySnapshot) (bool, error)
SendSnapshot sends snap on the open primary stream, and reports whether one was open. Either way, a Managed cluster gets it when it connects with an older policy version, as from a control plane.
func (*Server) SetAcceptEvents ¶
SetAcceptEvents changes what the next Welcome says.
func (*Server) SetAcceptRequestStats ¶ added in v0.3.0
SetAcceptRequestStats changes what the next Welcome says.
func (*Server) SnapshotVersion ¶
SnapshotVersion is the version of the newest snapshot (0: none).
type Stats ¶
type Stats struct {
EnrollCalls int
ConnectCalls int
Hellos []*controlplanev1.Hello
// States are the ClusterStates received, oldest first.
States []*controlplanev1.ClusterState
Heartbeats int
// Events counts the distinct events stored; EventUploads the uploads
// received (resends included); EventsDropped what replicas reported
// dropping, once per buffer and sequence.
Events int
EventUploads int
EventsDropped uint64
// StatsUploads counts the request count uploads.
StatsUploads int
Renewals int
// Clusters is how many distinct clusters enrolled.
Clusters int
// Acks and Nacks answered the policy snapshots, oldest first.
Acks []uint64
Nacks []*controlplanev1.PolicyNack
}
Stats is what the server saw.