-
Notifications
You must be signed in to change notification settings - Fork 159
Add metadata info in tag on PD #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Enable extra-create-metadata flag for external-provisioner | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: "--extra-create-metadata" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ limitations under the License. | |
package gcecloudprovider | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
@@ -268,21 +269,42 @@ func ValidateDiskParameters(disk *CloudDisk, params common.DiskParameters) error | |
|
||
func (cloud *CloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key, params common.DiskParameters, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotID string) error { | ||
klog.V(5).Infof("Inserting disk %v", volKey) | ||
|
||
description, err := encodeDiskTags(params.Tags) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch volKey.Type() { | ||
case meta.Zonal: | ||
return cloud.insertZonalDisk(ctx, volKey, params, capBytes, capacityRange, snapshotID) | ||
if description == "" { | ||
description = "Disk created by GCE-PD CSI Driver" | ||
} | ||
return cloud.insertZonalDisk(ctx, volKey, params, capBytes, capacityRange, snapshotID, description) | ||
case meta.Regional: | ||
return cloud.insertRegionalDisk(ctx, volKey, params, capBytes, capacityRange, replicaZones, snapshotID) | ||
if description == "" { | ||
description = "Regional disk created by GCE-PD CSI Driver" | ||
} | ||
return cloud.insertRegionalDisk(ctx, volKey, params, capBytes, capacityRange, replicaZones, snapshotID, description) | ||
default: | ||
return fmt.Errorf("could not insert disk, key was neither zonal nor regional, instead got: %v", volKey.String()) | ||
} | ||
} | ||
|
||
func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta.Key, params common.DiskParameters, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotID string) error { | ||
func (cloud *CloudProvider) insertRegionalDisk( | ||
ctx context.Context, | ||
volKey *meta.Key, | ||
params common.DiskParameters, | ||
capBytes int64, | ||
capacityRange *csi.CapacityRange, | ||
replicaZones []string, | ||
snapshotID string, | ||
description string) error { | ||
|
||
diskToCreate := &computev1.Disk{ | ||
Name: volKey.Name, | ||
SizeGb: common.BytesToGb(capBytes), | ||
Description: "Regional disk created by GCE-PD CSI Driver", | ||
Description: description, | ||
Type: cloud.GetDiskTypeURI(volKey, params.DiskType), | ||
} | ||
if snapshotID != "" { | ||
|
@@ -337,11 +359,18 @@ func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta | |
return nil | ||
} | ||
|
||
func (cloud *CloudProvider) insertZonalDisk(ctx context.Context, volKey *meta.Key, params common.DiskParameters, capBytes int64, capacityRange *csi.CapacityRange, snapshotID string) error { | ||
func (cloud *CloudProvider) insertZonalDisk( | ||
ctx context.Context, | ||
volKey *meta.Key, | ||
params common.DiskParameters, | ||
capBytes int64, | ||
capacityRange *csi.CapacityRange, | ||
snapshotID string, | ||
description string) error { | ||
diskToCreate := &computev1.Disk{ | ||
Name: volKey.Name, | ||
SizeGb: common.BytesToGb(capBytes), | ||
Description: "Disk created by GCE-PD CSI Driver", | ||
Description: description, | ||
Type: cloud.GetDiskTypeURI(volKey, params.DiskType), | ||
} | ||
|
||
|
@@ -788,3 +817,18 @@ func removeCryptoKeyVersion(kmsKey string) string { | |
} | ||
return kmsKey | ||
} | ||
|
||
// encodeDiskTags encodes requested volume tags into JSON string, as GCE does | ||
// not support tags on GCE PDs and we use Description field as fallback. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about labels? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is another PR adding labels (#566). My plan is to merge this, and poke that PR to incorporate these as labels as well. |
||
func encodeDiskTags(tags map[string]string) (string, error) { | ||
if len(tags) == 0 { | ||
// No tags -> empty JSON | ||
return "", nil | ||
} | ||
|
||
enc, err := json.Marshal(tags) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to encodeDiskTags %v: %v", tags, err) | ||
} | ||
return string(enc), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to set this regardless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to retain the existing behavior (description set to
Regional disk created by GCE-PD CSI Driver
orDisk created by GCE-PD CSI Driver
depending on disk) if the PVC/PV parameters aren't present.