mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
journal: store CreationTime for VolumeGroups
Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
parent
6d1ab1b8d9
commit
503d10eb1a
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
"github.com/ceph/ceph-csi/internal/util/log"
|
"github.com/ceph/ceph-csi/internal/util/log"
|
||||||
@ -75,6 +76,11 @@ type VolumeGroupJournal interface {
|
|||||||
// VolumeGroupJournalConfig contains the configuration.
|
// VolumeGroupJournalConfig contains the configuration.
|
||||||
type VolumeGroupJournalConfig struct {
|
type VolumeGroupJournalConfig struct {
|
||||||
Config
|
Config
|
||||||
|
|
||||||
|
// csiCreationTimeKey can hold the key for the time a group was
|
||||||
|
// created. At least RBD groups do not provide the creation time
|
||||||
|
// through API calls.
|
||||||
|
csiCreationTimeKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
type volumeGroupJournalConnection struct {
|
type volumeGroupJournalConnection struct {
|
||||||
@ -97,6 +103,7 @@ func NewCSIVolumeGroupJournal(suffix string) VolumeGroupJournalConfig {
|
|||||||
csiNameKey: "csi.volname",
|
csiNameKey: "csi.volname",
|
||||||
namespace: "",
|
namespace: "",
|
||||||
},
|
},
|
||||||
|
csiCreationTimeKey: "csi.creationtime",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +236,7 @@ func (vgjc *volumeGroupJournalConnection) CheckReservation(ctx context.Context,
|
|||||||
volGroupData.VolumeGroupAttributes = &VolumeGroupAttributes{}
|
volGroupData.VolumeGroupAttributes = &VolumeGroupAttributes{}
|
||||||
volGroupData.VolumeGroupAttributes.RequestName = savedVolumeGroupAttributes.RequestName
|
volGroupData.VolumeGroupAttributes.RequestName = savedVolumeGroupAttributes.RequestName
|
||||||
volGroupData.VolumeGroupAttributes.VolumeMap = savedVolumeGroupAttributes.VolumeMap
|
volGroupData.VolumeGroupAttributes.VolumeMap = savedVolumeGroupAttributes.VolumeMap
|
||||||
|
volGroupData.VolumeGroupAttributes.CreationTime = savedVolumeGroupAttributes.CreationTime
|
||||||
|
|
||||||
return volGroupData, nil
|
return volGroupData, nil
|
||||||
}
|
}
|
||||||
@ -354,6 +362,12 @@ func (vgjc *volumeGroupJournalConnection) ReserveName(ctx context.Context,
|
|||||||
omapValues[cj.csiNameKey] = reqName
|
omapValues[cj.csiNameKey] = reqName
|
||||||
omapValues[cj.csiImageKey] = groupName
|
omapValues[cj.csiImageKey] = groupName
|
||||||
|
|
||||||
|
t, err := time.Now().MarshalText()
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
omapValues[cj.csiCreationTimeKey] = string(t)
|
||||||
|
|
||||||
err = setOMapKeys(ctx, vgjc.connection, journalPool, cj.namespace, oid, omapValues)
|
err = setOMapKeys(ctx, vgjc.connection, journalPool, cj.namespace, oid, omapValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
@ -365,9 +379,10 @@ func (vgjc *volumeGroupJournalConnection) ReserveName(ctx context.Context,
|
|||||||
// VolumeGroupAttributes contains the request name and the volumeID's and
|
// VolumeGroupAttributes contains the request name and the volumeID's and
|
||||||
// the corresponding snapshotID's.
|
// the corresponding snapshotID's.
|
||||||
type VolumeGroupAttributes struct {
|
type VolumeGroupAttributes struct {
|
||||||
RequestName string // Contains the request name for the passed in UUID
|
RequestName string // Contains the request name for the passed in UUID
|
||||||
GroupName string // Contains the group name
|
GroupName string // Contains the group name
|
||||||
VolumeMap map[string]string // Contains the volumeID and the corresponding value mapping
|
CreationTime *time.Time // Contains the time of creation of the group
|
||||||
|
VolumeMap map[string]string // Contains the volumeID and the corresponding value mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vgjc *volumeGroupJournalConnection) GetVolumeGroupAttributes(
|
func (vgjc *volumeGroupJournalConnection) GetVolumeGroupAttributes(
|
||||||
@ -390,13 +405,21 @@ func (vgjc *volumeGroupJournalConnection) GetVolumeGroupAttributes(
|
|||||||
log.WarningLog(ctx, "unable to read omap values: pool missing: %v", err)
|
log.WarningLog(ctx, "unable to read omap values: pool missing: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t := &time.Time{}
|
||||||
|
err = t.UnmarshalText([]byte(values[cj.csiCreationTimeKey]))
|
||||||
|
if err != nil {
|
||||||
|
t = nil
|
||||||
|
}
|
||||||
|
|
||||||
groupAttributes.RequestName = values[cj.csiNameKey]
|
groupAttributes.RequestName = values[cj.csiNameKey]
|
||||||
groupAttributes.GroupName = values[cj.csiImageKey]
|
groupAttributes.GroupName = values[cj.csiImageKey]
|
||||||
|
groupAttributes.CreationTime = t
|
||||||
|
|
||||||
// Remove request name key and group name key from the omap, as we are
|
// Remove request name key and group name key from the omap, as we are
|
||||||
// looking for volumeID/snapshotID mapping
|
// looking for volumeID/snapshotID mapping
|
||||||
delete(values, cj.csiNameKey)
|
delete(values, cj.csiNameKey)
|
||||||
delete(values, cj.csiImageKey)
|
delete(values, cj.csiImageKey)
|
||||||
|
delete(values, cj.csiCreationTimeKey)
|
||||||
groupAttributes.VolumeMap = map[string]string{}
|
groupAttributes.VolumeMap = map[string]string{}
|
||||||
for k, v := range values {
|
for k, v := range values {
|
||||||
groupAttributes.VolumeMap[k] = v
|
groupAttributes.VolumeMap[k] = v
|
||||||
|
Loading…
Reference in New Issue
Block a user