Documentation
¶
Index ¶
- Constants
- type Args
- type Runtime
- type TestHarness
- func (th *TestHarness) AssertErrorStatus(t *testing.T, err error, c codes.Code, msgRegex string)
- func (th *TestHarness) FakeKubeConfigFileName() string
- func (th *TestHarness) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error)
- func (th *TestHarness) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error)
- func (th *TestHarness) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error)
- func (th *TestHarness) RemoveFakeKubeConfig(t *testing.T)
- func (th *TestHarness) RemoveTestTLSFiles(_ *testing.T)
- func (th *TestHarness) RuntimeArgs() Args
- func (th *TestHarness) RuntimeForFakeCSIDriver(t *testing.T) *Runtime
- func (th *TestHarness) RuntimeForMockCSIDriver(t *testing.T) *Runtime
- func (th *TestHarness) TerminateFakeCSIDriver(t *testing.T)
- func (th *TestHarness) TerminateMockCSIDriver()
- func (th *TestHarness) WithFakeCSIDriver(t *testing.T, sms csi.SnapshotMetadataServer) *TestHarness
- func (th *TestHarness) WithFakeKubeConfig(t *testing.T) *TestHarness
- func (th *TestHarness) WithMockCSIDriver(t *testing.T) *TestHarness
- func (th *TestHarness) WithTestTLSFiles(t *testing.T) *TestHarness
Constants ¶
const ( LabelTargetSnapshotName = "target_snapshot" LabelBaseSnapshotName = "base_snapshot" SubSystem = "snapshot_metadata_controller" // MetadataAllocatedOperationName is the operation that tracks how long the controller takes to get the allocated blocks for a snapshot. // Specifically, the operation metric is emitted based on the following timestamps: // - Start_time: controller notices the first time that there is a GetMetadataAllocated RPC call to fetch the allocated blocks of metadata // - End_time: controller notices that the RPC call is finished and the allocated blocks is streamed back to the driver MetadataAllocatedOperationName = "MetadataAllocated" // MetadataDeltaOperationName is the operation that tracks how long the controller takes to get the changed blocks between 2 snapshots // Specifically, the operation metric is emitted based on the following timestamps: // - Start_time: controller notices the first time that there is a GetMetadataDelta RPC call to fetch the changed blocks between 2 snapshots // - End_time: controller notices that the RPC call is finished and the changed blocks is streamed back to the driver MetadataDeltaOperationName = "MetadataDelta" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Args ¶
type Args struct {
// Address of the CSI driver socket.
CSIAddress string
// CSITimeout is the timeout for CSI driver communications.
CSITimeout time.Duration
// Burst for the K8s apiserver.
KubeAPIBurst int
// QPS for the K8s apiserver.
KubeAPIQPS float32
// Absolute path to a kubeconfig file if operating out of cluster.
Kubeconfig string
// GRPC port number
GRPCPort int
// Absolute path to the TLS cert file.
TLSCertFile string
// Absolute path to the TLS key file.
TLSKeyFile string
// HttpEndpoint is the address of the metrics sever
HttpEndpoint string
// MetricsPath is the path where metrics will be recorded
MetricsPath string
}
type Runtime ¶
type Runtime struct {
Args
Config *rest.Config
KubeClient kubernetes.Interface
CBTClient cbt.Interface
SnapshotClient snapshot.Interface
CSIConn *grpc.ClientConn
MetricsManager metrics.CSIMetricsManager
DriverName string
}
Runtime contains client connection objects needed for the sidecar.
func (*Runtime) RecordMetricsWithLabels ¶
func (rt *Runtime) RecordMetricsWithLabels(opLabel map[string]string, opName string, startTime time.Time, opErr error)
RecordMetricsWithLabels is a wrapper on the csi-lib-utils RecordMetrics function, that calls the "RecordMetrics" functions with the necessary labels added to the MetricsManager runtime.
func (*Runtime) WaitTillCSIDriverIsValidated ¶
WaitTillCSIDriverIsValidated waits until the CSI driver becomes ready, and then confirms that it supports the snapshot metadata service.
type TestHarness ¶
type TestHarness struct {
MockController *gomock.Controller
MockCSIDriver *driver.MockCSIDriver
MockCSIIdentityServer *driver.MockIdentityServer
MockCSISnapshotMetadataServer *driver.MockSnapshotMetadataServer
MockCSIDriverConn *grpc.ClientConn
MetricsManager metrics.CSIMetricsManager
FakeCSIDriver *driver.CSIDriver
// Identity server responses
FakeProbeResponse *csi.ProbeResponse
FakeGetPluginCapabilitiesResponse *csi.GetPluginCapabilitiesResponse
// for the mock/fake servers
*csi.UnimplementedIdentityServer
// contains filtered or unexported fields
}
TestHarness provides a Runtime that can either work with a fake CSI driver based on the csi-test framework, or a mock CSI driver with the CSI Identity and CSI SnapshotMetadata servers.
Mock CSI driver usage example th := NewTestHarness().WithMockCSIDriver(t) defer th.TerminateMockCSIDriver() th.MockCSIIdentityServer.EXPECT().GetDriverName(gomock.Any(), gomock.Any()).Return("driver",nil) rt := th.RuntimeForMockCSIDriver(t) name, err := csirpc.GetDriverName(ctx, rt.CSIConn) // sample GRPC client call
Fake CSI driver usage example sms := &fakeSnapshotMetadataServer{} // optional th := NewTestHarness().WithFakeKubeConfig(t).WithFakeCSIDriver(t, sms) defer th.RemoveFakeKubeConfig(t) defer th.TerminateFakeCSIDriver(t) rt := th.RuntimeForFakeCSIDriver(t) name, err := csirpc.GetDriverName(ctx, rt.CSIConn) // sample GRPC client call
The runtime args can point to real TLS cert and key files instead of non-existent paths. th := NewTestHarness().WithTestTLSFiles(t).With... defer th.RemoveFakeTLSFiles(t) rta := th.RuntimeArgs() cert, err := tls.LoadX509KeyPair(rta.TLSCertFile, rta.TLSKeyFile)
func (*TestHarness) AssertErrorStatus ¶
func (*TestHarness) FakeKubeConfigFileName ¶
func (th *TestHarness) FakeKubeConfigFileName() string
func (*TestHarness) GetPluginCapabilities ¶
func (th *TestHarness) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error)
func (*TestHarness) GetPluginInfo ¶
func (th *TestHarness) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error)
func (*TestHarness) Probe ¶
func (th *TestHarness) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error)
func (*TestHarness) RemoveFakeKubeConfig ¶
func (th *TestHarness) RemoveFakeKubeConfig(t *testing.T)
func (*TestHarness) RemoveTestTLSFiles ¶
func (th *TestHarness) RemoveTestTLSFiles(_ *testing.T)
func (*TestHarness) RuntimeArgs ¶
func (th *TestHarness) RuntimeArgs() Args
func (*TestHarness) RuntimeForFakeCSIDriver ¶
func (th *TestHarness) RuntimeForFakeCSIDriver(t *testing.T) *Runtime
func (*TestHarness) RuntimeForMockCSIDriver ¶
func (th *TestHarness) RuntimeForMockCSIDriver(t *testing.T) *Runtime
func (*TestHarness) TerminateFakeCSIDriver ¶
func (th *TestHarness) TerminateFakeCSIDriver(t *testing.T)
func (*TestHarness) TerminateMockCSIDriver ¶
func (th *TestHarness) TerminateMockCSIDriver()
func (*TestHarness) WithFakeCSIDriver ¶
func (th *TestHarness) WithFakeCSIDriver(t *testing.T, sms csi.SnapshotMetadataServer) *TestHarness
WithFakeCSIDriver launches a fake CSIDriver, optionally with a provided SnapshotMetadataServer. If a SnapshotMetadataServer is provided then it initializes the FakeGetPluginCapabilitiesResponse field to set the capability for the service.
func (*TestHarness) WithFakeKubeConfig ¶
func (th *TestHarness) WithFakeKubeConfig(t *testing.T) *TestHarness
WithFakeKubeConfig creates a kubeconfig file that is needed to communicate with the fake CSI driver.
func (*TestHarness) WithMockCSIDriver ¶
func (th *TestHarness) WithMockCSIDriver(t *testing.T) *TestHarness
func (*TestHarness) WithTestTLSFiles ¶
func (th *TestHarness) WithTestTLSFiles(t *testing.T) *TestHarness
WithTestTLSFiles will provide temporary but valid TLS files.