Documentation
¶
Index ¶
- Constants
- Variables
- func Authenticate(client *api.APIClient, username, password string) (context.Context, error)
- func GetAPIErrorResponse(oerr error) error
- func GetAPIErrorRootCause(oerr error) error
- func ReadCredsFromMountedSecret(path string) (string, string, error)
- type Client
- func (c *Client) AddToken(ctx context.Context) context.Context
- func (c *Client) ListSharedVolumes() (SharedVolumeList, error)
- func (c *Client) Refresh(ctx context.Context, secretPath string, reset chan struct{}, ...) error
- func (c *Client) SetExternalEndpoint(id string, namespace string, endpoint string) error
- type ControlPlane
- type MockClient
- func (c *MockClient) Delete(id string, namespace string)
- func (c *MockClient) Get(id string, namespace string) (*SharedVolume, error)
- func (c *MockClient) ListSharedVolumes() (SharedVolumeList, error)
- func (c *MockClient) RandomVol() *SharedVolume
- func (c *MockClient) Reset()
- func (c *MockClient) Set(v *SharedVolume) *SharedVolume
- func (c *MockClient) SetExternalEndpoint(id string, namespace string, endpoint string) error
- type SharedVolume
- func (v *SharedVolume) Endpoints() *corev1.Endpoints
- func (v *SharedVolume) EndpointsIsEqual(e *corev1.Endpoints) bool
- func (v *SharedVolume) EndpointsUpdate(e *corev1.Endpoints) *corev1.Endpoints
- func (v *SharedVolume) InternalAddress() string
- func (v *SharedVolume) InternalPort() int
- func (v *SharedVolume) IsEqual(obj *SharedVolume) bool
- func (v *SharedVolume) Service(ownerRef metav1.OwnerReference) *corev1.Service
- func (v *SharedVolume) ServiceIsEqual(svc *corev1.Service) bool
- func (v *SharedVolume) ServiceUpdate(svc *corev1.Service) *corev1.Service
- type SharedVolumeList
Constants ¶
const ( // DefaultPort is the default api port. DefaultPort = 5705 // DefaultScheme is used for api endpoint. DefaultScheme = "http" // TLSScheme scheme can be used if the api endpoint has TLS enabled. TLSScheme = "https" )
const ( // NFSPort is the port exposed by the service. Each service will have a // unique ip, so it can be fixed to the default NFS port. NFSPort int32 = 2049 // NFSPortName is used as the name of the NFS port in the service defintion. NFSPortName = "nfs" // NFSProtocol is the prtocol to be used for NFS. NFSProtocol = "TCP" // VolumeIDLabelName is the label to set on created resources that refers // back to the StorageOS volume by its ID. This label is intended for // assisting with debugging and the api-manager should not rely on it being // set. VolumeIDLabelName = "storageos.com/volume-id" // LabelNFSMountEndpoint is the nfs attachment's mount endpoint, if any. LabelNFSMountEndpoint = "storageos.com/nfs/mount-endpoint" // LabelPVName holds the name of the corresponding PV. LabelPVName = "csi.storage.k8s.io/pv/name" // LabelPVCName holds the name of the corresponding PVC. LabelPVCName = "csi.storage.k8s.io/pvc/name" // LabelPVCNamespace holds the namespace of the corresponding PVC. It // should always be the same as the volume namespace. LabelPVCNamespace = "csi.storage.k8s.io/pvc/namespace" )
Variables ¶
var ( // ErrNotInitialized is returned if the API client was accessed before it // was initialised. ErrNotInitialized = errors.New("api client not initialized") // ErrNoAuthToken is returned when the API client did not get an error // during authentication but no valid auth token was returned. ErrNoAuthToken = errors.New("no token found in auth response") // HTTPTimeout is the time limit for requests made by the API Client. The // timeout includes connection time, any redirects, and reading the response // body. The timer remains running after Get, Head, Post, or Do return and // will interrupt reading of the Response.Body. HTTPTimeout = 10 * time.Second // AuthenticationTimeout is the time limit for authentication requests to // complete. It should be longer than the HTTPTimeout. AuthenticationTimeout = 20 * time.Second // DefaultRequestTimeout is the default time limit for api requests to // complete. It should be longer than the HTTPTimeout. DefaultRequestTimeout = 20 * time.Second )
var ( // ErrNamespaceNotFound is returned if a namespace was provided but it was not found. ErrNamespaceNotFound = errors.New("namespace not found") // ErrNotFound is returned if a volume was provided but it was not found. ErrNotFound = errors.New("volume not found") ErrNotShared = errors.New("volume not shared") // ErrNotKubernetes is returned if a volume was not created by the // Kubernetes volume provisioner. This is required as the provisioner adds // labels to the volume that allows it to be traced back to the PVC. // Without the link to the PVC, we can't tell if the volume was created as // RWX and we can set the PVC as the OwnerReference, allowing cleanup on // PVC delete. ErrNotKubernetes = errors.New("volume not created by kubernetes") ErrVolumeShared = errors.New("volume is shared") // ErrListingVolumes can be returned if there was an error listing volumes. ErrListingVolumes = errors.New("failed to list volumes") )
Functions ¶
func Authenticate ¶
Authenticate against the API and set the authentication token in the client to be used for subsequent API requests. The token must be refreshed periodically using AuthenticateRefresh().
func GetAPIErrorResponse ¶
GetAPIErrorResponse returns the actual API response error incl. the response Body.
func GetAPIErrorRootCause ¶
GetAPIErrorRootCause attempts to unwrap the error to isolate the root cause, without decoration from the chain of calling functions.
The list of error types evaluated is somewhat arbitrary: we want to capture things like:
- `connect: connection refused` - `401 Unauthorized`
But not:
- `Get http://storageos:5705/v2/namespaces: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)`
Some errors could be unwrapped even further, but after a certain level the detail no longer makes sense. This is purely subjective.
Callers should not rely on specific errors being returned as they are subject to fine-tuning.
func ReadCredsFromMountedSecret ¶
ReadCredsFromMountedSecret reads the api username and password from a Kubernetes secret mounted at the given path. If the username or password in the secret changes, the data in the mounted file will also change.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides access to the StorageOS API.
func New ¶
New returns a pre-authenticated client for the StorageOS API. The authentication token must be refreshed periodically using AuthenticateRefresh().
func NewTracedClient ¶
NewTracedClient returns a pre-authenticated client for the StorageOS API that has tracing enabled. The authentication token must be refreshed periodically using AuthenticateRefresh().
func (*Client) AddToken ¶ added in v1.0.2
AddToken adds the current authentication token to a given context.
func (*Client) ListSharedVolumes ¶
func (c *Client) ListSharedVolumes() (SharedVolumeList, error)
ListSharedVolumes returns a list of active shared volumes.
func (*Client) Refresh ¶
func (c *Client) Refresh(ctx context.Context, secretPath string, reset chan struct{}, interval time.Duration, resultCounter metrics.ResultMetric, log logr.Logger) error
Refresh the api token on a given interval, or reset is received on the reset channel. This function is blocking and is intended to be run in a goroutine. Errors are currently logged at info level since they will be retried and should be recoverable. Only a cancelled context will cause this to stop. Be aware that any errors returned will trigger a process shutdown.
type ControlPlane ¶ added in v1.0.2
type ControlPlane interface {
RefreshJwt(ctx context.Context) (api.UserSession, *http.Response, error)
AuthenticateUser(ctx context.Context, authUserData api.AuthUserData) (api.UserSession, *http.Response, error)
ListNamespaces(ctx context.Context) ([]api.Namespace, *http.Response, error)
DeleteNamespace(ctx context.Context, id string, version string, localVarOptionals *api.DeleteNamespaceOpts) (*http.Response, error)
ListNodes(ctx context.Context) ([]api.Node, *http.Response, error)
UpdateNode(ctx context.Context, id string, updateNodeData api.UpdateNodeData, localVarOptionals *api.UpdateNodeOpts) (api.Node, *http.Response, error)
DeleteNode(ctx context.Context, id string, version string, localVarOptionals *api.DeleteNodeOpts) (*http.Response, error)
// SetComputeOnly(ctx context.Context, id string, setComputeOnlyNodeData api.SetComputeOnlyNodeData, localVarOptionals *api.SetComputeOnlyOpts) (api.Node, *http.Response, error)
ListVolumes(ctx context.Context, namespaceID string) ([]api.Volume, *http.Response, error)
GetVolume(ctx context.Context, namespaceID string, id string) (api.Volume, *http.Response, error)
UpdateVolume(ctx context.Context, namespaceID string, id string, updateVolumeData api.UpdateVolumeData, localVarOptionals *api.UpdateVolumeOpts) (api.Volume, *http.Response, error)
SetReplicas(ctx context.Context, namespaceID string, id string, setReplicasRequest api.SetReplicasRequest, localVarOptionals *api.SetReplicasOpts) (api.AcceptedMessage, *http.Response, error)
UpdateNFSVolumeMountEndpoint(ctx context.Context, namespaceID string, id string, nfsVolumeMountEndpoint api.NfsVolumeMountEndpoint, localVarOptionals *api.UpdateNFSVolumeMountEndpointOpts) (*http.Response, error)
}
ControlPlane is the subset of the StorageOS control plane ControlPlane that api-manager requires. New methods should be added here as needed, then the mocks regenerated.
type MockClient ¶
type MockClient struct {
SetEndpointErr error
// contains filtered or unexported fields
}
MockClient provides a test interface to the StorageOS api.
func (*MockClient) Delete ¶
func (c *MockClient) Delete(id string, namespace string)
Delete a shared volume.
func (*MockClient) Get ¶
func (c *MockClient) Get(id string, namespace string) (*SharedVolume, error)
Get returns a SharedVolume.
func (*MockClient) ListSharedVolumes ¶
func (c *MockClient) ListSharedVolumes() (SharedVolumeList, error)
ListSharedVolumes returns a list of active shared volumes.
func (*MockClient) RandomVol ¶
func (c *MockClient) RandomVol() *SharedVolume
RandomVol returns a randomly generated shared volume. Always uses default namespace since it will always exist.
func (*MockClient) Set ¶
func (c *MockClient) Set(v *SharedVolume) *SharedVolume
Set adds or replaces a shared volume, and also returns it.
func (*MockClient) SetExternalEndpoint ¶
func (c *MockClient) SetExternalEndpoint(id string, namespace string, endpoint string) error
SetExternalEndpoint sets the external endpoint on a SharedVolume. The endpoint should be <host|ip>:<port>.
type SharedVolume ¶
type SharedVolume struct {
}
SharedVolume represents a single StorageOS shared volume.
func NewSharedVolume ¶
func NewSharedVolume(id, pvName, pvcName, pvcNamespace, intEndpoint, extEndpoint string) *SharedVolume
NewSharedVolume returns a sharedvolume object.
func (*SharedVolume) Endpoints ¶
func (v *SharedVolume) Endpoints() *corev1.Endpoints
Endpoints returns the desired endpoints corresponding to the SharedVolume.
func (*SharedVolume) EndpointsIsEqual ¶
func (v *SharedVolume) EndpointsIsEqual(e *corev1.Endpoints) bool
EndpointsIsEqual returns true if the endpoints provided matches the desired state of the SharedVolume.
func (*SharedVolume) EndpointsUpdate ¶
func (v *SharedVolume) EndpointsUpdate(e *corev1.Endpoints) *corev1.Endpoints
EndpointsUpdate returns the provided endpoints, with updates to match the SharedVolume.
func (*SharedVolume) InternalAddress ¶
func (v *SharedVolume) InternalAddress() string
InternalAddress returns the address of the intenral SharedVolume listener.
func (*SharedVolume) InternalPort ¶
func (v *SharedVolume) InternalPort() int
InternalPort returns the port of the intenral SharedVolume listener.
func (*SharedVolume) IsEqual ¶
func (v *SharedVolume) IsEqual(obj *SharedVolume) bool
IsEqual returns true if the given SharedVolume object is equivalent.
func (*SharedVolume) Service ¶
func (v *SharedVolume) Service(ownerRef metav1.OwnerReference) *corev1.Service
Service returns the desired service corresponding to the SharedVolume. ClusterIP can be provided if an existing ClusterIP should be re-used. The ownerRef must be set to the volume's PersistentVolumeClaim.
func (*SharedVolume) ServiceIsEqual ¶
func (v *SharedVolume) ServiceIsEqual(svc *corev1.Service) bool
ServiceIsEqual returns true if the service provided matches the desired state of the SharedVolume.
func (*SharedVolume) ServiceUpdate ¶
func (v *SharedVolume) ServiceUpdate(svc *corev1.Service) *corev1.Service
ServiceUpdate returns the provided service, with updates to match the SharedVolume.
type SharedVolumeList ¶
type SharedVolumeList []*SharedVolume
SharedVolumeList is a collection of SharedVolumes.