rbd: set cluster Name as metadata on the image

This change helps read the cluster name from the cmdline args,
the provisioner will set the same on the RBD images.

Fixes: #2973
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2022-04-11 09:57:29 +05:30 committed by mergify[bot]
parent deb003e605
commit 2880c25fd6
8 changed files with 35 additions and 5 deletions

View File

@ -68,6 +68,7 @@ func init() {
flag.StringVar(&conf.NodeID, "nodeid", "", "node id") flag.StringVar(&conf.NodeID, "nodeid", "", "node id")
flag.StringVar(&conf.PluginPath, "pluginpath", defaultPluginPath, "plugin path") flag.StringVar(&conf.PluginPath, "pluginpath", defaultPluginPath, "plugin path")
flag.StringVar(&conf.StagingPath, "stagingpath", defaultStagingPath, "staging path") flag.StringVar(&conf.StagingPath, "stagingpath", defaultStagingPath, "staging path")
flag.StringVar(&conf.ClusterName, "clustername", "", "name of the cluster")
flag.StringVar(&conf.InstanceID, "instanceid", "", "Unique ID distinguishing this instance of Ceph CSI among other"+ flag.StringVar(&conf.InstanceID, "instanceid", "", "Unique ID distinguishing this instance of Ceph CSI among other"+
" instances, when sharing Ceph clusters across CSI instances for provisioning") " instances, when sharing Ceph clusters across CSI instances for provisioning")
flag.IntVar(&conf.PidLimit, "pidlimit", 0, "the PID limit to configure through cgroups") flag.IntVar(&conf.PidLimit, "pidlimit", 0, "the PID limit to configure through cgroups")
@ -249,6 +250,7 @@ func main() {
cfg := controller.Config{ cfg := controller.Config{
DriverName: dname, DriverName: dname,
Namespace: conf.DriverNamespace, Namespace: conf.DriverNamespace,
ClusterName: conf.ClusterName,
} }
// initialize all controllers before starting. // initialize all controllers before starting.
initControllers() initControllers()

View File

@ -37,6 +37,7 @@ type Manager interface {
type Config struct { type Config struct {
DriverName string DriverName string
Namespace string Namespace string
ClusterName string
} }
// ControllerList holds the list of managers need to be started. // ControllerList holds the list of managers need to be started.

View File

@ -184,6 +184,7 @@ func (r ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime.
volumeHandler, volumeHandler,
requestName, requestName,
pvcNamespace, pvcNamespace,
r.config.ClusterName,
cr) cr)
if err != nil { if err != nil {
log.ErrorLogMsg("failed to regenerate journal %s", err) log.ErrorLogMsg("failed to regenerate journal %s", err)

View File

@ -51,6 +51,9 @@ type ControllerServer struct {
// A map storing all volumes/snapshots with ongoing operations. // A map storing all volumes/snapshots with ongoing operations.
OperationLocks *util.OperationLock OperationLocks *util.OperationLock
// Cluster name
ClusterName string
} }
func (cs *ControllerServer) validateVolumeReq(ctx context.Context, req *csi.CreateVolumeRequest) error { func (cs *ControllerServer) validateVolumeReq(ctx context.Context, req *csi.CreateVolumeRequest) error {
@ -132,6 +135,8 @@ func (cs *ControllerServer) parseVolCreateRequest(
return nil, status.Error(codes.InvalidArgument, err.Error()) return nil, status.Error(codes.InvalidArgument, err.Error())
} }
rbdVol.ClusterName = cs.ClusterName
// if the KMS is of type VaultToken, additional metadata is needed // if the KMS is of type VaultToken, additional metadata is needed
// depending on the tenant, the KMS can be configured with other // depending on the tenant, the KMS can be configured with other
// options // options
@ -1090,6 +1095,7 @@ func (cs *ControllerServer) CreateSnapshot(
// Update the metadata on snapshot not on the original image // Update the metadata on snapshot not on the original image
rbdVol.RbdImageName = rbdSnap.RbdSnapName rbdVol.RbdImageName = rbdSnap.RbdSnapName
rbdVol.ClusterName = cs.ClusterName
err = rbdVol.unsetAllMetadata(k8s.GetVolumeMetadataKeys()) err = rbdVol.unsetAllMetadata(k8s.GetVolumeMetadataKeys())
if err != nil { if err != nil {

View File

@ -161,6 +161,7 @@ func (r *Driver) Run(conf *util.Config) {
if conf.IsControllerServer { if conf.IsControllerServer {
r.cs = NewControllerServer(r.cd) r.cs = NewControllerServer(r.cd)
r.cs.ClusterName = conf.ClusterName
r.rs = NewReplicationServer(r.cs) r.rs = NewReplicationServer(r.cs)
} }
if !conf.IsControllerServer && !conf.IsNodeServer { if !conf.IsControllerServer && !conf.IsNodeServer {

View File

@ -541,7 +541,8 @@ func RegenerateJournal(
claimName, claimName,
volumeID, volumeID,
requestName, requestName,
owner string, owner,
clusterName string,
cr *util.Credentials, cr *util.Credentials,
) (string, error) { ) (string, error) {
ctx := context.Background() ctx := context.Background()
@ -555,6 +556,7 @@ func RegenerateJournal(
rbdVol = &rbdVolume{} rbdVol = &rbdVolume{}
rbdVol.VolID = volumeID rbdVol.VolID = volumeID
rbdVol.ClusterName = clusterName
err = vi.DecomposeCSIID(rbdVol.VolID) err = vi.DecomposeCSIID(rbdVol.VolID)
if err != nil { if err != nil {

View File

@ -78,6 +78,9 @@ const (
// krbd attribute file to check supported features. // krbd attribute file to check supported features.
krbdSupportedFeaturesFile = "/sys/bus/rbd/supported_features" krbdSupportedFeaturesFile = "/sys/bus/rbd/supported_features"
// clusterNameKey cluster Key, set on RBD image.
clusterNameKey = "csi.ceph.com/cluster/name"
) )
// rbdImage contains common attributes and methods for the rbdVolume and // rbdImage contains common attributes and methods for the rbdVolume and
@ -121,6 +124,9 @@ type rbdImage struct {
// Primary represent if the image is primary or not. // Primary represent if the image is primary or not.
Primary bool Primary bool
// Cluster name
ClusterName string
// encryption provides access to optional VolumeEncryption functions // encryption provides access to optional VolumeEncryption functions
encryption *util.VolumeEncryption encryption *util.VolumeEncryption
// Owner is the creator (tenant, Kubernetes Namespace) of the volume // Owner is the creator (tenant, Kubernetes Namespace) of the volume
@ -2001,6 +2007,14 @@ func (rv *rbdVolume) setAllMetadata(parameters map[string]string) error {
} }
} }
if rv.ClusterName != "" {
err := rv.SetMetadata(clusterNameKey, rv.ClusterName)
if err != nil {
return fmt.Errorf("failed to set metadata key %q, value %q on image: %w",
clusterNameKey, rv.ClusterName, err)
}
}
return nil return nil
} }

View File

@ -121,6 +121,9 @@ type Config struct {
// CSI-Addons endpoint // CSI-Addons endpoint
CSIAddonsEndpoint string CSIAddonsEndpoint string
// Cluster name
ClusterName string
} }
// ValidateDriverName validates the driver name. // ValidateDriverName validates the driver name.