mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rbd:store/Read volumeID in/from PV annotation
In the case of the Async DR, the volumeID will not be the same if the clusterID or the PoolID is different, With Earlier implementation, it is expected that the new volumeID mapping is stored in the rados omap pool. In the case of the ControllerExpand or the DeleteVolume Request, the only volumeID will be sent it's not possible to find the corresponding poolID in the new cluster. With This Change, it works as below The csi-rbdplugin-controller will watch for the PV objects, when there are any PV objects created it will check the omap already exists, If the omap doesn't exist it will generate the new volumeID and it checks for the volumeID mapping entry in the PV annotation, if the mapping does not exist, it will add the new entry to the PV annotation. The cephcsi will check for the PV annotations if the omap does not exist if the mapping exists in the PV annotation, it will use the new volumeID for further operations. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
9aea701bd9
commit
0f8813d89f
@ -35,6 +35,7 @@ import (
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/cloud-provider/volume/helpers"
|
||||
)
|
||||
@ -777,9 +778,8 @@ func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID str
|
||||
return err
|
||||
}
|
||||
|
||||
// genVolFromVolID generates a rbdVolume structure from the provided identifier, updating
|
||||
// the structure with elements from on-disk image metadata as well.
|
||||
func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials, secrets map[string]string) (*rbdVolume, error) {
|
||||
// generateVolumeFromVolumeID generates a rbdVolume structure from the provided identifier.
|
||||
func generateVolumeFromVolumeID(ctx context.Context, volumeID string, cr *util.Credentials, secrets map[string]string) (*rbdVolume, error) {
|
||||
var (
|
||||
options map[string]string
|
||||
vi util.CSIIdentifier
|
||||
@ -821,20 +821,6 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
|
||||
}
|
||||
defer j.Destroy()
|
||||
|
||||
// check is there any volumeID mapping exists.
|
||||
id, err := j.CheckNewUUIDMapping(ctx, rbdVol.JournalPool, volumeID)
|
||||
if err != nil {
|
||||
return rbdVol, fmt.Errorf("failed to get volume id %s mapping %w",
|
||||
volumeID, err)
|
||||
}
|
||||
if id != "" {
|
||||
rbdVol.VolID = id
|
||||
err = vi.DecomposeCSIID(rbdVol.VolID)
|
||||
if err != nil {
|
||||
return rbdVol, fmt.Errorf("%w: error decoding volume ID (%s) (%s)",
|
||||
ErrInvalidVolID, err, rbdVol.VolID)
|
||||
}
|
||||
}
|
||||
rbdVol.Pool, err = util.GetPoolName(rbdVol.Monitors, cr, vi.LocationID)
|
||||
if err != nil {
|
||||
return rbdVol, err
|
||||
@ -883,6 +869,38 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
|
||||
return rbdVol, err
|
||||
}
|
||||
|
||||
// genVolFromVolID generates a rbdVolume structure from the provided identifier, updating
|
||||
// the structure with elements from on-disk image metadata as well.
|
||||
func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials, secrets map[string]string) (*rbdVolume, error) {
|
||||
vol, err := generateVolumeFromVolumeID(ctx, volumeID, cr, secrets)
|
||||
if !errors.Is(err, util.ErrKeyNotFound) && !errors.Is(err, util.ErrPoolNotFound) {
|
||||
return vol, err
|
||||
}
|
||||
|
||||
// If the volume details are not found in the OMAP it can be a mirrored RBD
|
||||
// image and the OMAP is already generated and the volumeHandle might not
|
||||
// be the same in the PV.Spec.CSI.VolumeHandle. Check the PV annotation for
|
||||
// the new volumeHandle. If the new volumeHandle is found, generate the RBD
|
||||
// volume structure from the new volumeHandle.
|
||||
c := util.NewK8sClient()
|
||||
listOpt := metav1.ListOptions{
|
||||
LabelSelector: PVReplicatedLabelKey,
|
||||
}
|
||||
pvlist, pErr := c.CoreV1().PersistentVolumes().List(context.TODO(), listOpt)
|
||||
if pErr != nil {
|
||||
return vol, pErr
|
||||
}
|
||||
for i := range pvlist.Items {
|
||||
if pvlist.Items[i].Spec.CSI != nil && pvlist.Items[i].Spec.CSI.VolumeHandle == volumeID {
|
||||
if v, ok := pvlist.Items[i].Annotations[PVVolumeHandleAnnotationKey]; ok {
|
||||
util.UsefulLog(ctx, "found new volumeID %s for existing volumeID %s", v, volumeID)
|
||||
return generateVolumeFromVolumeID(ctx, v, cr, secrets)
|
||||
}
|
||||
}
|
||||
}
|
||||
return vol, err
|
||||
}
|
||||
|
||||
func genVolFromVolumeOptions(ctx context.Context, volOptions, credentials map[string]string, disableInUseChecks bool) (*rbdVolume, error) {
|
||||
var (
|
||||
ok bool
|
||||
|
Reference in New Issue
Block a user