Documentation ¶
Index ¶
- Constants
- Variables
- func GetK8SCache() (cache.Cache, error)
- func GetK8SClient() (k8sCl.Client, error)
- func GetK8SClientset() (*kubernetes.Clientset, error)
- func PrepareScheme() (*runtime.Scheme, error)
- type CRHelper
- type CRHelperImpl
- func (cs *CRHelperImpl) DeleteACsByNodeID(nodeID string) error
- func (cs *CRHelperImpl) DeleteObjectByName(ctx context.Context, name string, namespace string, obj k8sCl.Object) error
- func (cs *CRHelperImpl) GetACByLocation(location string) (*accrd.AvailableCapacity, error)
- func (cs *CRHelperImpl) GetACCRs(node ...string) ([]accrd.AvailableCapacity, error)
- func (cs *CRHelperImpl) GetDriveCRAndLVGCRByVolume(volume *volumecrd.Volume) (*drivecrd.Drive, *lvgcrd.LogicalVolumeGroup, error)
- func (cs *CRHelperImpl) GetDriveCRByVolume(volume *volumecrd.Volume) (*drivecrd.Drive, error)
- func (cs *CRHelperImpl) GetDriveCRs(node ...string) ([]drivecrd.Drive, error)
- func (cs *CRHelperImpl) GetLVGByDrive(ctx context.Context, driveUUID string) (*lvgcrd.LogicalVolumeGroup, error)
- func (cs *CRHelperImpl) GetLVGCRs(node ...string) ([]lvgcrd.LogicalVolumeGroup, error)
- func (cs *CRHelperImpl) GetVGNameByLVGCRName(lvgCRName string) (string, error)
- func (cs *CRHelperImpl) GetVolumeByID(volID string) (*volumecrd.Volume, error)
- func (cs *CRHelperImpl) GetVolumeCRs(node ...string) ([]volumecrd.Volume, error)
- func (cs *CRHelperImpl) GetVolumesByLocation(ctx context.Context, location string) ([]*volumecrd.Volume, error)
- func (cs *CRHelperImpl) SetReader(reader CRReader) CRHelper
- func (cs *CRHelperImpl) UpdateDrivesStatusOnNode(nodeID, status string) error
- func (cs *CRHelperImpl) UpdateVolumeCRSpec(volName string, namespace string, newSpec api.Volume) error
- func (cs *CRHelperImpl) UpdateVolumeOpStatus(ctx context.Context, volume *volumecrd.Volume, opStatus string) error
- func (cs *CRHelperImpl) UpdateVolumesOpStatusOnNode(nodeID, opStatus string) error
- type CRReader
- type CtxKey
- type FakeClientWrapper
- func (fkw *FakeClientWrapper) Create(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.CreateOption) error
- func (fkw *FakeClientWrapper) Delete(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.DeleteOption) error
- func (fkw *FakeClientWrapper) DeleteAllOf(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.DeleteAllOfOption) error
- func (fkw *FakeClientWrapper) Get(ctx context.Context, key k8sCl.ObjectKey, obj k8sCl.Object, ...) error
- func (fkw *FakeClientWrapper) GroupVersionKindFor(obj runtime.Object) (gvk schema.GroupVersionKind, err error)
- func (fkw *FakeClientWrapper) IsObjectNamespaced(obj runtime.Object) (bool, error)
- func (fkw *FakeClientWrapper) List(ctx context.Context, list k8sCl.ObjectList, opts ...k8sCl.ListOption) error
- func (fkw *FakeClientWrapper) Patch(ctx context.Context, obj k8sCl.Object, patch k8sCl.Patch, ...) error
- func (fkw *FakeClientWrapper) RESTMapper() meta.RESTMapper
- func (fkw *FakeClientWrapper) Scheme() *runtime.Scheme
- func (fkw *FakeClientWrapper) Status() k8sCl.StatusWriter
- func (fkw *FakeClientWrapper) SubResource(subresource string) k8sCl.SubResourceClient
- func (fkw *FakeClientWrapper) Update(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.UpdateOption) error
- type KubeCache
- type KubeClient
- func (k *KubeClient) ConstructACCR(name string, apiAC api.AvailableCapacity) *accrd.AvailableCapacity
- func (k *KubeClient) ConstructACRCR(name string, apiACR api.AvailableCapacityReservation) *acrcrd.AvailableCapacityReservation
- func (k *KubeClient) ConstructCSIBMNodeCR(name string, csiNode api.Node) *nodecrd.Node
- func (k *KubeClient) ConstructDriveCR(name string, apiDrive api.Drive) *drivecrd.Drive
- func (k *KubeClient) ConstructLVGCR(name, storageGroup string, apiLVG api.LogicalVolumeGroup) *lvgcrd.LogicalVolumeGroup
- func (k *KubeClient) ConstructVolumeCR(name, namespace string, labels map[string]string, apiVolume api.Volume) *volumecrd.Volume
- func (k *KubeClient) CreateCR(ctx context.Context, name string, obj k8sCl.Object) error
- func (k *KubeClient) DeleteCR(ctx context.Context, obj k8sCl.Object) error
- func (k *KubeClient) GetNodes(ctx context.Context) ([]coreV1.Node, error)
- func (k *KubeClient) GetPods(ctx context.Context, mask string) ([]*coreV1.Pod, error)
- func (k *KubeClient) GetSystemDriveUUIDs() []string
- func (k *KubeClient) ReadCR(ctx context.Context, name string, namespace string, obj k8sCl.Object) error
- func (k *KubeClient) ReadList(ctx context.Context, obj k8sCl.ObjectList) error
- func (k *KubeClient) UpdateCR(ctx context.Context, obj k8sCl.Object) error
Constants ¶
const ( // DefaultVolumeID is the constant to avoid linter error DefaultVolumeID = "Unknown" // TickerStep is the time between attempts to interact with Volume CR TickerStep = 500 * time.Millisecond // AppLabelKey matches CSI CRs with csi-baremetal app AppLabelKey = "app.kubernetes.io/name" // AppLabelShortKey matches CSI CRs with csi-baremetal app AppLabelShortKey = "app" // ReleaseLabelKey matches CSI CRs with the helm release ReleaseLabelKey = "release" // AppLabelValue matches CSI CRs with csi-baremetal app AppLabelValue = "csi-baremetal" )
Variables ¶
var ( // UpdateFailCtx raises an error on fakeClient.Update UpdateFailCtx = context.WithValue(context.Background(), updateFailCtxKey, updateFailCtxValue) // ListFailCtx raises an error on fakeClient.List ListFailCtx = context.WithValue(context.Background(), listFailCtxKey, listFailCtxValue) // GetFailCtx raises an error on fakeClient.Get GetFailCtx = context.WithValue(context.Background(), getFailCtxKey, getFailCtxValue) // DeleteFailCtx raises an error on fakeClient.Get DeleteFailCtx = context.WithValue(context.Background(), deleteFailCtxKey, deleteFailCtxValue) )
Functions ¶
func GetK8SClient ¶
GetK8SClient returns controller-runtime k8s client with modified scheme which includes CSI custom resources Returns controller-runtime/pkg/Client which can work with CSI CRs or error if something went wrong
func GetK8SClientset ¶
func GetK8SClientset() (*kubernetes.Clientset, error)
GetK8SClientset gets in-cluster k8s clientset
func PrepareScheme ¶
PrepareScheme registers CSI custom resources to runtime.Scheme Returns modified runtime.Scheme or error if something went wrong
Types ¶
type CRHelper ¶
type CRHelper interface { SetReader(reader CRReader) CRHelper GetACByLocation(location string) (*accrd.AvailableCapacity, error) DeleteACsByNodeID(nodeID string) error GetVolumesByLocation(ctx context.Context, location string) ([]*volumecrd.Volume, error) GetLVGByDrive(ctx context.Context, driveUUID string) (*lvgcrd.LogicalVolumeGroup, error) UpdateVolumesOpStatusOnNode(nodeID, opStatus string) error GetVolumeByID(volID string) (*volumecrd.Volume, error) GetVolumeCRs(node ...string) ([]volumecrd.Volume, error) UpdateDrivesStatusOnNode(nodeID, status string) error GetDriveCRs(node ...string) ([]drivecrd.Drive, error) GetACCRs(node ...string) ([]accrd.AvailableCapacity, error) GetDriveCRByVolume(volume *volumecrd.Volume) (*drivecrd.Drive, error) GetDriveCRAndLVGCRByVolume(volume *volumecrd.Volume) (*drivecrd.Drive, *lvgcrd.LogicalVolumeGroup, error) GetVGNameByLVGCRName(lvgCRName string) (string, error) GetLVGCRs(node ...string) ([]lvgcrd.LogicalVolumeGroup, error) UpdateVolumeCRSpec(volName string, namespace string, newSpec api.Volume) error DeleteObjectByName(ctx context.Context, name string, namespace string, obj k8sCl.Object) error UpdateVolumeOpStatus(ctx context.Context, volume *volumecrd.Volume, opStatus string) error }
CRHelper is holds idempotent methods that consists of WrapFS methods
type CRHelperImpl ¶ added in v1.3.0
type CRHelperImpl struct {
// contains filtered or unexported fields
}
CRHelperImpl is implementation of CRHelper
func NewCRHelperImpl ¶ added in v1.3.0
func NewCRHelperImpl(k *KubeClient, logger *logrus.Logger) *CRHelperImpl
NewCRHelperImpl is a constructor for CRHelperImpl instance
func (*CRHelperImpl) DeleteACsByNodeID ¶ added in v1.3.0
func (cs *CRHelperImpl) DeleteACsByNodeID(nodeID string) error
DeleteACsByNodeID deletes AC CRs for specific node ID Receives unique identifier of the node Returns error or nil
func (*CRHelperImpl) DeleteObjectByName ¶ added in v1.3.0
func (cs *CRHelperImpl) DeleteObjectByName(ctx context.Context, name string, namespace string, obj k8sCl.Object) error
DeleteObjectByName read runtime.Object by its name and then delete it
func (*CRHelperImpl) GetACByLocation ¶ added in v1.3.0
func (cs *CRHelperImpl) GetACByLocation(location string) (*accrd.AvailableCapacity, error)
GetACByLocation reads the whole list of AC CRs from a cluster and searches the AC with provided location Receive context and location name which should be equal to AvailableCapacity.Spec.Location Returns a pointer to the instance of accrd.AvailableCapacity or nil
func (*CRHelperImpl) GetACCRs ¶ added in v1.3.0
func (cs *CRHelperImpl) GetACCRs(node ...string) ([]accrd.AvailableCapacity, error)
GetACCRs collect ACs CR that locate on node, use just node[0] element if node isn't provided - return all ACs CR if error occurs - return nil and error
func (*CRHelperImpl) GetDriveCRAndLVGCRByVolume ¶ added in v1.3.0
func (cs *CRHelperImpl) GetDriveCRAndLVGCRByVolume(volume *volumecrd.Volume) (*drivecrd.Drive, *lvgcrd.LogicalVolumeGroup, error)
GetDriveCRAndLVGCRByVolume reads drive CRs and returns CR for drive and CR for lvg (if exist) on which volume is located
func (*CRHelperImpl) GetDriveCRByVolume ¶ added in v1.3.0
GetDriveCRByVolume reads drive CRs and returns CR for drive on which volume is located
func (*CRHelperImpl) GetDriveCRs ¶ added in v1.3.0
func (cs *CRHelperImpl) GetDriveCRs(node ...string) ([]drivecrd.Drive, error)
GetDriveCRs collect Drives CR that locate on node, use just node[0] element if node isn't provided - return all Drives CR if error occurs - return nil and error
func (*CRHelperImpl) GetLVGByDrive ¶ added in v1.3.0
func (cs *CRHelperImpl) GetLVGByDrive(ctx context.Context, driveUUID string) (*lvgcrd.LogicalVolumeGroup, error)
GetLVGByDrive reads list of LogicalVolumeGroup CRs from a cluster and searches the lvg with provided location Receives golang context and drive uuid Returns found lvg and error
func (*CRHelperImpl) GetLVGCRs ¶ added in v1.3.0
func (cs *CRHelperImpl) GetLVGCRs(node ...string) ([]lvgcrd.LogicalVolumeGroup, error)
GetLVGCRs collect LogicalVolumeGroup CRs that locate on node, use just node[0] element if node isn't provided - return all volume CRs if error occurs - return nil
func (*CRHelperImpl) GetVGNameByLVGCRName ¶ added in v1.3.0
func (cs *CRHelperImpl) GetVGNameByLVGCRName(lvgCRName string) (string, error)
GetVGNameByLVGCRName read LogicalVolumeGroup CR with name lvgCRName and returns LogicalVolumeGroup CR.Spec.Name method is used for LogicalVolumeGroup based on system VG because system VG name != LogicalVolumeGroup CR name in case of error returns empty string and error
func (*CRHelperImpl) GetVolumeByID ¶ added in v1.3.0
func (cs *CRHelperImpl) GetVolumeByID(volID string) (*volumecrd.Volume, error)
GetVolumeByID reads volume CRs and returns volumes CR if it .Spec.Id == volId
func (*CRHelperImpl) GetVolumeCRs ¶ added in v1.3.0
func (cs *CRHelperImpl) GetVolumeCRs(node ...string) ([]volumecrd.Volume, error)
GetVolumeCRs collect volume CRs that locate on node, use just node[0] element if node isn't provided - return all volume CRs if error occurs - return nil and error
func (*CRHelperImpl) GetVolumesByLocation ¶ added in v1.3.0
func (cs *CRHelperImpl) GetVolumesByLocation(ctx context.Context, location string) ([]*volumecrd.Volume, error)
GetVolumesByLocation reads the whole list of Volume CRs from a cluster and searches the volume with provided location Receives golang context and location name which should be equal to Volume.Spec.Location Returns a list of a pointers to volumes which are belong to the location and error
func (*CRHelperImpl) SetReader ¶ added in v1.3.0
func (cs *CRHelperImpl) SetReader(reader CRReader) CRHelper
SetReader allow to set separate CRReader for CRHelper, by default k8sClient will be used
func (*CRHelperImpl) UpdateDrivesStatusOnNode ¶ added in v1.3.0
func (cs *CRHelperImpl) UpdateDrivesStatusOnNode(nodeID, status string) error
UpdateDrivesStatusOnNode updates status of drives on a node without taking into account current state Receives unique identifier of the node and status to be set Returns error or nil
func (*CRHelperImpl) UpdateVolumeCRSpec ¶ added in v1.3.0
func (cs *CRHelperImpl) UpdateVolumeCRSpec(volName string, namespace string, newSpec api.Volume) error
UpdateVolumeCRSpec reads volume CR with name volName and update it's spec to newSpec returns nil or error in case of error
func (*CRHelperImpl) UpdateVolumeOpStatus ¶ added in v1.3.0
func (cs *CRHelperImpl) UpdateVolumeOpStatus(ctx context.Context, volume *volumecrd.Volume, opStatus string) error
UpdateVolumeOpStatus Update volume Operational status to opStatus returns nil or error in case of error
func (*CRHelperImpl) UpdateVolumesOpStatusOnNode ¶ added in v1.3.0
func (cs *CRHelperImpl) UpdateVolumesOpStatusOnNode(nodeID, opStatus string) error
UpdateVolumesOpStatusOnNode updates operational status of volumes on a node without taking into account current state Receives unique identifier of the node and operational status to be set Returns error or nil
type CRReader ¶
type CRReader interface { // ReadCR reads CR ReadCR(ctx context.Context, name string, namespace string, obj k8sCl.Object) error // ReadList reads CR list ReadList(ctx context.Context, obj k8sCl.ObjectList) error }
CRReader is a reader interface for k8s client wrapper
type FakeClientWrapper ¶
type FakeClientWrapper struct {
// contains filtered or unexported fields
}
FakeClientWrapper wrapper for k8s fake client required because behaviour of real kube client and fake are different real client will return resources with Cluster scope even if namespaced request was sent fake client doesn't know about scope for resources, so it will search for resources with Cluster scope in namespace, which was submitted in request
func NewFakeClientWrapper ¶
func NewFakeClientWrapper(client k8sCl.Client, scheme *runtime.Scheme) *FakeClientWrapper
NewFakeClientWrapper return new instance of FakeClientWrapper
func (*FakeClientWrapper) Create ¶
func (fkw *FakeClientWrapper) Create(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.CreateOption) error
Create is a wrapper around Create method
func (*FakeClientWrapper) Delete ¶
func (fkw *FakeClientWrapper) Delete(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.DeleteOption) error
Delete is a wrapper around Delete method
func (*FakeClientWrapper) DeleteAllOf ¶
func (fkw *FakeClientWrapper) DeleteAllOf(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.DeleteAllOfOption) error
DeleteAllOf is a wrapper around DeleteAllOf method
func (*FakeClientWrapper) Get ¶
func (fkw *FakeClientWrapper) Get(ctx context.Context, key k8sCl.ObjectKey, obj k8sCl.Object, opts ...k8sCl.GetOption) error
Get is a wrapper around Get method
func (*FakeClientWrapper) GroupVersionKindFor ¶ added in v1.7.0
func (fkw *FakeClientWrapper) GroupVersionKindFor(obj runtime.Object) (gvk schema.GroupVersionKind, err error)
GroupVersionKindFor is a wrapper around GroupVersionKindFor method
func (*FakeClientWrapper) IsObjectNamespaced ¶ added in v1.7.0
func (fkw *FakeClientWrapper) IsObjectNamespaced(obj runtime.Object) (bool, error)
IsObjectNamespaced is a wrapper around IsObjectNamespaced method
func (*FakeClientWrapper) List ¶
func (fkw *FakeClientWrapper) List(ctx context.Context, list k8sCl.ObjectList, opts ...k8sCl.ListOption) error
List is a wrapper around List method
func (*FakeClientWrapper) Patch ¶
func (fkw *FakeClientWrapper) Patch(ctx context.Context, obj k8sCl.Object, patch k8sCl.Patch, opts ...k8sCl.PatchOption) error
Patch is a wrapper around Patch method
func (*FakeClientWrapper) RESTMapper ¶ added in v1.3.0
func (fkw *FakeClientWrapper) RESTMapper() meta.RESTMapper
RESTMapper is a wrapper around RESTMapper should return the rest this client is using, but not need in fake implementation
func (*FakeClientWrapper) Scheme ¶ added in v1.3.0
func (fkw *FakeClientWrapper) Scheme() *runtime.Scheme
Scheme is a wrapper around Scheme method
func (*FakeClientWrapper) Status ¶
func (fkw *FakeClientWrapper) Status() k8sCl.StatusWriter
Status is a wrapper around Status method
func (*FakeClientWrapper) SubResource ¶ added in v1.7.0
func (fkw *FakeClientWrapper) SubResource(subresource string) k8sCl.SubResourceClient
SubResource is a wrapper around SubResource method
func (*FakeClientWrapper) Update ¶
func (fkw *FakeClientWrapper) Update(ctx context.Context, obj k8sCl.Object, opts ...k8sCl.UpdateOption) error
Update is a wrapper around Update method
type KubeCache ¶
KubeCache is a wrapper for controller-runtime cache
func InitKubeCache ¶
func InitKubeCache(stopCH context.Context, logger *logrus.Logger, objects ...k8sCl.Object) (*KubeCache, error)
InitKubeCache creates and starts KubeCache, if objects passed the function will block until cache synced for these objects
func NewKubeCache ¶
NewKubeCache is the constructor for KubeCache struct Receives basic reader from controller-runtime, logrus logger Returns an instance of KubeCache struct
type KubeClient ¶
KubeClient is the extension of k8s client which supports CSI custom recources
func GetFakeKubeClient ¶
func GetFakeKubeClient(testNs string, logger *logrus.Logger) (*KubeClient, error)
GetFakeKubeClient returns fake KubeClient for test purposes Receives namespace to work Returns instance of mocked KubeClient or error if something went wrong TODO: test code shouldn't be in base package - https://github.com/dell/csi-baremetal/issues/81
func NewKubeClient ¶
func NewKubeClient(k8sclient k8sCl.Client, logger *logrus.Logger, objectsLogger objects.ObjectLogger, namespace string) *KubeClient
NewKubeClient is the constructor for KubeClient struct Receives basic k8s client from controller-runtime, logrus logger and namespace where to work Returns an instance of KubeClient struct
func (*KubeClient) ConstructACCR ¶
func (k *KubeClient) ConstructACCR(name string, apiAC api.AvailableCapacity) *accrd.AvailableCapacity
ConstructACCR constructs AvailableCapacity custom resource from api.AvailableCapacity struct Receives a name for k8s ObjectMeta and an instance of api.AvailableCapacity struct Returns an instance of AvailableCapacity CR struct
func (*KubeClient) ConstructACRCR ¶
func (k *KubeClient) ConstructACRCR(name string, apiACR api.AvailableCapacityReservation) *acrcrd.AvailableCapacityReservation
ConstructACRCR constructs AvailableCapacityReservation custom resource from api.AvailableCapacityReservation struct Receives name and instance of api.AvailableCapacityReservation struct Returns pointer on AvailableCapacityReservation CR struct
func (*KubeClient) ConstructCSIBMNodeCR ¶
ConstructCSIBMNodeCR constructs Node custom resource from api.Node struct Receives a name for k8s ObjectMeta and an instance of api.Node struct Returns an instance of Node CR struct
func (*KubeClient) ConstructDriveCR ¶
ConstructDriveCR constructs Drive custom resource from api.Drive struct Receives a name for k8s ObjectMeta and an instance of api.Drive struct Returns an instance of Drive CR struct
func (*KubeClient) ConstructLVGCR ¶
func (k *KubeClient) ConstructLVGCR(name, storageGroup string, apiLVG api.LogicalVolumeGroup) *lvgcrd.LogicalVolumeGroup
ConstructLVGCR constructs LogicalVolumeGroup custom resource from api.LogicalVolumeGroup struct Receives a name for k8s ObjectMeta and an instance of api.LogicalVolumeGroup struct Returns an instance of LogicalVolumeGroup CR struct
func (*KubeClient) ConstructVolumeCR ¶
func (k *KubeClient) ConstructVolumeCR(name, namespace string, labels map[string]string, apiVolume api.Volume) *volumecrd.Volume
ConstructVolumeCR constructs Volume custom resource from api.Volume struct Receives a name for k8s ObjectMeta and an instance of api.Volume struct Returns an instance of Volume CR struct
func (*KubeClient) CreateCR ¶
CreateCR creates provided resource on k8s cluster with checking its existence before Receives golang context, name of the created object, and object that implements k8s runtime.Object interface Returns error if something went wrong
func (*KubeClient) DeleteCR ¶
DeleteCR deletes provided resource from k8s cluster Receives golang context and removable object that implements k8s runtime.Object interface Returns error if something went wrong
func (*KubeClient) GetNodes ¶
GetNodes returns list of nodes Receives golang context Returns slice of coreV1.Node or error if something went wrong
func (*KubeClient) GetPods ¶
GetPods returns list of pods which names contain mask Receives golang context and mask for pods filtering Returns slice of coreV1.Pod or error if something went wrong todo use labels instead of mask
func (*KubeClient) GetSystemDriveUUIDs ¶
func (k *KubeClient) GetSystemDriveUUIDs() []string
GetSystemDriveUUIDs returns system drives uuid Receives golang context Returns return slice of string - system drives uuids
func (*KubeClient) ReadCR ¶
func (k *KubeClient) ReadCR(ctx context.Context, name string, namespace string, obj k8sCl.Object) error
ReadCR reads specified resource from k8s cluster into a pointer of struct that implements runtime.Object Receives golang context, name of the read object, and object pointer where to read Returns error if something went wrong
func (*KubeClient) ReadList ¶
func (k *KubeClient) ReadList(ctx context.Context, obj k8sCl.ObjectList) error
ReadList reads a list of specified resources into k8s resource List struct (for example v1.PodList) Receives golang context, and List object pointer where to read Returns error if something went wrong