Documentation ¶
Index ¶
- Constants
- func GetK8SCache() (cache.Cache, error)
- func GetK8SClient() (k8sCl.Client, error)
- func GetK8SClientset() (*kubernetes.Clientset, error)
- func PrepareScheme() (*runtime.Scheme, error)
- type CRHelper
- func (cs *CRHelper) DeleteACsByNodeID(nodeID string) error
- func (cs *CRHelper) DeleteObjectByName(ctx context.Context, name string, namespace string, obj runtime.Object) error
- func (cs *CRHelper) GetACByLocation(location string) (*accrd.AvailableCapacity, error)
- func (cs *CRHelper) GetACCRs(node ...string) ([]accrd.AvailableCapacity, error)
- func (cs *CRHelper) GetDriveCRByUUID(dUUID string) *drivecrd.Drive
- func (cs *CRHelper) GetDriveCRByVolume(volume *volumecrd.Volume) (*drivecrd.Drive, error)
- func (cs *CRHelper) GetDriveCRs(node ...string) ([]drivecrd.Drive, error)
- func (cs *CRHelper) GetLVGByDrive(ctx context.Context, driveUUID string) (*lvgcrd.LogicalVolumeGroup, error)
- func (cs *CRHelper) GetLVGCRs(node ...string) ([]lvgcrd.LogicalVolumeGroup, error)
- func (cs *CRHelper) GetVGNameByLVGCRName(lvgCRName string) (string, error)
- func (cs *CRHelper) GetVolumeByID(volID string) (*volumecrd.Volume, error)
- func (cs *CRHelper) GetVolumeCRs(node ...string) ([]volumecrd.Volume, error)
- func (cs *CRHelper) GetVolumesByLocation(ctx context.Context, location string) ([]*volumecrd.Volume, error)
- func (cs *CRHelper) SetReader(reader CRReader) *CRHelper
- func (cs *CRHelper) UpdateDrivesStatusOnNode(nodeID, status string) error
- func (cs *CRHelper) UpdateVolumeCRSpec(volName string, namespace string, newSpec api.Volume) error
- func (cs *CRHelper) UpdateVolumeOpStatus(ctx context.Context, volume *volumecrd.Volume, opStatus string) error
- func (cs *CRHelper) UpdateVolumesOpStatusOnNode(nodeID, opStatus string) error
- type CRReader
- type CtxKey
- type FakeClientWrapper
- func (fkw *FakeClientWrapper) Create(ctx context.Context, obj runtime.Object, opts ...k8sCl.CreateOption) error
- func (fkw *FakeClientWrapper) Delete(ctx context.Context, obj runtime.Object, opts ...k8sCl.DeleteOption) error
- func (fkw *FakeClientWrapper) DeleteAllOf(ctx context.Context, obj runtime.Object, opts ...k8sCl.DeleteAllOfOption) error
- func (fkw *FakeClientWrapper) Get(ctx context.Context, key k8sCl.ObjectKey, obj runtime.Object) error
- func (fkw *FakeClientWrapper) List(ctx context.Context, list runtime.Object, opts ...k8sCl.ListOption) error
- func (fkw *FakeClientWrapper) Patch(ctx context.Context, obj runtime.Object, patch k8sCl.Patch, ...) error
- func (fkw *FakeClientWrapper) Status() k8sCl.StatusWriter
- func (fkw *FakeClientWrapper) Update(ctx context.Context, obj runtime.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 string, apiLVG api.LogicalVolumeGroup) *lvgcrd.LogicalVolumeGroup
- func (k *KubeClient) ConstructVolumeCR(name, namespace, appName string, apiVolume api.Volume) *volumecrd.Volume
- func (k *KubeClient) CreateCR(ctx context.Context, name string, obj runtime.Object) error
- func (k *KubeClient) DeleteCR(ctx context.Context, obj runtime.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 runtime.Object) error
- func (k *KubeClient) ReadCRWithAttempts(name string, namespace string, obj runtime.Object, attempts int) error
- func (k *KubeClient) ReadList(ctx context.Context, obj runtime.Object) error
- func (k *KubeClient) UpdateCR(ctx context.Context, obj runtime.Object) error
- func (k *KubeClient) UpdateCRWithAttempts(ctx context.Context, obj runtime.Object, attempts int) 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" // AppLabelValue matches CSI CRs with csi-baremetal app AppLabelValue = "csi-baremetal" )
Variables ¶
This section is empty.
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 struct {
// contains filtered or unexported fields
}
CRHelper is able to collect different CRs by different criteria
func NewCRHelper ¶
func NewCRHelper(k *KubeClient, logger *logrus.Logger) *CRHelper
NewCRHelper is a constructor for CRHelper instance
func (*CRHelper) DeleteACsByNodeID ¶
DeleteACsByNodeID deletes AC CRs for specific node ID Receives unique identifier of the node Returns error or nil
func (*CRHelper) DeleteObjectByName ¶
func (cs *CRHelper) DeleteObjectByName(ctx context.Context, name string, namespace string, obj runtime.Object) error
DeleteObjectByName read runtime.Object by its name and then delete it
func (*CRHelper) GetACByLocation ¶
func (cs *CRHelper) 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 (*CRHelper) GetACCRs ¶
func (cs *CRHelper) 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 (*CRHelper) GetDriveCRByUUID ¶
GetDriveCRByUUID reads drive CRs and returns drive CR with uuid dUUID
func (*CRHelper) GetDriveCRByVolume ¶
GetDriveCRByVolume reads drive CRs and returns CR for drive on which volume is located
func (*CRHelper) GetDriveCRs ¶
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 (*CRHelper) GetLVGByDrive ¶
func (cs *CRHelper) 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 (*CRHelper) GetLVGCRs ¶
func (cs *CRHelper) 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 (*CRHelper) GetVGNameByLVGCRName ¶
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 (*CRHelper) GetVolumeByID ¶
GetVolumeByID reads volume CRs and returns volumes CR if it .Spec.Id == volId
func (*CRHelper) GetVolumeCRs ¶
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 (*CRHelper) GetVolumesByLocation ¶
func (cs *CRHelper) 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 (*CRHelper) SetReader ¶
SetReader allow to set separate CRReader for CRHelper, by default k8sClient will be used
func (*CRHelper) UpdateDrivesStatusOnNode ¶
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 (*CRHelper) UpdateVolumeCRSpec ¶
UpdateVolumeCRSpec reads volume CR with name volName and update it's spec to newSpec returns nil or error in case of error
func (*CRHelper) UpdateVolumeOpStatus ¶
func (cs *CRHelper) 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 (*CRHelper) UpdateVolumesOpStatusOnNode ¶
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 runtime.Object) error // ReadList reads CR list ReadList(ctx context.Context, obj runtime.Object) 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 runtime.Object, opts ...k8sCl.CreateOption) error
Create is a wrapper around Create method
func (*FakeClientWrapper) Delete ¶
func (fkw *FakeClientWrapper) Delete(ctx context.Context, obj runtime.Object, opts ...k8sCl.DeleteOption) error
Delete is a wrapper around Delete method
func (*FakeClientWrapper) DeleteAllOf ¶
func (fkw *FakeClientWrapper) DeleteAllOf(ctx context.Context, obj runtime.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 runtime.Object) error
Get is a wrapper around Get method
func (*FakeClientWrapper) List ¶
func (fkw *FakeClientWrapper) List(ctx context.Context, list runtime.Object, opts ...k8sCl.ListOption) error
List is a wrapper around List method
func (*FakeClientWrapper) Patch ¶
func (fkw *FakeClientWrapper) Patch(ctx context.Context, obj runtime.Object, patch k8sCl.Patch, opts ...k8sCl.PatchOption) error
Patch is a wrapper around Patch method
func (*FakeClientWrapper) Status ¶
func (fkw *FakeClientWrapper) Status() k8sCl.StatusWriter
Status is a wrapper around Status method
func (*FakeClientWrapper) Update ¶
func (fkw *FakeClientWrapper) Update(ctx context.Context, obj runtime.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(logger *logrus.Logger, stopCH <-chan struct{}, objects ...runtime.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 ¶
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 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, appName 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 runtime.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) ReadCRWithAttempts ¶
func (k *KubeClient) ReadCRWithAttempts(name string, namespace string, obj runtime.Object, attempts int) error
ReadCRWithAttempts reads specified resource from k8s cluster into a pointer of struct that implements runtime.Object with specified amount of attempts. Fails right away if resource is not found Receives golang context, name of the read object, and object pointer where to read Returns error if something went wrong
func (*KubeClient) ReadList ¶
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
func (*KubeClient) UpdateCR ¶
UpdateCR updates provided resource on k8s cluster Receives golang context and updated object that implements k8s runtime.Object interface Returns error if something went wrong
func (*KubeClient) UpdateCRWithAttempts ¶
func (k *KubeClient) UpdateCRWithAttempts(ctx context.Context, obj runtime.Object, attempts int) error
UpdateCRWithAttempts updates provided resource on k8s cluster with specified amount of attempts Fails right away if resource is not found or was changed Receives golang context and updated object that implements k8s runtime.Object interface Returns error if something went wrong